class Elasticsearch::Persistence::Repository::Response::Results

Attributes

repository[R]
response[R]

Public Class Methods

new(repository, response, options = {}) click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 13
def initialize(repository, response, options = {})
  @repository = repository
  @response = Elasticsearch::Model::HashWrapper.new(response)
  @options = options
end

Public Instance Methods

current_page() click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 63
def current_page
  @pagination_attrs[:current_page]
end
each_with_hit(&block) click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 35
def each_with_hit(&block)
  results.zip(response['hits']['hits']).each(&block)
end
map_with_hit(&block) click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 39
def map_with_hit(&block)
  results.zip(response['hits']['hits']).map(&block)
end
max_score() click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 31
def max_score
  response['hits']['max_score']
end
method_missing(method_name, *arguments, &block) click to toggle source
Calls superclass method
# File lib/elasticsearch/persistence/repository/response/results.rb, line 19
def method_missing(method_name, *arguments, &block) # rubocop:disable Style/MissingRespondToMissing
  results.respond_to?(method_name) ? results.__send__(method_name, *arguments, &block) : super
end
paginate(options) click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 49
def paginate(options)
  @pagination_attrs = {
    total_pages: (total.to_f / options[:per_page]).ceil,
    current_page: options[:page],
    per_page: options[:per_page],
    total_entries: total
  }
  self
end
per_page() click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 67
def per_page
  @pagination_attrs[:per_page]
end
respond_to?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/elasticsearch/persistence/repository/response/results.rb, line 23
def respond_to?(method_name, include_private = false) # rubocop:disable Style/OptionalBooleanParameter
  results.respond_to?(method_name) || super
end
results() click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 43
def results
  @results ||= response['hits']['hits'].map do |document|
    repository.deserialize(document.to_hash)
  end
end
total() click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 27
def total
  response['hits']['total']
end
total_entries() click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 71
def total_entries
  @pagination_attrs[:total_entries]
end
total_pages() click to toggle source
# File lib/elasticsearch/persistence/repository/response/results.rb, line 59
def total_pages
  @pagination_attrs[:total_pages]
end