Class: Elastics::ActiveRecord::SearchResult
- Inherits:
-
Object
- Object
- Elastics::ActiveRecord::SearchResult
- Defined in:
- lib/elastics/active_record/search_result.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #aggregations ⇒ Object
- #collection ⇒ Object
- #hits ⇒ Object
- #ids ⇒ Object
- #ids_to_find ⇒ Object
-
#initialize(model, result, options = {}) ⇒ SearchResult
constructor
A new instance of SearchResult.
- #relation ⇒ Object
- #rest_ids ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(model, result, options = {}) ⇒ SearchResult
6 7 8 9 10 |
# File 'lib/elastics/active_record/search_result.rb', line 6 def initialize(model, result, = {}) @model = model @result = result = end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/elastics/active_record/search_result.rb', line 4 def result @result end |
Instance Method Details
#aggregations ⇒ Object
40 41 42 |
# File 'lib/elastics/active_record/search_result.rb', line 40 def aggregations @aggregations ||= @result['aggregations'.freeze] end |
#collection ⇒ Object
32 33 34 |
# File 'lib/elastics/active_record/search_result.rb', line 32 def collection @collection ||= @model.find_all_ordered ids_to_find end |
#hits ⇒ Object
12 13 14 |
# File 'lib/elastics/active_record/search_result.rb', line 12 def hits @hits ||= @result['hits'.freeze] end |
#ids ⇒ Object
16 17 18 |
# File 'lib/elastics/active_record/search_result.rb', line 16 def ids @ids ||= hits['hits'.freeze].map { |x| x['_id'.freeze].to_i } end |
#ids_to_find ⇒ Object
20 21 22 23 24 25 |
# File 'lib/elastics/active_record/search_result.rb', line 20 def ids_to_find @ids_to_find ||= begin limit = [:limit] limit ? ids[0...limit] : ids end end |
#relation ⇒ Object
36 37 38 |
# File 'lib/elastics/active_record/search_result.rb', line 36 def relation @model.where id: ids_to_find end |
#rest_ids ⇒ Object
27 28 29 30 |
# File 'lib/elastics/active_record/search_result.rb', line 27 def rest_ids limit = [:limit] limit ? ids[limit..-1] : [] end |
#total ⇒ Object
44 45 46 |
# File 'lib/elastics/active_record/search_result.rb', line 44 def total hits['total'.freeze] end |