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(hits, total: nil) ⇒ SearchHits

Returns a new instance of SearchHits.



11
12
13
14
# File 'lib/elastic_record/search_hits.rb', line 11

def initialize(hits, total: nil)
  @hits  = hits
  @total = total.is_a?(Hash) ? total['value'] : total
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

#totalObject

Returns the value of attribute total.



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

def total
  @total
end

Class Method Details

.from_response(response) ⇒ Object



6
7
8
# File 'lib/elastic_record/search_hits.rb', line 6

def from_response(response)
  new(response['hits']['hits'], total: response['hits']['total'])
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