@@ -11,6 +11,7 @@ class Results
11
11
include Enumerable
12
12
13
13
attr_reader :repository
14
+ attr_reader :raw_response
14
15
15
16
# The key for accessing the results in an Elasticsearch query response.
16
17
#
@@ -30,8 +31,8 @@ class Results
30
31
#
31
32
def initialize ( repository , response , options = { } )
32
33
@repository = repository
33
- @response = Elasticsearch :: Model :: HashWrapper . new ( response )
34
- @options = options
34
+ @raw_response = response
35
+ @options = options
35
36
end
36
37
37
38
def method_missing ( method_name , *arguments , &block )
@@ -45,25 +46,25 @@ def respond_to?(method_name, include_private = false)
45
46
# The number of total hits for a query
46
47
#
47
48
def total
48
- response [ HITS ] [ TOTAL ]
49
+ raw_response [ HITS ] [ TOTAL ]
49
50
end
50
51
51
52
# The maximum score for a query
52
53
#
53
54
def max_score
54
- response [ HITS ] [ MAX_SCORE ]
55
+ raw_response [ HITS ] [ MAX_SCORE ]
55
56
end
56
57
57
58
# Yields [object, hit] pairs to the block
58
59
#
59
60
def each_with_hit ( &block )
60
- results . zip ( response [ HITS ] [ HITS ] ) . each ( &block )
61
+ results . zip ( raw_response [ HITS ] [ HITS ] ) . each ( &block )
61
62
end
62
63
63
64
# Yields [object, hit] pairs and returns the result
64
65
#
65
66
def map_with_hit ( &block )
66
- results . zip ( response [ HITS ] [ HITS ] ) . map ( &block )
67
+ results . zip ( raw_response [ HITS ] [ HITS ] ) . map ( &block )
67
68
end
68
69
69
70
# Return the collection of domain objects
@@ -76,7 +77,7 @@ def map_with_hit(&block)
76
77
# @return [Array]
77
78
#
78
79
def results
79
- @results ||= response [ HITS ] [ HITS ] . map do |document |
80
+ @results ||= raw_response [ HITS ] [ HITS ] . map do |document |
80
81
repository . deserialize ( document . to_hash )
81
82
end
82
83
end
@@ -93,7 +94,7 @@ def results
93
94
# @return [Elasticsearch::Model::HashWrapper]
94
95
#
95
96
def response
96
- @response
97
+ @response ||= Elasticsearch :: Model :: HashWrapper . new ( raw_response )
97
98
end
98
99
end
99
100
end
0 commit comments