Class: Elastics::ActiveRecord::SearchResult

Inherits:
Result::Search show all
Defined in:
lib/elastics/active_record/search_result.rb

Instance Attribute Summary

Attributes inherited from Result::Search

#response

Instance Method Summary collapse

Methods inherited from Result::Search

#aggregations, #hits, #ids_to_find, #rest_ids, #total

Constructor Details

#initialize(model, response, options = {}) ⇒ SearchResult



4
5
6
7
# File 'lib/elastics/active_record/search_result.rb', line 4

def initialize(model, response, options = {})
  @model = model
  super response, options
end

Instance Method Details

#collectionObject



14
15
16
# File 'lib/elastics/active_record/search_result.rb', line 14

def collection
  @collection ||= @model.find_all_ordered ids_to_find
end

#idsObject

super.map(&:to_i)



10
11
12
# File 'lib/elastics/active_record/search_result.rb', line 10

def ids
  @ids ||= hits['hits'.freeze].map { |x| x['_id'.freeze].to_i }
end

#relationObject



18
19
20
# File 'lib/elastics/active_record/search_result.rb', line 18

def relation
  @model.where(id: ids_to_find)
end