Class: Orchestrate::Search::Results
- Inherits:
-
Object
- Object
- Orchestrate::Search::Results
- Includes:
- Enumerable
- Defined in:
- lib/orchestrate/search/results.rb
Overview
An enumerator for searching an Orchestrate::Collection
Instance Attribute Summary collapse
-
#aggregates ⇒ #to_json
readonly
The response object's aggregate results.
-
#collection ⇒ Collection
readonly
The collection this object will search.
-
#options ⇒ Hash
readonly
The query paramaters.
-
#query ⇒ #to_s
readonly
The Lucene Query String given as the search query.
-
#response ⇒ Orchestrate::API::CollectionResponse
readonly
The response object.
Instance Method Summary collapse
-
#each ⇒ Object
Iterates over each result from the Search.
-
#each_aggregate ⇒ Object
Iterates over each aggregate result from the Search.
-
#initialize(collection, query, options) ⇒ Results
constructor
Initialize a new SearchResults object.
-
#lazy ⇒ Object
Creates a Lazy Enumerator for the Search Results.
Constructor Details
#initialize(collection, query, options) ⇒ Results
Initialize a new SearchResults object
23 24 25 26 27 28 29 |
# File 'lib/orchestrate/search/results.rb', line 23 def initialize(collection, query, ) @collection = collection @query = query @options = @response = nil @aggregates = nil end |
Instance Attribute Details
#aggregates ⇒ #to_json (readonly)
Returns The response object's aggregate results.
17 18 19 |
# File 'lib/orchestrate/search/results.rb', line 17 def aggregates @aggregates end |
#collection ⇒ Collection (readonly)
Returns The collection this object will search.
5 6 7 |
# File 'lib/orchestrate/search/results.rb', line 5 def collection @collection end |
#options ⇒ Hash (readonly)
Returns The query paramaters.
11 12 13 |
# File 'lib/orchestrate/search/results.rb', line 11 def @options end |
#query ⇒ #to_s (readonly)
Returns The Lucene Query String given as the search query.
8 9 10 |
# File 'lib/orchestrate/search/results.rb', line 8 def query @query end |
#response ⇒ Orchestrate::API::CollectionResponse (readonly)
Returns The response object.
14 15 16 |
# File 'lib/orchestrate/search/results.rb', line 14 def response @response end |
Instance Method Details
#each ⇒ Object #each {|score,key_value| ... } ⇒ Object
Iterates over each result from the Search. Used as the basis for Enumerable methods. Items are provided on the basis of score, with most relevant first.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/orchestrate/search/results.rb', line 43 def each @response ||= collection.perform(:search, query, ) @aggregates ||= @response.aggregates return enum_for(:each) unless block_given? raise Orchestrate::ResultsNotReady.new if collection.app.inside_parallel? loop do @response.results.each do |listing| case listing['path']['kind'] when 'event' kv = collection.stub(listing['key']) event_type = Orchestrate::EventType.new(kv, listing['type']) event = Orchestrate::Event.from_listing(event_type, listing, @response) yield [listing['score'], event] else yield [listing['score'], Orchestrate::KeyValue.from_listing(collection, listing, @response)] end end break unless @response.next_link @response = @response.next_results end @response = nil end |
#each_aggregate ⇒ Object #each_aggregate {|| ... } ⇒ Object
Iterates over each aggregate result from the Search. Used as the basis for Enumerable methods. Items are provided on the basis of score, with most relevant first.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/orchestrate/search/results.rb', line 72 def each_aggregate @response ||= collection.perform(:search, query, ) @aggregates ||= @response.aggregates return enum_for(:each_aggregate) unless block_given? raise Orchestrate::ResultsNotReady.new if collection.app.inside_parallel? @aggregates.each do |listing| case listing['aggregate_kind'] when 'stats' yield StatsResult.new(collection, listing) when 'range' yield RangeResult.new(collection, listing) when 'distance' yield DistanceResult.new(collection, listing) when 'time_series' yield TimeSeriesResult.new(collection, listing) end end end |
#lazy ⇒ Object
Creates a Lazy Enumerator for the Search Results. If called inside its
app's in_parallel
block, will pre-fetch results.
93 94 95 96 |
# File 'lib/orchestrate/search/results.rb', line 93 def lazy return each.lazy if collection.app.inside_parallel? super end |