elastic_adapter 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3023280225ea7fdf0075512820f96c192d448e33
|
4
|
+
data.tar.gz: f492fc71afbd84718f09dc7fb2a176f9adee2de0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35fa163b104cb2965f2559ae8ea97a0438ededd741e339d7d9e163e0839360eef9004df5bd1140f93b5f487040a2f5a73ce498f43234efe80bfd03f82c7478d2
|
7
|
+
data.tar.gz: e5e2cf3126f2b0e58d98163d6716db4cec4da8f019c01606cfa975cd018b8f0dc89665fd4d02aba5efeaa4726194d6303a569f20630505edb28af06e94493ca1
|
@@ -1,20 +1,37 @@
|
|
1
1
|
module ElasticAdapter
|
2
2
|
module Responses
|
3
3
|
class SearchResponse < BaseResponse
|
4
|
-
attr_reader :hits
|
4
|
+
attr_reader :hits, :aggregations, :suggestions
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
8
|
def set_instance_variables
|
9
|
-
hits =
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
@hits = collect_hits
|
10
|
+
@aggregations = collect_aggregations
|
11
|
+
@suggestions = collect_suggestions
|
12
|
+
end
|
13
|
+
|
14
|
+
def collect_hits
|
15
|
+
object[:hits][:hits].map { |hit| { id: hit[:id] }.merge(hit[:source]) }
|
16
|
+
end
|
14
17
|
|
18
|
+
def collect_aggregations
|
19
|
+
aggs = {}
|
20
|
+
object[:aggregations].each do |agg_name, result|
|
21
|
+
aggs[agg_name] = []
|
22
|
+
result[:buckets].each do |agg|
|
23
|
+
aggs[agg_name] << { term: agg[:key], count: agg[:doc_count] }
|
24
|
+
end
|
15
25
|
end
|
26
|
+
aggs
|
27
|
+
end
|
16
28
|
|
17
|
-
|
29
|
+
def collect_suggestions
|
30
|
+
object[:suggest].map { |suggestion_name, content|
|
31
|
+
# In this context key is the named suggestion
|
32
|
+
# returned by elasticsearch
|
33
|
+
SuggestionResponse::Suggestion.new(suggestion_name, content)
|
34
|
+
}
|
18
35
|
end
|
19
36
|
end
|
20
37
|
end
|
@@ -23,6 +23,36 @@ module ElasticAdapter
|
|
23
23
|
}
|
24
24
|
}
|
25
25
|
]
|
26
|
+
},
|
27
|
+
aggregations: {
|
28
|
+
products: {
|
29
|
+
doc_count_error_upper_bound: 46,
|
30
|
+
buckets: [
|
31
|
+
{
|
32
|
+
key: "Product A",
|
33
|
+
doc_count: 100
|
34
|
+
},
|
35
|
+
{
|
36
|
+
key: "Product Z",
|
37
|
+
doc_count: 52
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
},
|
42
|
+
suggest: {
|
43
|
+
foo_suggest: [
|
44
|
+
{
|
45
|
+
text: "ba",
|
46
|
+
offset: 0,
|
47
|
+
length: 2,
|
48
|
+
options: [
|
49
|
+
{
|
50
|
+
text: "bar",
|
51
|
+
score: 1.0
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
]
|
26
56
|
}
|
27
57
|
}}
|
28
58
|
|
@@ -38,6 +68,71 @@ module ElasticAdapter
|
|
38
68
|
})
|
39
69
|
end
|
40
70
|
end
|
71
|
+
|
72
|
+
describe "#aggregations" do
|
73
|
+
it "counts one" do
|
74
|
+
expect(subject.aggregations.count).to eq 1
|
75
|
+
end
|
76
|
+
|
77
|
+
it "contains products" do
|
78
|
+
expect(subject.aggregations).to have_key :products
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "products" do
|
82
|
+
it "counts two" do
|
83
|
+
expect(subject.aggregations[:products].count).to eq 2
|
84
|
+
end
|
85
|
+
|
86
|
+
it "contains Product A with it's count" do
|
87
|
+
expect(subject.aggregations[:products]).to include({
|
88
|
+
term: "Product A",
|
89
|
+
count: 100
|
90
|
+
})
|
91
|
+
end
|
92
|
+
|
93
|
+
it "contains Product Z with it's count" do
|
94
|
+
expect(subject.aggregations[:products]).to include({
|
95
|
+
term: "Product Z",
|
96
|
+
count: 52
|
97
|
+
})
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "suggestions" do
|
103
|
+
it "is an array" do
|
104
|
+
expect(subject.suggestions).to be_an Array
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "first suggestion" do
|
108
|
+
describe "#terms" do
|
109
|
+
it "is an Array" do
|
110
|
+
expect(subject.suggestions.first.terms).to be_an Array
|
111
|
+
end
|
112
|
+
|
113
|
+
it "counts one" do
|
114
|
+
expect(subject.suggestions.first.terms.count).to eq 1
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "first term" do
|
118
|
+
describe "#text" do
|
119
|
+
it "equals 'ba'" do
|
120
|
+
expect(subject.suggestions.first.terms.first.text).to eq "ba"
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#options" do
|
124
|
+
it "includes the options" do
|
125
|
+
expect(subject.suggestions.first.terms.first.options).to include({
|
126
|
+
text: "bar",
|
127
|
+
score: 1.0
|
128
|
+
})
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
41
136
|
end
|
42
137
|
end
|
43
138
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristopher Bredemeier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|