Class: Elastics::ActiveRecord::SearchResult
- Inherits:
-
Result::Search
- Object
- Result::Search
- Elastics::ActiveRecord::SearchResult
- Defined in:
- lib/elastics/active_record/search_result.rb
Instance Attribute Summary
Attributes inherited from Result::Search
Instance Method Summary collapse
- #collection ⇒ Object
-
#ids ⇒ Object
super.map(&:to_i).
-
#initialize(response, options = {}) ⇒ SearchResult
constructor
It expects ‘:model` option with a model-class.
- #relation ⇒ Object
Methods inherited from Result::Search
#aggregations, #hits, #ids_to_find, #rest_ids, #total
Constructor Details
#initialize(response, options = {}) ⇒ SearchResult
It expects ‘:model` option with a model-class. Optionally pass `scope` option with a lambda which takes and modifies relation.
7 8 9 10 11 |
# File 'lib/elastics/active_record/search_result.rb', line 7 def initialize(response, = {}) @model = [:model] @scope = [:scope] super response, end |
Instance Method Details
#collection ⇒ Object
18 19 20 |
# File 'lib/elastics/active_record/search_result.rb', line 18 def collection @collection ||= relation.find_all_ordered(ids_to_find, true) end |
#ids ⇒ Object
super.map(&:to_i)
14 15 16 |
# File 'lib/elastics/active_record/search_result.rb', line 14 def ids @ids ||= hits['hits'.freeze].map { |x| x['_id'.freeze].to_i } end |
#relation ⇒ Object
22 23 24 25 26 27 |
# File 'lib/elastics/active_record/search_result.rb', line 22 def relation @relation ||= begin result = @model.where(id: ids_to_find) @scope ? @scope.call(result) : result end end |