class Elasticsearch::Rails2::Response::Results

Encapsulates the collection of documents returned from Elasticsearch

Implements Enumerable and forwards its methods to the {#results} object.

Attributes

klass[R]
response[R]

Public Class Methods

new(klass, response, options={}) click to toggle source

@param klass [Class] The name of the model class @param response [Hash] The full response returned from Elasticsearch client @param options [Hash] Optional parameters

# File lib/elasticsearch/rails2/response/results.rb, line 20
def initialize(klass, response, options={})
  @klass     = klass
  @response  = response
end

Public Instance Methods

ids() click to toggle source

Returns the hit IDs

# File lib/elasticsearch/rails2/response/results.rb, line 45
def ids
  response.response['hits']['hits'].map { |hit| hit['_id'] }
end
max_score() click to toggle source

Returns the max_score

# File lib/elasticsearch/rails2/response/results.rb, line 39
def max_score
  response.response['hits']['max_score']
end
results() click to toggle source

Returns the {Results} collection

# File lib/elasticsearch/rails2/response/results.rb, line 27
def results
  @results  = response.response['hits']['hits'].map { |hit| Result.new(hit) }
end
total() click to toggle source

Returns the total number of hits

# File lib/elasticsearch/rails2/response/results.rb, line 33
def total
  response.response['hits']['total']
end