lib/elasticsearch/persistence/repository/response/results.rb in elasticsearch-persistence-6.0.0.pre vs lib/elasticsearch/persistence/repository/response/results.rb in elasticsearch-persistence-6.0.0

- old
+ new

@@ -9,10 +9,11 @@ # class Results include Enumerable attr_reader :repository + attr_reader :raw_response # The key for accessing the results in an Elasticsearch query response. # HITS = 'hits'.freeze @@ -28,12 +29,12 @@ # @param response [Hash] The full response returned from the Elasticsearch client # @param options [Hash] Optional parameters # def initialize(repository, response, options={}) @repository = repository - @response = Elasticsearch::Model::HashWrapper.new(response) - @options = options + @raw_response = response + @options = options end def method_missing(method_name, *arguments, &block) results.respond_to?(method_name) ? results.__send__(method_name, *arguments, &block) : super end @@ -43,29 +44,29 @@ end # The number of total hits for a query # def total - response[HITS][TOTAL] + raw_response[HITS][TOTAL] end # The maximum score for a query # def max_score - response[HITS][MAX_SCORE] + raw_response[HITS][MAX_SCORE] end # Yields [object, hit] pairs to the block # def each_with_hit(&block) - results.zip(response[HITS][HITS]).each(&block) + results.zip(raw_response[HITS][HITS]).each(&block) end # Yields [object, hit] pairs and returns the result # def map_with_hit(&block) - results.zip(response[HITS][HITS]).map(&block) + results.zip(raw_response[HITS][HITS]).map(&block) end # Return the collection of domain objects # # @example Iterate over the results @@ -74,11 +75,11 @@ # => ["Fox", "Dog"] # # @return [Array] # def results - @results ||= response[HITS][HITS].map do |document| + @results ||= raw_response[HITS][HITS].map do |document| repository.deserialize(document.to_hash) end end # Access the response returned from Elasticsearch by the client @@ -91,10 +92,10 @@ # # => ["brown: 1", "dog: 1", ...] # # @return [Elasticsearch::Model::HashWrapper] # def response - @response + @response ||= Elasticsearch::Model::HashWrapper.new(raw_response) end end end end end