daedal 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -1
  3. data/.travis.yml +7 -0
  4. data/Gemfile +9 -7
  5. data/Gemfile.lock +47 -32
  6. data/README.md +115 -56
  7. data/daedal.gemspec +0 -1
  8. data/lib/daedal.rb +41 -5
  9. data/lib/daedal/attributes/boost.rb +7 -0
  10. data/lib/daedal/attributes/facet.rb +13 -0
  11. data/lib/daedal/attributes/field.rb +7 -0
  12. data/lib/daedal/attributes/filter.rb +2 -2
  13. data/lib/daedal/attributes/filter_array.rb +4 -4
  14. data/lib/daedal/attributes/query.rb +2 -2
  15. data/lib/daedal/attributes/query_array.rb +2 -2
  16. data/lib/daedal/attributes/query_value.rb +19 -0
  17. data/lib/daedal/facets/facet.rb +15 -0
  18. data/lib/daedal/filters/and_filter.rb +2 -5
  19. data/lib/daedal/filters/bool_filter.rb +15 -0
  20. data/lib/daedal/filters/{base_filter.rb → filter.rb} +1 -3
  21. data/lib/daedal/filters/geo_distance_filter.rb +6 -9
  22. data/lib/daedal/filters/or_filter.rb +18 -0
  23. data/lib/daedal/filters/range_filter.rb +8 -8
  24. data/lib/daedal/filters/term_filter.rb +3 -6
  25. data/lib/daedal/filters/terms_filter.rb +3 -6
  26. data/lib/daedal/queries/bool_query.rb +8 -11
  27. data/lib/daedal/queries/constant_score_query.rb +4 -8
  28. data/lib/daedal/queries/dis_max_query.rb +5 -9
  29. data/lib/daedal/queries/filtered_query.rb +3 -8
  30. data/lib/daedal/queries/fuzzy_query.rb +24 -0
  31. data/lib/daedal/queries/match_all_query.rb +1 -3
  32. data/lib/daedal/queries/match_query.rb +11 -15
  33. data/lib/daedal/queries/multi_match_query.rb +12 -16
  34. data/lib/daedal/queries/nested_query.rb +7 -10
  35. data/lib/daedal/queries/prefix_query.rb +7 -9
  36. data/lib/daedal/queries/{base_query.rb → query.rb} +1 -4
  37. data/lib/daedal/queries/query_string_query.rb +32 -0
  38. data/lib/daedal/version.rb +1 -1
  39. data/spec/spec_helper.rb +4 -2
  40. data/spec/unit/daedal/filters/and_filter_spec.rb +0 -1
  41. data/spec/unit/daedal/filters/bool_filter_spec.rb +89 -0
  42. data/spec/unit/daedal/filters/geo_distance_filter_spec.rb +0 -1
  43. data/spec/unit/daedal/filters/or_filter_spec.rb +74 -0
  44. data/spec/unit/daedal/filters/range_filter_spec.rb +0 -1
  45. data/spec/unit/daedal/filters/term_filter_spec.rb +0 -1
  46. data/spec/unit/daedal/filters/terms_filter_spec.rb +4 -2
  47. data/spec/unit/daedal/queries/bool_query_spec.rb +1 -3
  48. data/spec/unit/daedal/queries/constant_score_query_spec.rb +0 -2
  49. data/spec/unit/daedal/queries/dis_max_query_spec.rb +1 -2
  50. data/spec/unit/daedal/queries/filtered_query_spec.rb +1 -3
  51. data/spec/unit/daedal/queries/fuzzy_query_spec.rb +89 -0
  52. data/spec/unit/daedal/queries/match_all_query_spec.rb +0 -1
  53. data/spec/unit/daedal/queries/match_query_spec.rb +2 -3
  54. data/spec/unit/daedal/queries/multi_match_query_spec.rb +2 -3
  55. data/spec/unit/daedal/queries/nested_query_spec.rb +0 -2
  56. data/spec/unit/daedal/queries/prefix_query_spec.rb +0 -1
  57. data/spec/unit/daedal/queries/query_string_spec.rb +296 -0
  58. metadata +18 -7
  59. data/lib/daedal/attributes.rb +0 -15
  60. data/lib/daedal/filters.rb +0 -11
  61. data/lib/daedal/queries.rb +0 -15
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
- require 'debugger'
4
2
 
