Class: Blodsband::Riak::Search
- Inherits:
-
Object
- Object
- Blodsband::Riak::Search
- Defined in:
- lib/blodsband/riak/search.rb
Constant Summary collapse
- BOOLS =
Set.new(["AND", "OR"])
Instance Method Summary collapse
-
#aindex!(document) ⇒ Blodsband::Riak::Future<Object>
Index a document in Riak Search.
-
#asearch(query, options = {}) ⇒ Blodsband::Future<Hash<Symbol, Object>>
Search for documents in Riak Search.
-
#index!(document) ⇒ Object
Index a document in Riak Search.
-
#initialize(url) ⇒ Search
constructor
Create a search instance.
-
#search(query, options = {}) ⇒ Hash<Symbol, Object>
Search for documents in Riak Search.
Constructor Details
#initialize(url) ⇒ Search
Create a search instance.
15 16 17 |
# File 'lib/blodsband/riak/search.rb', line 15 def initialize(url) @url = url end |
Instance Method Details
#aindex!(document) ⇒ Blodsband::Riak::Future<Object>
Index a document in Riak Search.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/blodsband/riak/search.rb', line 79 def aindex!(document) mult = Multi.new mult.add(:resp, client(URI.join(@url.to_s, "/solr/update")). apost(:head => { 'Content-Type' => 'text/xml' }, :body => add_document_xml(document).to_s)) return(Future.new do mult.really_perform mult.responses[:callback][:resp].response end) end |
#asearch(query, options = {}) ⇒ Blodsband::Future<Hash<Symbol, Object>>
Search for documents in Riak Search.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/blodsband/riak/search.rb', line 25 def asearch(query, = {}) = .clone fields = .delete(:fields) if fields asearch(multi_field_query(query, fields), ) else mult = Multi.new mult.add(:resp, client(URI.join(@url.to_s, "/solr/select")). aget(:query => (query, ))) return(Future.new do mult.really_perform response = mult.responses[:callback][:resp].response['response'] rval = { :total => response['numFound'], :results => response['docs'].map do |x| x['fields'] end } class << rval attr_reader :max_score end rval.instance_eval do @max_score = response['maxScore'] end rval end) end end |
#index!(document) ⇒ Object
Index a document in Riak Search.
97 98 99 |
# File 'lib/blodsband/riak/search.rb', line 97 def index!(document) aindex!(document).get end |
#search(query, options = {}) ⇒ Hash<Symbol, Object>
Search for documents in Riak Search.
68 69 70 |
# File 'lib/blodsband/riak/search.rb', line 68 def search(query, = {}) asearch(query, ).get end |