daedal 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +29 -1
  5. data/daedal.gemspec +1 -1
  6. data/lib/daedal/attributes.rb +5 -0
  7. data/lib/daedal/attributes/distance_unit.rb +15 -0
  8. data/lib/daedal/attributes/filter.rb +13 -0
  9. data/lib/daedal/attributes/filter_array.rb +24 -0
  10. data/lib/daedal/attributes/lower_case_string.rb +14 -0
  11. data/lib/daedal/attributes/query.rb +13 -0
  12. data/lib/daedal/attributes/query_array.rb +2 -0
  13. data/lib/daedal/filters.rb +3 -0
  14. data/lib/daedal/filters/and_filter.rb +21 -0
  15. data/lib/daedal/filters/base_filter.rb +1 -1
  16. data/lib/daedal/filters/geo_distance_filter.rb +27 -0
  17. data/lib/daedal/filters/range_filter.rb +27 -0
  18. data/lib/daedal/queries.rb +1 -0
  19. data/lib/daedal/queries/bool_query.rb +5 -4
  20. data/lib/daedal/queries/constant_score_query.rb +2 -2
  21. data/lib/daedal/queries/dis_max_query.rb +3 -2
  22. data/lib/daedal/queries/filtered_query.rb +2 -2
  23. data/lib/daedal/queries/match_query.rb +2 -1
  24. data/lib/daedal/queries/nested_query.rb +4 -4
  25. data/lib/daedal/queries/prefix_query.rb +25 -0
  26. data/lib/daedal/version.rb +3 -0
  27. data/spec/unit/daedal/filters/and_filter_spec.rb +87 -0
  28. data/spec/unit/daedal/filters/geo_distance_filter_spec.rb +104 -0
  29. data/spec/unit/daedal/filters/range_filter_spec.rb +90 -0
  30. data/spec/unit/daedal/filters/term_filter_spec.rb +3 -3
  31. data/spec/unit/daedal/filters/terms_filter_spec.rb +2 -2
  32. data/spec/unit/daedal/queries/bool_query_spec.rb +42 -4
  33. data/spec/unit/daedal/queries/constant_score_query_spec.rb +3 -3
  34. data/spec/unit/daedal/queries/dis_max_query_spec.rb +18 -2
  35. data/spec/unit/daedal/queries/filtered_query_spec.rb +3 -3
  36. data/spec/unit/daedal/queries/match_query_spec.rb +36 -8
  37. data/spec/unit/daedal/queries/multi_match_query_spec.rb +8 -8
  38. data/spec/unit/daedal/queries/nested_query_spec.rb +4 -4
  39. data/spec/unit/daedal/queries/prefix_query_spec.rb +85 -0
  40. metadata +17 -3
@@ -37,19 +37,19 @@ describe Daedal::Queries::FilteredQuery do
37
37
  expect(query.filter.to_hash).to eq base_filter.to_hash
38
38
  end
39
39
  it 'will have the correct hash representation' do
40
- expect(query.to_hash).to eq({filtered: {query: {match_all: {}}, filter: {}}})
40
+ expect(query.to_hash).to eq({filtered: {query: {match_all: {}}, filter: nil}})
41
41
  end
42
42
  end
43
43
 
44
44
  context 'with an invalid query specified' do
45
45
  it 'will raise an error' do
46
- expect{subject.new(query: :foo)}.to raise_error
46
+ expect{subject.new(query: :foo)}.to raise_error(Virtus::CoercionError)
47
47
  end
48
48
  end
49
49
 
50
50
  context 'with an invalid filter specified' do
51
51
  it 'will raise an error' do
52
- expect{subject.new(filter: :foo)}.to raise_error
52
+ expect{subject.new(filter: :foo)}.to raise_error(Virtus::CoercionError)
53
53
  end
54
54
  end
55
55
 
@@ -13,13 +13,13 @@ describe Daedal::Queries::MatchQuery do
13
13
 
14
14
  context 'without a field or term given' do
15
15
  it 'will raise an error' do
16
- expect {subject.new}.to raise_error
16
+ expect {subject.new}.to raise_error(Virtus::CoercionError)
17
17
  end
18
18
  end
19
19
 
20
20
  context 'without a term given' do
21
21
  it 'will raise an error' do
22
- expect {subject.new(field: :foo)}.to raise_error
22
+ expect {subject.new(field: :foo)}.to raise_error(Virtus::CoercionError)
23
23
  end
24
24
  end
25
25
 
@@ -77,7 +77,7 @@ describe Daedal::Queries::MatchQuery do
77
77
 
78
78
  context 'with a non-valid operator specified' do
79
79
  it 'will raise an error' do
