Class: Elasticsearch::Rails2::Response::Results

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/elasticsearch/rails2/response/results.rb

Overview

Encapsulates the collection of documents returned from Elasticsearch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, response, options = {}) ⇒ Results

Returns a new instance of Results.

Parameters:

  • klass (Class)

    The name of the model class

  • response (Hash)

    The full response returned from Elasticsearch client

  • options (Hash) (defaults to: {})

    Optional parameters



20
21
22
23
# File 'lib/elasticsearch/rails2/response/results.rb', line 20

def initialize(klass, response, options={})
  @klass     = klass
  @response  = response
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



10
11
12
# File 'lib/elasticsearch/rails2/response/results.rb', line 10

def klass
  @klass
end

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/elasticsearch/rails2/response/results.rb', line 10

def response
  @response
end

Instance Method Details

#idsObject

Returns the hit IDs



45
46
47
# File 'lib/elasticsearch/rails2/response/results.rb', line 45

def ids
  response.response['hits']['hits'].map { |hit| hit['_id'] }
end

#max_scoreObject

Returns the max_score



39
40
41
# File 'lib/elasticsearch/rails2/response/results.rb', line 39

def max_score
  response.response['hits']['max_score']
end

#resultsObject



27
28
29
# File 'lib/elasticsearch/rails2/response/results.rb', line 27

def results
  @results  = response.response['hits']['hits'].map { |hit| Result.new(hit) }
end

#totalObject

Returns the total number of hits



33
34
35
# File 'lib/elasticsearch/rails2/response/results.rb', line 33

def total
  response.response['hits']['total']
end