Class: Elasticsearch::Rails2::Response::Results
- Inherits:
-
Object
- Object
- Elasticsearch::Rails2::Response::Results
- 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
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#ids ⇒ Object
Returns the hit IDs.
-
#initialize(klass, response, options = {}) ⇒ Results
constructor
A new instance of Results.
-
#max_score ⇒ Object
Returns the max_score.
-
#results ⇒ Object
Returns the Results collection.
-
#total ⇒ Object
Returns the total number of hits.
Constructor Details
#initialize(klass, response, options = {}) ⇒ Results
Returns a new instance of Results.
20 21 22 23 |
# File 'lib/elasticsearch/rails2/response/results.rb', line 20 def initialize(klass, response, ={}) @klass = klass @response = response end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
10 11 12 |
# File 'lib/elasticsearch/rails2/response/results.rb', line 10 def klass @klass end |
#response ⇒ Object (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
#ids ⇒ Object
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_score ⇒ Object
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 |
#results ⇒ Object
Returns the Elasticsearch::Rails2::Response::Results collection
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 |
#total ⇒ Object
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 |