class Orchestrate::Search::Results
An enumerator for searching an Orchestrate::Collection
Attributes
@return [#to_json] The response object’s aggregate results
@return [Collection] The collection this object will search.
@return [Hash] The query paramaters.
@return [#to_s] The Lucene Query String given as the search query.
@return [Orchestrate::API::CollectionResponse] The response object
Public Class Methods
Initialize a new SearchResults object @param collection [Orchestrate::Collection] The collection searched. @param query [#to_s] The Lucene Query performed. @param options [Hash] The query parameters.
# File lib/orchestrate/search/results.rb, line 23 def initialize(collection, query, options) @collection = collection @query = query @options = options @response = nil @aggregates = nil end
Public Instance Methods
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. @overload each
@return Enumerator
@overload each(&block)
@yieldparam [Array<(Float, Orchestrate::KeyValue)>] score,key_value The item's score and the item.
@example
collection.search("trendy").limit(5).execute.each do |score, item| puts "#{item.key} has a trend score of #{score}" end
# File lib/orchestrate/search/results.rb, line 43 def each @response ||= collection.perform(:search, query, options) @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
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. @overload each_aggregate
@return Enumerator
@overload each_aggregate
(&block)
@yieldparam <(Orchestrate::Collection::AggregateResult)>
# File lib/orchestrate/search/results.rb, line 72 def each_aggregate @response ||= collection.perform(:search, query, options) @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