80
- expect {subject.new(field: :foo, query: :bar, operator: :foo)}.to raise_error
80
+ expect {subject.new(field: :foo, query: :bar, operator: :foo)}.to raise_error(Virtus::CoercionError)
81
81
  end
82
82
  end
83
83
 
@@ -105,7 +105,7 @@ describe Daedal::Queries::MatchQuery do
105
105
 
106
106
  context 'with a non-valid type specified' do
107
107
  it 'will raise an error' do
108
- expect {subject.new(field: :foo, query: :bar, type: :foo)}.to raise_error
108
+ expect {subject.new(field: :foo, query: :bar, type: :foo)}.to raise_error(Virtus::CoercionError)
109
109
  end
110
110
  end
111
111
 
@@ -133,7 +133,7 @@ describe Daedal::Queries::MatchQuery do
133
133
 
134
134
  context 'with a non-integer minimum should match specified' do
135
135
  it 'will raise an error' do
136
- expect {subject.new(field: :foo, query: :bar, minimum_should_match: 'foo')}.to raise_error
136
+ expect {subject.new(field: :foo, query: :bar, minimum_should_match: 'foo')}.to raise_error(Virtus::CoercionError)
137
137
  end
138
138
  end
139
139
 
@@ -161,7 +161,7 @@ describe Daedal::Queries::MatchQuery do
161
161
 
162
162
  context 'with a non-float cutoff frequency specified' do
163
163
  it 'will raise an error' do
164
- expect {subject.new(field: :foo, query: :bar, cutoff_frequency: 'foo')}.to raise_error
164
+ expect {subject.new(field: :foo, query: :bar, cutoff_frequency: 'foo')}.to raise_error(Virtus::CoercionError)
165
165
  end
166
166
  end
167
167
 
@@ -211,7 +211,35 @@ describe Daedal::Queries::MatchQuery do
211
211
 
212
212
  context 'with a non integer boost specified' do
213
213
  it 'will raise an error' do
214
- expect {subject.new(field: :foo, query: :bar, boost: 'foo')}.to raise_error
214
+ expect {subject.new(field: :foo, query: :bar, boost: 'foo')}.to raise_error(Virtus::CoercionError)
215
+ end
216
+ end
217
+
218
+ context 'with a slop of 2 specified' do
219
+ let(:match_query) do
220
+ subject.new(field: :foo, query: :bar, slop: 2)
221
+ end
222
+
223
+ before do
224
+ base_query[:match][:foo][:slop] = 2
225
+ end
226
+
227
+ it 'will set the phrase type to :phrase' do
228
+ expect(match_query.slop).to eq 2
229
+ end
230
+
231
+ it 'will have the correct hash representation' do
232
+ expect(match_query.to_hash).to eq base_query
233
+ end
234
+
235
+ it 'will have the correct json representation' do
236
+ expect(match_query.to_json).to eq base_query.to_json
237
+ end
238
+ end
239
+
240
+ context 'with a non integer slop specified' do
241
+ it 'will raise an error' do
242
+ expect {subject.new(field: :foo, query: :bar, slop: 'foo')}.to raise_error(Virtus::CoercionError)
215
243
  end
216
244
  end
217
245
 
@@ -239,7 +267,7 @@ describe Daedal::Queries::MatchQuery do
239
267
 
240
268
  context 'with a non float or integer fuzziness specified' do
241
269
  it 'will raise an error' do
242
- expect {subject.new(field: :foo, query: :bar, fuzziness: 'foo')}.to raise_error
270
+ expect {subject.new(field: :foo, query: :bar, fuzziness: 'foo')}.to raise_error(Virtus::CoercionError)
243
271
  end
244
272
  end
245
273
  end
@@ -21,13 +21,13 @@ describe Daedal::Queries::MultiMatchQuery do
21
21
 
22
22
  context 'without a field or term given' do
23
23
  it 'will raise an error' do
24
- expect {subject.new}.to raise_error
24
+ expect {subject.new}.to raise_error(Virtus::CoercionError)
25
25
  end
26
26
  end
27
27
 
28
28
  context 'without fields given' do
29
29
  it 'will raise an error' do
30
- expect {subject.new(query: term)}.to raise_error
30
+ expect {subject.new(query: term)}.to raise_error(RuntimeError)
31
31
  end
32
32
  end
33
33
 
@@ -85,7 +85,7 @@ describe Daedal::Queries::MultiMatchQuery do
85
85
 
86
86
  context 'with a non-valid operator specified' do
87
87
  it 'will raise an error' do
88
- expect {subject.new(query: term, fields: fields, operator: :foo)}.to raise_error
88
+ expect {subject.new(query: term, fields: fields, operator: :foo)}.to raise_error(Virtus::CoercionError)
89
89
  end
90
90
  end
91
91
 
