daedal 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWY3ZDMyOWU5OTNhZWEzNDViNGYwZjkxZDQ1Y2E3MTczODM4MzlmYQ==
4
+ ZGMxMGUzOWUzOTllYzcyZmVmNTViYmMxOWFiYzBiNTc1ODA4MDY0Yg==
5
5
  data.tar.gz: !binary |-
6
- ZDY2ZTFjYmRmNDAzMjRiYjgyYjI4NGNkZTc2Mzg2NTYzZGI3NzNmZQ==
6
+ ZTMzZDNhMTI3ZWY3ZDg2YzAxYmUzZGQwM2JkZDYwNTQwNWEyYzdiMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzQ4YjZiMjFjNGFjOWZlZDQ0YjlmMjZmZWFiMWZkYjBkNTFkOGNkOWNkMmI4
10
- ZGQ2YjE4NzkyN2E2NjA4ZjFkOTAzN2JkNGU1NzVmOTMyMjE4YTA3Nzc2YmVm
11
- YWYyYTlmMjRhNTc1OTlmOTI0YzJkZjNkNzgwNmU2YzEwNzFjMGU=
9
+ MDAzODBjM2E0M2Y5NDVkNzllNWQzY2ZhZTVmNWExOGQ1MzJlZjE1ZDVkYTZi
10
+ ZDk5MzI3NGRlMzU4NjRiNWM4Y2ZlNmRjYTdhYzMxNjM2NzViMGYwZWMyNzVi
11
+ ODc0YjBhNmVlNzljZDc5MDFjNzYxNTYzZDhlYzU3ODk4NWEwYjQ=
12
12
  data.tar.gz: !binary |-
