Class: ElasticRecord::SearchHits
- Inherits:
-
Object
- Object
- ElasticRecord::SearchHits
- Defined in:
- lib/elastic_record/search_hits.rb
Instance Attribute Summary collapse
-
#hits ⇒ Object
Returns the value of attribute hits.
-
#model ⇒ Object
Returns the value of attribute model.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(model, hits) ⇒ SearchHits
constructor
A new instance of SearchHits.
- #to_ids ⇒ Object
- #to_records ⇒ Object
Constructor Details
#initialize(model, hits) ⇒ SearchHits
Returns a new instance of SearchHits.
11 12 13 14 |
# File 'lib/elastic_record/search_hits.rb', line 11 def initialize(model, hits) @model = model @hits = hits end |
Instance Attribute Details
#hits ⇒ Object
Returns the value of attribute hits.
3 4 5 |
# File 'lib/elastic_record/search_hits.rb', line 3 def hits @hits end |
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/elastic_record/search_hits.rb', line 3 def model @model end |
Class Method Details
.from_response(model, response) ⇒ Object
6 7 8 |
# File 'lib/elastic_record/search_hits.rb', line 6 def from_response(model, response) new(model, response['hits']['hits']) end |
Instance Method Details
#to_ids ⇒ Object
16 17 18 |
# File 'lib/elastic_record/search_hits.rb', line 16 def to_ids hits.map { |hit| hit['_id'] } end |
#to_records ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/elastic_record/search_hits.rb', line 20 def to_records if model.elastic_index.load_from_source hits.map { |hit| load_from_hit(hit) } else model.find to_ids end end |