5
3
  describe Daedal::Queries::BoolQuery do
6
4
 
@@ -55,7 +53,7 @@ describe Daedal::Queries::BoolQuery do
55
53
 
56
54
  context 'with a boost specified' do
57
55
  before do
58
- hash_query[:bool][:boost] = 2
56
+ hash_query[:bool][:boost] = 2.0
59
57
  end
60
58
  let(:query_with_boost) do
61
59
  subject.new(boost: 2)
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
- require 'daedal/filters'
4
2
 
5
3
  describe Daedal::Queries::ConstantScoreQuery do
6
4
 
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
2
 
4
3
  describe Daedal::Queries::DisMaxQuery do
5
4
 
@@ -52,7 +51,7 @@ describe Daedal::Queries::DisMaxQuery do
52
51
 
53
52
  context 'with a boost specified' do
54
53
  before do
55
- hash_query[:dis_max][:boost] = 2
54
+ hash_query[:dis_max][:boost] = 2.0
56
55
  end
57
56
  let(:query_with_boost) do
58
57
  subject.new(boost: 2)
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
- require 'daedal/filters'
4
2
 
5
3
  describe Daedal::Queries::FilteredQuery do
6
4
 
@@ -23,7 +21,7 @@ describe Daedal::Queries::FilteredQuery do
23
21
  context 'with no query or filter specified' do
24
22
 
25
23
  let(:base_filter) do
26
- Daedal::Filters::BaseFilter.new
24
+ Daedal::Filters::Filter.new
27
25
  end
28
26
  let(:match_all_query) do
29
27
  Daedal::Queries::MatchAllQuery.new
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Queries::FuzzyQuery do
4
+
5
+ subject do
6
+ Daedal::Queries::FuzzyQuery
7
+ end
8
+
9
+ let(:hash_query) do
10
+ {fuzzy: {foo: {value: :bar}}}
11
+ end
12
+
13
+ context 'without a field' do
14
+ it 'will raise an error' do
15
+ expect{subject.new(query: :foo)}.to raise_error
16
+ end
17
+ end
18
+
19
+ context 'without a search term' do
20
+ it 'will raise an error' do
21
+ expect{subject.new(field: :foo)}.to raise_error
22
+ end
23
+ end
24
+
25
+ context 'with a field and a search term' do
26
+ let(:query) do
27
+ subject.new field: :foo, query: :bar
28
+ end
29
+ it 'will create a fuzzy query with the correct fields' do
30
+ expect(query.field).to eq :foo
31
+ expect(query.query).to eq :bar
32
+ end
33
+ it 'will have the correct hash and json representations' do
34
+ expect(query.to_hash).to eq hash_query
35
+ expect(query.to_json).to eq hash_query.to_json
36
+ end
37
+ end
38
+
39
+ context 'with a boost specified' do
40
+ let(:query) do
41
+ subject.new field: :foo, query: :bar, boost: 5.0
42
+ end
43
+
44
+ before do
45
+ hash_query[:fuzzy][:foo][:boost] = 5.0
46
+ end
47
+ it 'will set the boost correctly' do
48
+ expect(query.boost).to eq 5.0
49
+ end
50
+ it 'will have the correct hash and json representations' do
51
+ expect(query.to_hash).to eq hash_query
52
+ expect(query.to_json).to eq hash_query.to_json
53
+ end
54
+ end
55
+
56
+ context 'with a min_similarity specified' do
57
+ let(:query) do
58
+ subject.new field: :foo, query: :bar, min_similarity: 0.5
59
+ end
60
+
61
+ before do
62
+ hash_query[:fuzzy][:foo][:min_similarity] = 0.5
63
+ end
64
+ it 'will set the min_similarity correctly' do
65
+ expect(query.min_similarity).to eq 0.5
66
+ end
67
+ it 'will have the correct hash and json representations' do
68
+ expect(query.to_hash).to eq hash_query
69
+ expect(query.to_json).to eq hash_query.to_json
70
+ end
71
+ end
72
+
73
+ context 'with a prefix_length specified' do
74
+ let(:query) do
75
+ subject.new field: :foo, query: :bar, prefix_length: 1
76
+ end
77
+
78
+ before do
79
+ hash_query[:fuzzy][:foo][:prefix_length] = 1
80
+ end
81
+ it 'will set the prefix_length correctly' do
82
+ expect(query.prefix_length).to eq 1
83
+ end
84
+ it 'will have the correct hash and json representations' do
85
+ expect(query.to_hash).to eq hash_query
86
+ expect(query.to_json).to eq hash_query.to_json
87
+ end
88
+ end
89
+ end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
2
 
