daedal 0.0.2
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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +82 -0
- data/Guardfile +4 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/daedal.gemspec +14 -0
- data/lib/daedal.rb +8 -0
- data/lib/daedal/attributes.rb +94 -0
- data/lib/daedal/filters.rb +7 -0
- data/lib/daedal/filters/base_filter.rb +17 -0
- data/lib/daedal/filters/term_filter.rb +18 -0
- data/lib/daedal/queries.rb +13 -0
- data/lib/daedal/queries/base_query.rb +13 -0
- data/lib/daedal/queries/bool_query.rb +48 -0
- data/lib/daedal/queries/constant_score_query.rb +35 -0
- data/lib/daedal/queries/dis_max_query.rb +37 -0
- data/lib/daedal/queries/filtered_query.rb +20 -0
- data/lib/daedal/queries/match_all_query.rb +12 -0
- data/lib/daedal/queries/match_query.rb +33 -0
- data/lib/daedal/queries/multi_match_query.rb +43 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/daedal/filters/term_filter_spec.rb +55 -0
- data/spec/unit/daedal/queries/bool_query_spec.rb +214 -0
- data/spec/unit/daedal/queries/constant_score_query_spec.rb +72 -0
- data/spec/unit/daedal/queries/dis_max_query_spec.rb +151 -0
- data/spec/unit/daedal/queries/filtered_query_spec.rb +60 -0
- data/spec/unit/daedal/queries/match_all_query_spec.rb +19 -0
- data/spec/unit/daedal/queries/match_query_spec.rb +245 -0
- data/spec/unit/daedal/queries/multi_match_query_spec.rb +253 -0
- metadata +74 -0
@@ -0,0 +1,253 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'daedal/queries'
|
3
|
+
|
4
|
+
describe Daedal::Queries::MultiMatchQuery do
|
5
|
+
|
6
|
+
subject do
|
7
|
+
Daedal::Queries::MultiMatchQuery
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:term) do
|
11
|
+
:foo
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:fields) do
|
15
|
+
[:a, :b]
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:base_query) do
|
19
|
+
{multi_match: {query: term, fields: fields}}
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'without a field or term given' do
|
23
|
+
it 'will raise an error' do
|
24
|
+
expect {subject.new}.to raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'without fields given' do
|
29
|
+
it 'will raise an error' do
|
30
|
+
expect {subject.new(query: term)}.to raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with a term and fields given' do
|
35
|
+
|
36
|
+
let(:query) do
|
37
|
+
subject.new(query: term, fields: fields)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'will create a match query object that has the correct field and term' do
|
41
|
+
expect(query.fields).to eq fields
|
42
|
+
expect(query.query).to eq term
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'will have the other options set to nil' do
|
46
|
+
expect(query.minimum_should_match).to eq nil
|
47
|
+
expect(query.cutoff_frequency).to eq nil
|
48
|
+
expect(query.type).to eq nil
|
49
|
+
expect(query.analyzer).to eq nil
|
50
|
+
expect(query.boost).to eq nil
|
51
|
+
expect(query.fuzziness).to eq nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'will have the correct hash representation' do
|
55
|
+
expect(query.to_hash).to eq base_query
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'will have the correct json representation' do
|
59
|
+
expect(query.to_json).to eq base_query.to_json
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with an operator of :and specified" do
|
64
|
+
|
65
|
+
let(:query) do
|
66
|
+
subject.new(query: term, fields: fields, operator: :and)
|
67
|
+
end
|
68
|
+
|
69
|
+
before do
|
70
|
+
base_query[:multi_match][:operator] = :and
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'will set the operator to :and' do
|
74
|
+
expect(query.operator).to eq :and
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'will have the correct hash representation' do
|
78
|
+
expect(query.to_hash).to eq base_query
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'will have the correct json representation' do
|
82
|
+
expect(query.to_json).to eq base_query.to_json
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'with a non-valid operator specified' do
|
87
|
+
it 'will raise an error' do
|
88
|
+
expect {subject.new(query: term, fields: fields, operator: :foo)}.to raise_error
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with a phrase type specified' do
|
93
|
+
let(:query) do
|
94
|
+
subject.new(query: term, fields: fields, type: :phrase)
|
95
|
+
end
|
96
|
+
|
97
|
+
before do
|
98
|
+
base_query[:multi_match][:type] = :phrase
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'will set the phrase type to :phrase' do
|
102
|
+
expect(query.type).to eq :phrase
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'will have the correct hash representation' do
|
106
|
+
expect(query.to_hash).to eq base_query
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'will have the correct json representation' do
|
110
|
+
expect(query.to_json).to eq base_query.to_json
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with a non-valid type specified' do
|
115
|
+
it 'will raise an error' do
|
116
|
+
expect {subject.new(query: term, fields: fields, type: :foo)}.to raise_error
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'with a minimum should match of 2 specified' do
|
121
|
+
let(:query) do
|
122
|
+
subject.new(query: term, fields: fields, minimum_should_match: 2)
|
123
|
+
end
|
124
|
+
|
125
|
+
before do
|
126
|
+
base_query[:multi_match][:minimum_should_match] = 2
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'will set the phrase type to :phrase' do
|
130
|
+
expect(query.minimum_should_match).to eq 2
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'will have the correct hash representation' do
|
134
|
+
expect(query.to_hash).to eq base_query
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'will have the correct json representation' do
|
138
|
+
expect(query.to_json).to eq base_query.to_json
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'with a non-integer minimum should match specified' do
|
143
|
+
it 'will raise an error' do
|
144
|
+
expect {subject.new(query: term, fields: fields, minimum_should_match: 'foo')}.to raise_error
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'with a cutoff frequency of 0.5 specified' do
|
149
|
+
let(:query) do
|
150
|
+
subject.new(query: term, fields: fields, cutoff_frequency: 0.5)
|
151
|
+
end
|
152
|
+
|
153
|
+
before do
|
154
|
+
base_query[:multi_match][:cutoff_frequency] = 0.5
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'will set the phrase type to :phrase' do
|
158
|
+
expect(query.cutoff_frequency).to eq 0.5
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'will have the correct hash representation' do
|
162
|
+
expect(query.to_hash).to eq base_query
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'will have the correct json representation' do
|
166
|
+
expect(query.to_json).to eq base_query.to_json
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'with a non-float cutoff frequency specified' do
|
171
|
+
it 'will raise an error' do
|
172
|
+
expect {subject.new(query: term, fields: fields, cutoff_frequency: 'foo')}.to raise_error
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'with an analyzer of :foo specified' do
|
177
|
+
let(:query) do
|
178
|
+
subject.new(query: term, fields: fields, analyzer: :foo)
|
179
|
+
end
|
180
|
+
|
181
|
+
before do
|
182
|
+
base_query[:multi_match][:analyzer] = :foo
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'will set the phrase type to :phrase' do
|
186
|
+
expect(query.analyzer).to eq :foo
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'will have the correct hash representation' do
|
190
|
+
expect(query.to_hash).to eq base_query
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'will have the correct json representation' do
|
194
|
+
expect(query.to_json).to eq base_query.to_json
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'with a boost of 2 specified' do
|
199
|
+
let(:query) do
|
200
|
+
subject.new(query: term, fields: fields, boost: 2)
|
201
|
+
end
|
202
|
+
|
203
|
+
before do
|
204
|
+
base_query[:multi_match][:boost] = 2
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'will set the phrase type to :phrase' do
|
208
|
+
expect(query.boost).to eq 2
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'will have the correct hash representation' do
|
212
|
+
expect(query.to_hash).to eq base_query
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'will have the correct json representation' do
|
216
|
+
expect(query.to_json).to eq base_query.to_json
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'with a non integer boost specified' do
|
221
|
+
it 'will raise an error' do
|
222
|
+
expect {subject.new(query: term, fields: fields, boost: 'foo')}.to raise_error
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'with a fuzziness of 0.5 specified' do
|
227
|
+
let(:query) do
|
228
|
+
subject.new(query: term, fields: fields, fuzziness: 0.5)
|
229
|
+
end
|
230
|
+
|
231
|
+
before do
|
232
|
+
base_query[:multi_match][:fuzziness] = 0.5
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'will set the phrase type to :phrase' do
|
236
|
+
expect(query.fuzziness).to eq 0.5
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'will have the correct hash representation' do
|
240
|
+
expect(query.to_hash).to eq base_query
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'will have the correct json representation' do
|
244
|
+
expect(query.to_json).to eq base_query.to_json
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context 'with a non float or integer fuzziness specified' do
|
249
|
+
it 'will raise an error' do
|
250
|
+
expect {subject.new(query: term, fields: fields, fuzziness: 'foo')}.to raise_error
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daedal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Schuch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Classes for easier ElasticSearch query creation
|
14
|
+
email: cas13091@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- .gitignore
|
20
|
+
- .rspec
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- Guardfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- daedal.gemspec
|
27
|
+
- lib/daedal.rb
|
28
|
+
- lib/daedal/attributes.rb
|
29
|
+
- lib/daedal/filters.rb
|
30
|
+
- lib/daedal/filters/base_filter.rb
|
31
|
+
- lib/daedal/filters/term_filter.rb
|
32
|
+
- lib/daedal/queries.rb
|
33
|
+
- lib/daedal/queries/base_query.rb
|
34
|
+
- lib/daedal/queries/bool_query.rb
|
35
|
+
- lib/daedal/queries/constant_score_query.rb
|
36
|
+
- lib/daedal/queries/dis_max_query.rb
|
37
|
+
- lib/daedal/queries/filtered_query.rb
|
38
|
+
- lib/daedal/queries/match_all_query.rb
|
39
|
+
- lib/daedal/queries/match_query.rb
|
40
|
+
- lib/daedal/queries/multi_match_query.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
- spec/unit/daedal/filters/term_filter_spec.rb
|
43
|
+
- spec/unit/daedal/queries/bool_query_spec.rb
|
44
|
+
- spec/unit/daedal/queries/constant_score_query_spec.rb
|
45
|
+
- spec/unit/daedal/queries/dis_max_query_spec.rb
|
46
|
+
- spec/unit/daedal/queries/filtered_query_spec.rb
|
47
|
+
- spec/unit/daedal/queries/match_all_query_spec.rb
|
48
|
+
- spec/unit/daedal/queries/match_query_spec.rb
|
49
|
+
- spec/unit/daedal/queries/multi_match_query_spec.rb
|
50
|
+
homepage: https://github.com/cschuch/daedal
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.0.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: ElasticSearch Query DSL Builders
|
74
|
+
test_files: []
|