@@ -113,7 +113,7 @@ describe Daedal::Queries::MultiMatchQuery do
113
113
 
114
114
  context 'with a non-valid type specified' do
115
115
  it 'will raise an error' do
116
- expect {subject.new(query: term, fields: fields, type: :foo)}.to raise_error
116
+ expect {subject.new(query: term, fields: fields, type: :foo)}.to raise_error(Virtus::CoercionError)
117
117
  end
118
118
  end
119
119
 
@@ -141,7 +141,7 @@ describe Daedal::Queries::MultiMatchQuery do
141
141
 
142
142
  context 'with a non-integer minimum should match specified' do
143
143
  it 'will raise an error' do
144
- expect {subject.new(query: term, fields: fields, minimum_should_match: 'foo')}.to raise_error
144
+ expect {subject.new(query: term, fields: fields, minimum_should_match: 'foo')}.to raise_error(Virtus::CoercionError)
145
145
  end
146
146
  end
147
147
 
@@ -169,7 +169,7 @@ describe Daedal::Queries::MultiMatchQuery do
169
169
 
170
170
  context 'with a non-float cutoff frequency specified' do
171
171
  it 'will raise an error' do
172
- expect {subject.new(query: term, fields: fields, cutoff_frequency: 'foo')}.to raise_error
172
+ expect {subject.new(query: term, fields: fields, cutoff_frequency: 'foo')}.to raise_error(Virtus::CoercionError)
173
173
  end
174
174
  end
175
175
 
@@ -219,7 +219,7 @@ describe Daedal::Queries::MultiMatchQuery do
219
219
 
220
220
  context 'with a non integer boost specified' do
221
221
  it 'will raise an error' do
222
- expect {subject.new(query: term, fields: fields, boost: 'foo')}.to raise_error
222
+ expect {subject.new(query: term, fields: fields, boost: 'foo')}.to raise_error(Virtus::CoercionError)
223
223
  end
224
224
  end
225
225
 
@@ -247,7 +247,7 @@ describe Daedal::Queries::MultiMatchQuery do
247
247
 
248
248
  context 'with a non float or integer fuzziness specified' do
249
249
  it 'will raise an error' do
250
- expect {subject.new(query: term, fields: fields, fuzziness: 'foo')}.to raise_error
250
+ expect {subject.new(query: term, fields: fields, fuzziness: 'foo')}.to raise_error(Virtus::CoercionError)
251
251
  end
252
252
  end
253
253
  end
@@ -14,19 +14,19 @@ describe Daedal::Queries::NestedQuery do
14
14
 
15
15
  context 'with no path specified' do
16
16
  it 'will raise an error' do
17
- expect{subject.new(query: match_all_query)}.to raise_error
17
+ expect{subject.new(query: match_all_query)}.to raise_error(Virtus::CoercionError)
18
18
  end
19
19
  end
20
20
 
21
21
  context 'with no query specified' do
22
22
  it 'will raise an error' do
23
- expect{subject.new(path: 'foo')}.to raise_error
23
+ expect{subject.new(path: 'foo')}.to raise_error(Virtus::CoercionError)
24
24
  end
25
25
  end
26
26
 
27
27
  context 'with an invalid query specified' do
28
28
  it 'will raise an error' do
29
- expect{subject.new(query: :foo)}.to raise_error
29
+ expect{subject.new(query: :foo)}.to raise_error(Virtus::CoercionError)
30
30
  end
31
31
  end
32
32
 
@@ -76,7 +76,7 @@ describe Daedal::Queries::NestedQuery do
76
76
 
77
77
  context 'with an invalid score_mode specified' do
78
78
  it 'will raise an error' do
79
- expect{subject.new(query: match_all_query, path: :foo, score_mode: 'foo')}.to raise_error
79
+ expect{subject.new(query: match_all_query, path: :foo, score_mode: 'foo')}.to raise_error(Virtus::CoercionError)
80
80
  end
81
81
  end
82
82
  end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'daedal/queries'