4
3
  describe Daedal::Queries::MatchAllQuery do
5
4
 
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
2
 
4
3
  describe Daedal::Queries::MatchQuery do
5
4
 
@@ -193,11 +192,11 @@ describe Daedal::Queries::MatchQuery do
193
192
  end
194
193
 
195
194
  before do
196
- base_query[:match][:foo][:boost] = 2
195
+ base_query[:match][:foo][:boost] = 2.0
197
196
  end
198
197
 
199
198
  it 'will set the phrase type to :phrase' do
200
- expect(match_query.boost).to eq 2
199
+ expect(match_query.boost).to eq 2.0
201
200
  end
202
201
 
203
202
  it 'will have the correct hash representation' do
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
2
 
4
3
  describe Daedal::Queries::MultiMatchQuery do
5
4
 
@@ -201,11 +200,11 @@ describe Daedal::Queries::MultiMatchQuery do
201
200
  end
202
201
 
203
202
  before do
204
- base_query[:multi_match][:boost] = 2
203
+ base_query[:multi_match][:boost] = 2.0
205
204
  end
206
205
 
207
206
  it 'will set the phrase type to :phrase' do
208
- expect(query.boost).to eq 2
207
+ expect(query.boost).to eq 2.0
209
208
  end
210
209
 
211
210
  it 'will have the correct hash representation' do
@@ -1,6 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
- require 'daedal/filters'
4
2
 
5
3
  describe Daedal::Queries::NestedQuery do
6
4
 
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'daedal/queries'
3
2
 
4
3
  describe Daedal::Queries::PrefixQuery do
5
4
 
