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.
Instance Attribute Summary collapse
-
#loaded ⇒ Object
(also: #loaded?)
readonly
Returns the value of attribute loaded.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #delete(opts = nil) ⇒ Object
-
#each_with_hit(&block) ⇒ Object
Yields [object, hit] pairs to the block.
-
#initialize(repository, response, options = {}) ⇒ Results
constructor
A new instance of Results.
- #inner_hits ⇒ Object
-
#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 ⇒ Hashie::Mash
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.
22 23 24 25 26 27 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 22 def initialize(repository, response, ={}) @repository = repository @response = Elasticsearch::Persistence::Model::HashWrapper.new(response) @options = @loaded = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
29 30 31 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 29 def method_missing(method_name, *arguments, &block) results.respond_to?(method_name) ? results.__send__(method_name, *arguments, &block) : super end |
Instance Attribute Details
#loaded ⇒ Object (readonly) Also known as: loaded?
Returns the value of attribute loaded.
15 16 17 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 15 def loaded @loaded end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
15 16 17 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 15 def repository @repository end |
Instance Method Details
#delete(opts = nil) ⇒ Object
83 84 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 83 def delete(opts=nil) end |
#each_with_hit(&block) ⇒ Object
Yields [object, hit] pairs to the block
56 57 58 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 56 def each_with_hit(&block) results.zip(response['hits']['hits']).each(&block) end |
#inner_hits ⇒ Object
37 38 39 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 37 def inner_hits response['hits']['hits'].collect { |d| d['inner_hits'] } end |
#map_with_hit(&block) ⇒ Object
Yields [object, hit] pairs and returns the result
62 63 64 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 62 def map_with_hit(&block) results.zip(response['hits']['hits']).map(&block) end |
#max_score ⇒ Object
The maximum score for a query
50 51 52 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 50 def max_score response['hits']['max_score'] end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
33 34 35 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 33 def respond_to?(method_name, include_private = false) results.respond_to?(method_name) || super end |
#response ⇒ Hashie::Mash
Access the response returned from Elasticsearch by the client
97 98 99 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 97 def response @response end |
#results ⇒ Array
Return the collection of domain objects
75 76 77 78 79 80 81 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 75 def results @results ||= response['hits']['hits'].map do |document| repository.deserialize(document.to_hash) end @loaded = true @results end |
#total ⇒ Object
The number of total hits for a query
44 45 46 |
# File 'lib/elasticsearch/persistence/repository/response/results.rb', line 44 def total response['hits']['total'] end |