class Orchestrate::Search::Results

An enumerator for searching an Orchestrate::Collection

Attributes

aggregates[R]

@return [#to_json] The response object’s aggregate results

collection[R]

@return [Collection] The collection this object will search.

options[R]

@return [Hash] The query paramaters.

query[R]

@return [#to_s] The Lucene Query String given as the search query.

response[R]

@return [Orchestrate::API::CollectionResponse] The response object

Public Class Methods

new(collection, query, options) click to toggle source

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

each() { |listing, event| ... } click to toggle source

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
each_aggregate() { |stats_result| ... } click to toggle source

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
lazy() click to toggle source

Creates a Lazy Enumerator for the Search Results. If called inside its app’s ‘in_parallel` block, will pre-fetch results.

Calls superclass method
# File lib/orchestrate/search/results.rb, line 93
def lazy
  return each.lazy if collection.app.inside_parallel?
  super
end