@@ -0,0 +1,296 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Queries::QueryStringQuery do
4
+
5
+ subject do
6
+ Daedal::Queries::QueryStringQuery
7
+ end
8
+
9
+ let(:hash_query) do
10
+ {query_string: {query: 'foo'}}
11
+ end
12
+
13
+ context 'without a query string' do
14
+ it 'will raise an error' do
15
+ expect{subject.new}.to raise_error(Virtus::CoercionError)
16
+ end
17
+ end
18
+
19
+ context 'with a query that is not a string given' do
20
+ let(:query) do
21
+ subject.new query: :foo
22
+ end
23
+ it 'will convert to a string' do
24
+ expect(query.query).to eq 'foo'
25
+ end
26
+ end
27
+
28
+ context 'with a query' do
29
+ let(:query) do
30
+ subject.new query: 'foo'
31
+ end
32
+ it 'will create a query string with the correct value' do
33
+ expect(query.query).to eq 'foo'
34
+ end
35
+ it 'will have the correct hash and json representation' do
36
+ expect(query.to_hash).to eq hash_query
37
+ expect(query.to_json).to eq hash_query.to_json
38
+ end
39
+ end
40
+
41
+ context 'with a default_field' do
42
+ let(:query) do
43
+ subject.new query: 'foo', default_field: :bar
44
+ end
45
+ before do
46
+ hash_query[:query_string][:default_field] = :bar
47
+ end
48
+ it 'will set the default_field' do
49
+ expect(query.default_field).to eq :bar
50
+ end
51
+ it 'will have the correct hash and json representations' do
52
+ expect(query.to_hash).to eq hash_query
53
+ expect(query.to_json).to eq hash_query.to_json
54
+ end
55
+ end
56
+
57
+ context 'with an array of fields' do
58
+ let(:query) do
59
+ subject.new query: 'foo', fields: [:bar]
60
+ end
61
+ before do
62
+ hash_query[:query_string][:fields] = [:bar]
63
+ end
64
+ it 'will set the fields' do
65
+ expect(query.fields).to eq [:bar]
66
+ end
67
+ it 'will have the correct hash and json representations' do
68
+ expect(query.to_hash).to eq hash_query
69
+ expect(query.to_json).to eq hash_query.to_json
70
+ end
71
+ end
72
+
73
+ context 'with a default_operator' do
74
+ let(:query) do
75
+ subject.new query: 'foo', default_operator: 'OR'
76
+ end
77
+ before do
78
+ hash_query[:query_string][:default_operator] = 'OR'
79
+ end
80
+ it 'will set the default_operator' do
81
+ expect(query.default_operator).to eq 'OR'
82
+ end
83
+ it 'will have the correct hash and json representations' do
84
+ expect(query.to_hash).to eq hash_query
85
+ expect(query.to_json).to eq hash_query.to_json
86
+ end
87
+ end
88
+
89
+ context 'with an analyzer' do
90
+ let(:query) do
91
+ subject.new query: 'foo', analyzer: :bar
92
+ end
93
+ before do
94
+ hash_query[:query_string][:analyzer] = :bar
95
+ end
96
+ it 'will set the analyzer' do
97
+ expect(query.analyzer).to eq :bar
98
+ end
99
+ it 'will have the correct hash and json representations' do
100
+ expect(query.to_hash).to eq hash_query
101
+ expect(query.to_json).to eq hash_query.to_json
102
+ end
103
+ end
104
+
105
+ context 'with a allow_leading_wildcard' do
106
+ let(:query) do
107
+ subject.new query: 'foo', allow_leading_wildcard: true
108
+ end
109
+ before do
110
+ hash_query[:query_string][:allow_leading_wildcard] = true
111
+ end
112
+ it 'will set the allow_leading_wildcard' do
113
+ expect(query.allow_leading_wildcard).to eq true
114
+ end
115
+ it 'will have the correct hash and json representations' do
116
+ expect(query.to_hash).to eq hash_query
117
+ expect(query.to_json).to eq hash_query.to_json
118
+ end
119
+ end
120
+
121
+ context 'with a lowercase_expanded_terms' do
122
+ let(:query) do
123
+ subject.new query: 'foo', lowercase_expanded_terms: true
124
+ end
125
+ before do
126
+ hash_query[:query_string][:lowercase_expanded_terms] = true
127
+ end
128
+ it 'will set the lowercase_expanded_terms' do
129
+ expect(query.lowercase_expanded_terms).to eq true
130
+ end
131
+ it 'will have the correct hash and json representations' do
132
+ expect(query.to_hash).to eq hash_query
133
+ expect(query.to_json).to eq hash_query.to_json
134
+ end
135
+ end
136
+
137
+ context 'with a enable_position_increments' do
138
+ let(:query) do
139
+ subject.new query: 'foo', enable_position_increments: true
140
+ end
141
+ before do
142
+ hash_query[:query_string][:enable_position_increments] = true
143
+ end
144
+ it 'will set the enable_position_increments' do
145
+ expect(query.enable_position_increments).to eq true
146
+ end
147
+ it 'will have the correct hash and json representations' do
148
+ expect(query.to_hash).to eq hash_query
149
+ expect(query.to_json).to eq hash_query.to_json
150
+ end
151
+ end
152
+
153
+ context 'with a fuzzy_max_expansions' do
154
+ let(:query) do
155
+ subject.new query: 'foo', fuzzy_max_expansions: 50
156
+ end
157
+ before do
158
+ hash_query[:query_string][:fuzzy_max_expansions] = 50
159
+ end
160
+ it 'will set the fuzzy_max_expansions' do
161
+ expect(query.fuzzy_max_expansions).to eq 50
162
+ end
163
+ it 'will have the correct hash and json representations' do
164
+ expect(query.to_hash).to eq hash_query
165
+ expect(query.to_json).to eq hash_query.to_json
166
+ end
167
+ end
168
+
169
+ context 'with a fuzzy_min_sim' do
170
+ let(:query) do
171
+ subject.new query: 'foo', fuzzy_min_sim: 0.5
172
+ end
173
+ before do
174
+ hash_query[:query_string][:fuzzy_min_sim] = 0.5
175
+ end
176
+ it 'will set the fuzzy_min_sim' do
177
+ expect(query.fuzzy_min_sim).to eq 0.5
178
+ end
179
+ it 'will have the correct hash and json representations' do
180
+ expect(query.to_hash).to eq hash_query
181
+ expect(query.to_json).to eq hash_query.to_json
182
+ end
183
+ end
184
+
185
+ context 'with a fuzzy_prefix_length' do
186
+ let(:query) do
187
+ subject.new query: 'foo', fuzzy_prefix_length: 0
188
+ end
189
+ before do
190
+ hash_query[:query_string][:fuzzy_prefix_length] = 0
191
+ end
192
+ it 'will set the fuzzy_prefix_length' do
193
+ expect(query.fuzzy_prefix_length).to eq 0
194
+ end
195
+ it 'will have the correct hash and json representations' do
196
+ expect(query.to_hash).to eq hash_query
197
+ expect(query.to_json).to eq hash_query.to_json
198
+ end
199
+ end
200
+
201
+ context 'with a phrase_slop' do
202
+ let(:query) do
203
+ subject.new query: 'foo', phrase_slop: 2
204
+ end
205
+ before do
206
+ hash_query[:query_string][:phrase_slop] = 2
207
+ end
208
+ it 'will set the phrase_slop' do
209
+ expect(query.phrase_slop).to eq 2
210
+ end
211
+ it 'will have the correct hash and json representations' do
212
+ expect(query.to_hash).to eq hash_query
213
+ expect(query.to_json).to eq hash_query.to_json
214
+ end
215
+ end
216
+
217
+ context 'with a boost' do
218
+ let(:query) do
219
+ subject.new query: 'foo', boost: 1.0
220
+ end
221
+ before do
222
+ hash_query[:query_string][:boost] = 1.0
223
+ end
224
+ it 'will set the boost' do
225
+ expect(query.boost).to eq 1.0
226
+ end
227
+ it 'will have the correct hash and json representations' do
228
+ expect(query.to_hash).to eq hash_query
229
+ expect(query.to_json).to eq hash_query.to_json
230
+ end
231
+ end
232
+
233
+ context 'with a analyze_wildcard' do
234
+ let(:query) do
235
+ subject.new query: 'foo', analyze_wildcard: true
236
+ end
237
+ before do
238
+ hash_query[:query_string][:analyze_wildcard] = true
239
+ end
240
+ it 'will set the analyze_wildcard' do
241
+ expect(query.analyze_wildcard).to eq true
242
+ end
243
+ it 'will have the correct hash and json representations' do
244
+ expect(query.to_hash).to eq hash_query
245
+ expect(query.to_json).to eq hash_query.to_json
246
+ end
247
+ end
248
+
249
+ context 'with a auto_generate_phrase_queries' do
250
+ let(:query) do
251
+ subject.new query: 'foo', auto_generate_phrase_queries: true
252
+ end
253
+ before do
254
+ hash_query[:query_string][:auto_generate_phrase_queries] = true
255
+ end
256
+ it 'will set the auto_generate_phrase_queries' do
257
+ expect(query.auto_generate_phrase_queries).to eq true
258
+ end
259
+ it 'will have the correct hash and json representations' do
260
+ expect(query.to_hash).to eq hash_query
261
+ expect(query.to_json).to eq hash_query.to_json
262
+ end
263
+ end
264
+
265
+ context 'with a minimum_should_match' do
266
+ let(:query) do
267
+ subject.new query: 'foo', minimum_should_match: 2
268
+ end
269
+ before do
270
+ hash_query[:query_string][:minimum_should_match] = 2
271
+ end
272
+ it 'will set the minimum_should_match' do
273
+ expect(query.minimum_should_match).to eq 2
274
+ end
275
+ it 'will have the correct hash and json representations' do
276
+ expect(query.to_hash).to eq hash_query
277
+ expect(query.to_json).to eq hash_query.to_json
278
+ end
279
+ end
280
+
281
+ context 'with a lenient' do
282
+ let(:query) do
283
+ subject.new query: 'foo', lenient: true
284
+ end
285
+ before do
286
+ hash_query[:query_string][:lenient] = true
287
+ end
288
+ it 'will set the lenient' do
289
+ expect(query.lenient).to eq true
290
+ end
291
+ it 'will have the correct hash and json representations' do
292
+ expect(query.to_hash).to eq hash_query
293
+ expect(query.to_json).to eq hash_query.to_json
294
+ end
295
+ end
296
+ end