class Elasticsearch::Model::Response::Records
Encapsulates the collection of records returned from the database
Implements Enumerable and forwards its methods to the {#records} object, which is provided by an {Elasticsearch::Model::Adapter::Adapter} implementation.
Public Class Methods
new(klass, response, options = {})
click to toggle source
@see Base#initialize
Calls superclass method
Elasticsearch::Model::Response::Base::new
# File lib/elasticsearch/model/response/records.rb, line 19 def initialize(klass, response, options = {}) super # Include module provided by the adapter in the singleton class ("metaclass") # adapter = Adapter.from_class(klass) metaclass = class << self; self; end metaclass.__send__ :include, adapter.records_mixin self end
Public Instance Methods
each_with_hit(&block)
click to toggle source
Yields [record, hit] pairs to the block
# File lib/elasticsearch/model/response/records.rb, line 45 def each_with_hit(&block) records.to_a.zip(results).each(&block) end
ids()
click to toggle source
Returns the hit IDs
# File lib/elasticsearch/model/response/records.rb, line 33 def ids response.response["hits"]["hits"].map { |hit| hit["_id"] } end
map_with_hit(&block)
click to toggle source
Yields [record, hit] pairs and returns the result
# File lib/elasticsearch/model/response/records.rb, line 51 def map_with_hit(&block) records.to_a.zip(results).map(&block) end
method_missing(method_name, *arguments)
click to toggle source
Delegate methods to ‘@records`
Calls superclass method
# File lib/elasticsearch/model/response/records.rb, line 57 def method_missing(method_name, *arguments) records.respond_to?(method_name) ? records.__send__(method_name, *arguments) : super end
respond_to?(method_name, include_private = false)
click to toggle source
Respond to methods from ‘@records`
Calls superclass method
# File lib/elasticsearch/model/response/records.rb, line 63 def respond_to?(method_name, include_private = false) records.respond_to?(method_name) || super end
results()
click to toggle source
Returns the {Results} collection
# File lib/elasticsearch/model/response/records.rb, line 39 def results response.results end