Class: Elasticsearch::Persistence::Repository::Response::Results
- Inherits:
-
Object
- Object
- Elasticsearch::Persistence::Repository::Response::Results
- Includes:
- Enumerable
- Defined in:
- lib/elasticsearch/persistence/repository/response/results.rb
Overview
Encapsulates the domain objects and documents returned from Elasticsearch when searching
Implements ‘Enumerable` and forwards its methods to the #results object.
Constant Summary collapse
- HITS =
The key for accessing the results in an Elasticsearch query response.
'hits'.freeze
- TOTAL =
The key for accessing the total number of hits in an Elasticsearch query response.
'total'.freeze
- VALUE =
The key for accessing the value field in an Elasticsearch query response when ‘total’ is an object.
'value'.freeze
- MAX_SCORE =
The key for accessing the maximum score in an Elasticsearch query response.
'max_score'.freeze
Instance Attribute Summary collapse
- #raw_response ⇒ Object readonly
- #repository ⇒ Object readonly
Instance Method Summary collapse
-
#each_with_hit(&block) ⇒ Object
Yields [object, hit] pairs to the block.
-
#initialize(repository, response, options = {}) ⇒ Results
constructor
A new instance of Results.
-
#map_with_hit(&block) ⇒ Object
Yields [object, hit] pairs and returns the result.
-
#max_score ⇒ Object
The maximum score for a query.
- #method_missing(method_name, *arguments, &block) ⇒ Object
- #respond_to?(method_name, include_private = false) ⇒ Boolean
-
#response ⇒ Elasticsearch::Model::HashWrapper
Access the response returned from Elasticsearch by the client.
-
#results ⇒ Array
Return the collection of domain objects.
-
#total ⇒ Object
The number of total hits for a query.
Constructor Details
#initialize(repository, response, options = {}) ⇒ Results
Returns a new instance of Results.
53 54 55 56 57 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 53 def initialize(repository, response, ={}) @repository = repository @raw_response = response @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
59 60 61 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 59 def method_missing(method_name, *arguments, &block) results.respond_to?(method_name) ? results.__send__(method_name, *arguments, &block) : super end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
31 32 33 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 31 def raw_response @raw_response end |
#repository ⇒ Object (readonly)
30 31 32 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 30 def repository @repository end |
Instance Method Details
#each_with_hit(&block) ⇒ Object
Yields [object, hit] pairs to the block
85 86 87 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 85 def each_with_hit(&block) results.zip(raw_response[HITS][HITS]).each(&block) end |
#map_with_hit(&block) ⇒ Object
Yields [object, hit] pairs and returns the result
91 92 93 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 91 def map_with_hit(&block) results.zip(raw_response[HITS][HITS]).map(&block) end |
#max_score ⇒ Object
The maximum score for a query
79 80 81 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 79 def max_score raw_response[HITS][MAX_SCORE] end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
63 64 65 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 63 def respond_to?(method_name, include_private = false) results.respond_to?(method_name) || super end |
#response ⇒ Elasticsearch::Model::HashWrapper
Access the response returned from Elasticsearch by the client
121 122 123 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 121 def response @response ||= Elasticsearch::Model::HashWrapper.new(raw_response) end |