13
- NGZmY2I4NjYyZGU4NjFhOTY2MmM2NDRkZGZjNjU5MzcyMjU4NGQ4ZGNjYmJk
14
- ODNiYTg1YzNhMDI4N2Y5NDE0ZDZlMjBiZWIzNThhNTRmNDU4YzVmMWNjYzU1
15
- MTFjYmI0NTgwNzE2MGY5ZDdjODM0ODNiMmIwZmJmOWYwYzZlYjc=
13
+ MmI3ZTM4OTlmMDFjZmY2YTk4ZTQ2MWU3ZDRlODUyZTA2NjVmZTI0NDFhNjJh
14
+ YzZlOWRhYWM2ZGVmZmZhNDBkMTc2ZWNkODdlY2Q1NTdmMDRhNGIzYjVjZjA4
15
+ NzRiZDMyODZhNTVmYzc2MTJmYmRjZjJjNDYzYWRmMzAwOTQyNzc=
data/Gemfile.lock CHANGED
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daedal (0.0.5)
4
+ daedal (0.0.10)
5
5
  virtus (>= 1.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- axiom-types (0.0.5)
11
- descendants_tracker (~> 0.0.1)
12
- ice_nine (~> 0.9)
13
- backports (3.3.5)
10
+ atomic (1.1.16)
11
+ axiom-types (0.1.0)
12
+ descendants_tracker (~> 0.0.3)
13
+ ice_nine (~> 0.11.0)
14
+ thread_safe (~> 0.1.3)
14
15
  celluloid (0.15.2)
15
16
  timers (~> 1.1.0)
16
17
  coderay (1.1.0)
17
- coercible (0.2.0)
18
- backports (~> 3.0, >= 3.1.0)
18
+ coercible (1.0.0)
19
19
  descendants_tracker (~> 0.0.1)
20
20
  coveralls (0.7.0)
21
21
  multi_json (~> 1.3)
@@ -25,7 +25,7 @@ GEM
25
25
  thor
26
26
  descendants_tracker (0.0.3)
27
27
  diff-lcs (1.2.5)
28
- equalizer (0.0.8)
28
+ equalizer (0.0.9)
29
29
  ffi (1.9.3)
30
30
  formatador (0.2.4)
31
31
  fuubar (1.2.1)
@@ -41,7 +41,7 @@ GEM
41
41
  guard-rspec (4.2.0)
42
42
  guard (>= 2.1.1)
43
43
  rspec (>= 2.14, < 4.0)
44
- ice_nine (0.10.0)
44
+ ice_nine (0.11.0)
45
45
  listen (2.4.0)
46
46
  celluloid (>= 0.15.2)
47
47
  rb-fsevent (>= 0.9.3)
@@ -77,13 +77,15 @@ GEM
77
77
  term-ansicolor (1.2.2)
78
78
  tins (~> 0.8)
79
79
  thor (0.18.1)
80
+ thread_safe (0.1.3)
81
+ atomic
80
82
  timers (1.1.0)
81
83
  tins (0.13.1)
82
- virtus (1.0.0)
83
- axiom-types (~> 0.0.5)
84
- coercible (~> 0.2)
85
- descendants_tracker (~> 0.0.1)
86
- equalizer (~> 0.0.7)
84
+ virtus (1.0.2)
85
+ axiom-types (~> 0.1)
86
+ coercible (~> 1.0)
87
+ descendants_tracker (~> 0.0.3)
88
+ equalizer (~> 0.0.9)
87
89
 
88
90
  PLATFORMS
89
91
  ruby
data/README.md CHANGED
@@ -136,8 +136,6 @@ Currently, the following filters have been implemented:
136
136
  * [range filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html)
137
137
  * [term filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html)
138
138
  * [terms filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html)
139
-
140
- On deck:
141
139
  * [nested filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html)
142
140
 
143
141
  ### Type checking and attribute coercion
@@ -2,7 +2,7 @@ module Daedal
2
2
  module Attributes
3
3
  """Custom coercer for the type attribute"""
4
4
  class MatchType < Virtus::Attribute
5
- ALLOWED_MATCH_TYPES = [:phrase, :phrase_prefix]
5
+ ALLOWED_MATCH_TYPES = [:phrase, :phrase_prefix, :best_fields, :most_fields, :cross_fields]
6
6
  def coerce(value)
7
7
  unless value.nil?
8
8
  value = value.to_sym
@@ -11,10 +11,12 @@ module Daedal
11
11
  attribute :boost, Daedal::Attributes::Boost, required: false
12
12
  attribute :min_similarity, Daedal::Attributes::QueryValue, required: false
13
13
  attribute :prefix_length, Integer, required: false
14
+ attribute :max_expansions, Integer, required: false
15
+ attribute :fuzziness, Daedal::Attributes::QueryValue, required: false
14
16
 
15
17
  def to_hash
16
18
  result = {fuzzy: {field => {value: query}}}
17
- options = {boost: boost, min_similarity: min_similarity, prefix_length: prefix_length}.select {|k,v| !v.nil?}
19
+ options = {boost: boost, min_similarity: min_similarity, prefix_length: prefix_length, max_expansions: max_expansions, fuzziness: fuzziness}.select {|k,v| !v.nil?}
18
20
  result[:fuzzy][field].merge!(options)
19
21
 
20
22
  result
@@ -14,13 +14,16 @@ module Daedal
14
14
  attribute :type, Daedal::Attributes::MatchType, required: false
15
15
  attribute :analyzer, Symbol, required: false
16
16
  attribute :boost, Daedal::Attributes::Boost, required: false
17
- attribute :fuzziness, Float, required: false
17
+ attribute :fuzziness, Daedal::Attributes::QueryValue, required: false
18
18
  attribute :slop, Integer, required: false
19
+ attribute :max_expansions, Integer, required: false
20
+ attribute :prefix_length, Integer, required: false
21
+ attribute :lenient, Boolean, required: false
19
22
 
20
23
  def to_hash
21
24
 
22
25
  result = {match: {field => {query: query}}}
23
- options = {minimum_should_match: minimum_should_match, cutoff_frequency: cutoff_frequency, type: type, analyzer: analyzer, boost: boost, fuzziness: fuzziness, operator: operator, slop: slop}
26
+ options = {minimum_should_match: minimum_should_match, cutoff_frequency: cutoff_frequency, type: type, analyzer: analyzer, boost: boost, fuzziness: fuzziness, operator: operator, slop: slop, max_expansions: max_expansions, prefix_length: prefix_length, lenient: lenient}
24
27
  result[:match][field].merge! options.select {|k,v| !v.nil?}
25
28
 
26
29
  result
@@ -16,7 +16,9 @@ module Daedal
16
16
  attribute :type, Daedal::Attributes::MatchType, required: false
17
17
  attribute :analyzer, Symbol, required: false
18
18
  attribute :boost, Daedal::Attributes::Boost, required: false
19
- attribute :fuzziness, Float, required: false
19
+ attribute :fuzziness, Daedal::Attributes::QueryValue, required: false
20
+ attribute :prefix_length, Integer, required: false
21
+ attribute :max_expansions, Integer, required: false
20
22
 
21
23
  # Fields cannot be an empty array... should eventually refactor this kind of thing out of initialize
22
24
  def initialize(options={})
@@ -29,7 +31,7 @@ module Daedal
29
31
 
30
32
  def to_hash
31
33
  result = {multi_match: {query: query, fields: fields}}
32
- options = {minimum_should_match: minimum_should_match, cutoff_frequency: cutoff_frequency, type: type, analyzer: analyzer, boost: boost, fuzziness: fuzziness, operator: operator}
34
+ options = {minimum_should_match: minimum_should_match, cutoff_frequency: cutoff_frequency, type: type, analyzer: analyzer, boost: boost, fuzziness: fuzziness, operator: operator, prefix_length: prefix_length, max_expansions: max_expansions}
33
35
 
34
36
  result[:multi_match].merge!(options.select { |k,v| !v.nil? })
35
37
 
@@ -1,3 +1,3 @@
1
1
  module Daedal
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -86,4 +86,46 @@ describe Daedal::Queries::FuzzyQuery do
86
86
  expect(query.to_json).to eq hash_query.to_json
87
87
  end
88
88
  end
89
+
90
+ context 'with a fuzziness of 0.5 specified' do
91
+ let(:query) do
92
+ subject.new(query: :bar, field: :foo, fuzziness: 0.5)
93
+ end
94
+
95
+ before do
96
+ hash_query[:fuzzy][:foo][:fuzziness] = 0.5
97
+ end
98
+
99
+ it 'will set the fuzziness' do
100
+ expect(query.fuzziness).to eq 0.5
101
+ end
102
+
103
+ it 'will have the correct hash representation' do
104
+ expect(query.to_hash).to eq hash_query
105
+ end
106
+
107
+ it 'will have the correct json representation' do
108
+ expect(query.to_json).to eq hash_query.to_json
109
+ end
110
+ end
111
+
112
+ context 'with an invalid fuzziness specified' do
113
+ it 'will raise an error' do
114
+ expect {subject.new(query: :bar, field: :foo, fuzziness: {})}.to raise_error(Virtus::CoercionError)
115
+ end
116
+ end
117
+
118
+ context 'with max_expansions specified' do
119
+ context 'when given an int' do
120
+ before { hash_query[:fuzzy][:foo][:max_expansions] = 2 }
121
+ it 'will use the max_expansions' do
122
+ expect(subject.new(query: :bar, field: :foo, max_expansions: 2).to_hash).to eq hash_query
123
+ end
124
+ end
125
+ context 'with invalid input' do
126
+ it 'will raise an error' do
127
+ expect {subject.new(query: :bar, field: :foo, max_expansions: {})}.to raise_error(Virtus::CoercionError)
128
+ end
129
+ end
130
+ end
89
131
  end
@@ -251,7 +251,7 @@ describe Daedal::Queries::MatchQuery do
251
251
  base_query[:match][:foo][:fuzziness] = 0.5
252
252
  end
253
253
 
254
- it 'will set the phrase type to :phrase' do
254
+ it 'will set fuzziness correctly' do
255
255
  expect(match_query.fuzziness).to eq 0.5
256
256
  end
257
257
 
@@ -264,9 +264,60 @@ describe Daedal::Queries::MatchQuery do
264
264
  end
265
265
  end
266
266
 
267
- context 'with a non float or integer fuzziness specified' do
267
+ context 'with an invalid fuzziness specified' do
268
268
  it 'will raise an error' do
269
- expect {subject.new(field: :foo, query: :bar, fuzziness: 'foo')}.to raise_error(Virtus::CoercionError)
269
+ expect {subject.new(field: :foo, query: :bar, fuzziness: {})}.to raise_error(Virtus::CoercionError)
270
+ end
271
+ end
272
+
273
+ context 'with a lenient specified' do
274
+ let(:query) do
275
+ subject.new field: :foo, query: :bar, lenient: true
276
+ end
277
+
278
+ before do
279
+ base_query[:match][:foo][:lenient] = true
280
+ end
281
+ it 'will set the lenient correctly' do
282
+ expect(query.lenient).to eq true
283
+ end
284
+ it 'will have the correct hash and json representations' do
285
+ expect(query.to_hash).to eq base_query
286
+ expect(query.to_json).to eq base_query.to_json
287
+ end
288
+ end
289
+
290
+ context 'with a max_expansions specified' do
291
+ let(:query) do
292
+ subject.new field: :foo, query: :bar, max_expansions: 1
293
+ end
294
+
295
+ before do
296
+ base_query[:match][:foo][:max_expansions] = 1
297
+ end
298
+ it 'will set the max_expansions correctly' do
299
+ expect(query.max_expansions).to eq 1
300
+ end
301
+ it 'will have the correct hash and json representations' do
302
+ expect(query.to_hash).to eq base_query
303
+ expect(query.to_json).to eq base_query.to_json
304
+ end
305
+ end
306
+
307
+ context 'with a prefix_length specified' do
308
+ let(:query) do
309
+ subject.new field: :foo, query: :bar, prefix_length: 1
310
+ end
311
+
312
+ before do
313
+ base_query[:match][:foo][:prefix_length] = 1
314
+ end
315
+ it 'will set the prefix_length correctly' do
316
+ expect(query.prefix_length).to eq 1
317
+ end
318
+ it 'will have the correct hash and json representations' do
319
+ expect(query.to_hash).to eq base_query
320
+ expect(query.to_json).to eq base_query.to_json
270
321
  end
271
322
  end
272
323
  end
@@ -125,7 +125,7 @@ describe Daedal::Queries::MultiMatchQuery do
125
125
  base_query[:multi_match][:minimum_should_match] = 2
126
126
  end
127
127
 
128
- it 'will set the phrase type to :phrase' do
128
+ it 'will set the minimum_should_match' do
129
129
  expect(query.minimum_should_match).to eq 2
130
130
  end
131
131
 
@@ -153,7 +153,7 @@ describe Daedal::Queries::MultiMatchQuery do
153
153
  base_query[:multi_match][:cutoff_frequency] = 0.5
154
154
  end
155
155
 
156
- it 'will set the phrase type to :phrase' do
156
+ it 'will set the cutoff_frequency' do
157
157
  expect(query.cutoff_frequency).to eq 0.5
158
158
  end
159
159
 
@@ -181,7 +181,7 @@ describe Daedal::Queries::MultiMatchQuery do
181
181
  base_query[:multi_match][:analyzer] = :foo
182
182
  end
183
183
 
184
- it 'will set the phrase type to :phrase' do
184
+ it 'will set the analyzer' do
185
185
  expect(query.analyzer).to eq :foo
186
186
  end
187
187
 
@@ -203,7 +203,7 @@ describe Daedal::Queries::MultiMatchQuery do
203
203
  base_query[:multi_match][:boost] = 2.0
204
204
  end
205
205
 
206
- it 'will set the phrase type to :phrase' do
206
+ it 'will set the boost' do
207
207
  expect(query.boost).to eq 2.0
208
208
  end
209
209
 
@@ -231,7 +231,7 @@ describe Daedal::Queries::MultiMatchQuery do
231
231
  base_query[:multi_match][:fuzziness] = 0.5
232
232
  end
233
233
 
234
- it 'will set the phrase type to :phrase' do
234
+ it 'will set the fuzziness' do
235
235
  expect(query.fuzziness).to eq 0.5
236
236
  end
237
237
 
@@ -244,9 +244,38 @@ describe Daedal::Queries::MultiMatchQuery do
244
244
  end
245
245
  end
246
246
 
247
- context 'with a non float or integer fuzziness specified' do
247
+ context 'with an invalid fuzziness specified' do
248
248
  it 'will raise an error' do
249
- expect {subject.new(query: term, fields: fields, fuzziness: 'foo')}.to raise_error(Virtus::CoercionError)
249
+ expect {subject.new(query: term, fields: fields, fuzziness: {})}.to raise_error(Virtus::CoercionError)
250
+ end
251
+ end
252
+
253
+ context 'with prefix_length specified' do
254
+ context 'when given an int' do
255
+ before { base_query[:multi_match][:prefix_length] = 2 }
256
+ it 'will use the prefix_length' do
257
+ expect(subject.new(query: term, fields: fields, prefix_length: 2).to_hash).to eq base_query
258
+ end
259
+ end
260
+ context 'with invalid input' do
261
+ it 'will raise an error' do
262
+ expect {subject.new(query: term, fields: fields, prefix_length: {})}.to raise_error(Virtus::CoercionError)
263
+ end
250
264
  end
251
265
  end
266
+
267
+ context 'with max_expansions specified' do
268
+ context 'when given an int' do
269
+ before { base_query[:multi_match][:max_expansions] = 2 }
270
+ it 'will use the max_expansions' do
271
+ expect(subject.new(query: term, fields: fields, max_expansions: 2).to_hash).to eq base_query
272
+ end
273
+ end
274
+ context 'with invalid input' do
275
+ it 'will raise an error' do
276
+ expect {subject.new(query: term, fields: fields, max_expansions: {})}.to raise_error(Virtus::CoercionError)
277
+ end
278
+ end
279
+ end
280
+
252
281
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daedal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Schuch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-16 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus