Class: Elastics::Result::Search
- Inherits:
-
Object
- Object
- Elastics::Result::Search
show all
- Defined in:
- lib/elastics/result/search.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(response, options = {}) ⇒ Search
Returns a new instance of Search.
6
7
8
9
|
# File 'lib/elastics/result/search.rb', line 6
def initialize(response, options = {})
@response = response
@options = options
end
|
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
4
5
6
|
# File 'lib/elastics/result/search.rb', line 4
def response
@response
end
|
Instance Method Details
#aggregations ⇒ Object
34
35
36
|
# File 'lib/elastics/result/search.rb', line 34
def aggregations
@aggregations ||= @response['aggregations'.freeze]
end
|
#hits ⇒ Object
11
12
13
|
# File 'lib/elastics/result/search.rb', line 11
def hits
@hits ||= @response['hits'.freeze]
end
|
#ids ⇒ Object
15
16
17
|
# File 'lib/elastics/result/search.rb', line 15
def ids
@ids ||= hits['hits'.freeze].map { |x| x['_id'.freeze] }
end
|
#ids_to_find ⇒ Object
Allows to split ids into two parts, if you want to fetch from primary DB less then was found. This method returns the first part, ‘rest_ids` - the second.
22
23
24
25
26
27
|
# File 'lib/elastics/result/search.rb', line 22
def ids_to_find
@ids_to_find ||= begin
limit = @options[:limit]
limit ? ids[0...limit] : ids
end
end
|
#rest_ids ⇒ Object
29
30
31
32
|
# File 'lib/elastics/result/search.rb', line 29
def rest_ids
limit = @options[:limit]
limit ? ids[limit..-1] : []
end
|
#total ⇒ Object
38
39
40
|
# File 'lib/elastics/result/search.rb', line 38
def total
hits['total'.freeze]
end
|