Class: ElasticRecord::SearchHits

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_record/search_hits.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#hitsObject

Returns the value of attribute hits.



3
4
5
# File 'lib/elastic_record/search_hits.rb', line 3

def hits
  @hits
end

#modelObject

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_idsObject



16
17
18
# File 'lib/elastic_record/search_hits.rb', line 16

def to_ids
  hits.map { |hit| hit['_id'] }
end

#to_recordsObject



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