Module: ElasticRecord::Relation::Hits
- Included in:
- ElasticRecord::Relation
- Defined in:
- lib/elastic_record/relation/hits.rb
Instance Method Summary collapse
- #load_from_hit(hit) ⇒ Object
- #load_hits(search_hits) ⇒ Object
- #map_hits_to_ids(hits) ⇒ Object
- #search_hits ⇒ Object
- #search_results ⇒ Object
- #to_ids ⇒ Object
Instance Method Details
#load_from_hit(hit) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/elastic_record/relation/hits.rb', line 24 def load_from_hit(hit) record = klass.new record.id = hit['_id'] hit['_source'].each do |k, v| record.send("#{k}=", v) if record.respond_to?("#{k}=") end record end |
#load_hits(search_hits) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/elastic_record/relation/hits.rb', line 8 def load_hits(search_hits) if klass.elastic_index.load_from_source search_hits.map { |hit| load_from_hit(hit) } else klass.find map_hits_to_ids(search_hits) end end |
#map_hits_to_ids(hits) ⇒ Object
16 17 18 |
# File 'lib/elastic_record/relation/hits.rb', line 16 def map_hits_to_ids(hits) hits.map { |hit| hit['_id'] } end |
#search_hits ⇒ Object
20 21 22 |
# File 'lib/elastic_record/relation/hits.rb', line 20 def search_hits search_results['hits']['hits'] end |
#search_results ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/elastic_record/relation/hits.rb', line 33 def search_results @search_results ||= begin = {typed_keys: true} [:search_type] = search_type_value if search_type_value klass.elastic_index.search(as_elastic, ) end end |
#to_ids ⇒ Object
4 5 6 |
# File 'lib/elastic_record/relation/hits.rb', line 4 def to_ids map_hits_to_ids search_hits end |