3
+
4
+ describe Daedal::Queries::PrefixQuery do
5
+
6
+ subject do
7
+ Daedal::Queries::PrefixQuery
8
+ end
9
+
10
+ context 'with no field or term specified' do
11
+ it 'will raise an error' do
12
+ expect {subject.new}.to raise_error(Virtus::CoercionError)
13
+ end
14
+ end
15
+
16
+ context 'with no field specified' do
17
+ it 'will raise an error' do
18
+ expect {subject.new(query: :foo)}.to raise_error(Virtus::CoercionError)
19
+ end
20
+ end
21
+
22
+ context 'with no term specified' do
23
+ it 'will raise an error' do
24
+ expect {subject.new(field: :foo)}.to raise_error(Virtus::CoercionError)
25
+ end
26
+ end
27
+
28
+ context 'with a field and a term specified' do
29
+ let(:query) do
30
+ subject.new(field: :foo, query: :bar)
31
+ end
32
+ let(:hash_query) do
33
+ {prefix: {foo: 'bar'}}
34
+ end
35
+
36
+ it 'will create a prefix query with the correct values' do
37
+ expect(query.field).to eq :foo
38
+ expect(query.query).to eq 'bar'
39
+ end
40
+
41
+ it 'will have the correct hash and json representation' do
42
+ expect(query.to_hash).to eq hash_query
43
+ expect(query.to_json).to eq hash_query.to_json
44
+ end
45
+ end
46
+
47
+ context 'with a field and an upper cased term specified' do
48
+ let(:query) do
49
+ subject.new(field: :foo, query: 'Bar')
50
+ end
51
+ let(:hash_query) do
52
+ {prefix: {foo: 'bar'}}
53
+ end
54
+
55
+ it 'will create a prefix query and downcase the term' do
56
+ expect(query.field).to eq :foo
57
+ expect(query.query).to eq 'bar'
58
+ end
59
+
60
+ it 'will have the correct hash and json representations' do
61
+ expect(query.to_hash).to eq hash_query
62
+ expect(query.to_json).to eq hash_query.to_json
63
+ end
64
+ end
65
+
66
+ context 'with a boost specified' do
67
+ let(:query) do
68
+ subject.new(field: :foo, query: :bar, boost: 5.0)
69
+ end
70
+ let(:hash_query) do
71
+ {prefix: {foo: 'bar', boost: 5.0}}
72
+ end
73
+
74
+ it 'will create a prefix query with the correct values' do
75
+ expect(query.field).to eq :foo
76
+ expect(query.query).to eq 'bar'
77
+ expect(query.boost).to eq 5.0
78
+ end
79
+
80
+ it 'will have the correct hash and json representation' do
81
+ expect(query.to_hash).to eq hash_query
82
+ expect(query.to_json).to eq hash_query.to_json
83
+ end
84
+ end
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daedal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Schuch
@@ -14,14 +14,14 @@ dependencies:
14
14
  name: virtus
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.0
27
27
  description: Classes for easier ElasticSearch query creation
@@ -40,12 +40,20 @@ files:
40
40
  - daedal.gemspec
41
41
  - lib/daedal.rb
42
42
  - lib/daedal/attributes.rb
43
+ - lib/daedal/attributes/distance_unit.rb
44
+ - lib/daedal/attributes/filter.rb
45
+ - lib/daedal/attributes/filter_array.rb
46
+ - lib/daedal/attributes/lower_case_string.rb
43
47
  - lib/daedal/attributes/match_type.rb
44
48
  - lib/daedal/attributes/operator.rb
49
+ - lib/daedal/attributes/query.rb
45
50
  - lib/daedal/attributes/query_array.rb
46
51
  - lib/daedal/attributes/score_mode.rb
47
52
  - lib/daedal/filters.rb
53
+ - lib/daedal/filters/and_filter.rb
48
54
  - lib/daedal/filters/base_filter.rb
55
+ - lib/daedal/filters/geo_distance_filter.rb
56
+ - lib/daedal/filters/range_filter.rb
49
57
  - lib/daedal/filters/term_filter.rb
50
58
  - lib/daedal/filters/terms_filter.rb
51
59
  - lib/daedal/queries.rb
@@ -58,7 +66,12 @@ files:
58
66
  - lib/daedal/queries/match_query.rb
59
67
  - lib/daedal/queries/multi_match_query.rb
60
68
  - lib/daedal/queries/nested_query.rb
69
+ - lib/daedal/queries/prefix_query.rb
70
+ - lib/daedal/version.rb
61
71
  - spec/spec_helper.rb
72
+ - spec/unit/daedal/filters/and_filter_spec.rb
73
+ - spec/unit/daedal/filters/geo_distance_filter_spec.rb
74
+ - spec/unit/daedal/filters/range_filter_spec.rb
62
75
  - spec/unit/daedal/filters/term_filter_spec.rb
63
76
  - spec/unit/daedal/filters/terms_filter_spec.rb
64
77
  - spec/unit/daedal/queries/bool_query_spec.rb
@@ -69,6 +82,7 @@ files:
69
82
  - spec/unit/daedal/queries/match_query_spec.rb
70
83
  - spec/unit/daedal/queries/multi_match_query_spec.rb
71
84
  - spec/unit/daedal/queries/nested_query_spec.rb
85
+ - spec/unit/daedal/queries/prefix_query_spec.rb
72
86
  homepage: https://github.com/cschuch/daedal
73
87
  licenses:
74
88
  - MIT