chewy 7.1.0 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +58 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +53 -0
- data/Gemfile +0 -7
- data/Guardfile +3 -1
- data/README.md +282 -245
- data/chewy.gemspec +3 -5
- data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
- data/lib/chewy.rb +21 -75
- data/lib/chewy/config.rb +40 -40
- data/lib/chewy/errors.rb +0 -12
- data/lib/chewy/fields/base.rb +11 -1
- data/lib/chewy/fields/root.rb +3 -4
- data/lib/chewy/index.rb +46 -87
- data/lib/chewy/index/actions.rb +51 -32
- data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- data/lib/chewy/{type → index}/adapter/object.rb +27 -31
- data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
- data/lib/chewy/{type → index}/crutch.rb +5 -5
- data/lib/chewy/{type → index}/import.rb +36 -27
- data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
- data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
- data/lib/chewy/{type → index}/import/routine.rb +15 -14
- data/lib/chewy/{type → index}/mapping.rb +26 -31
- data/lib/chewy/{type → index}/observe.rb +9 -19
- data/lib/chewy/index/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +60 -57
- data/lib/chewy/{type → index}/witchcraft.rb +11 -7
- data/lib/chewy/{type → index}/wrapper.rb +2 -2
- data/lib/chewy/journal.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +9 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/railtie.rb +4 -2
- data/lib/chewy/rake_helper.rb +82 -107
- data/lib/chewy/rspec/update_index.rb +47 -43
- data/lib/chewy/search.rb +4 -17
- data/lib/chewy/search/loader.rb +18 -30
- data/lib/chewy/search/parameters.rb +4 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +82 -86
- data/lib/chewy/search/response.rb +4 -4
- data/lib/chewy/search/scoping.rb +6 -7
- data/lib/chewy/search/scrolling.rb +11 -11
- data/lib/chewy/stash.rb +14 -22
- data/lib/chewy/strategy.rb +3 -19
- data/lib/chewy/strategy/sidekiq.rb +1 -0
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +10 -22
- data/migration_guide.md +14 -0
- data/spec/chewy/config_spec.rb +14 -39
- data/spec/chewy/fields/base_spec.rb +412 -148
- data/spec/chewy/fields/root_spec.rb +16 -24
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +270 -24
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
- data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
- data/spec/chewy/{type → index}/import_spec.rb +102 -98
- data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
- data/spec/chewy/index/observe_spec.rb +116 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +7 -17
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +59 -102
- data/spec/chewy/journal_spec.rb +9 -22
- data/spec/chewy/minitest/helpers_spec.rb +13 -15
- data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
- data/spec/chewy/multi_search_spec.rb +4 -5
- data/spec/chewy/rake_helper_spec.rb +145 -55
- data/spec/chewy/rspec/update_index_spec.rb +74 -71
- data/spec/chewy/search/loader_spec.rb +19 -37
- data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/indices_spec.rb +2 -8
- data/spec/chewy/search/parameters/order_spec.rb +1 -1
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters_spec.rb +12 -3
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +222 -74
- data/spec/chewy/search/response_spec.rb +12 -12
- data/spec/chewy/search/scrolling_spec.rb +7 -9
- data/spec/chewy/search_spec.rb +32 -35
- data/spec/chewy/stash_spec.rb +9 -21
- data/spec/chewy/strategy/active_job_spec.rb +8 -8
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +14 -100
- data/spec/spec_helper.rb +2 -21
- data/spec/support/active_record.rb +15 -5
- metadata +44 -103
- data/.circleci/config.yml +0 -214
- data/Appraisals +0 -81
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type.rb +0 -120
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -100
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
@@ -5,7 +5,7 @@ describe Chewy::Search::Pagination::Kaminari do
|
|
5
5
|
describe '#objects' do
|
6
6
|
let(:data) { Array.new(12) { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
7
7
|
|
8
|
-
before { ProductsIndex
|
8
|
+
before { ProductsIndex.import!(data.map { |h| double(h) }) }
|
9
9
|
before { allow(::Kaminari.config).to receive_messages(default_per_page: 17) }
|
10
10
|
|
11
11
|
specify { expect(search.objects.class).to eq(Kaminari::PaginatableArray) }
|
@@ -2,14 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Chewy::Search::Parameters::Indices do
|
4
4
|
before do
|
5
|
-
stub_index(:first)
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
stub_index(:second) do
|
10
|
-
define_type :three
|
11
|
-
end
|
12
|
-
|
5
|
+
stub_index(:first)
|
6
|
+
stub_index(:second)
|
13
7
|
stub_index(:third)
|
14
8
|
end
|
15
9
|
|
@@ -10,7 +10,7 @@ describe Chewy::Search::Parameters::Order do
|
|
10
10
|
specify { expect(described_class.new(42).value).to eq('42' => nil) }
|
11
11
|
specify { expect(described_class.new([42, 43]).value).to eq('42' => nil, '43' => nil) }
|
12
12
|
specify { expect(described_class.new(a: 1).value).to eq('a' => 1) }
|
13
|
-
specify { expect(described_class.new(['', 43, a: 1]).value).to eq('a' => 1, '43' => nil) }
|
13
|
+
specify { expect(described_class.new(['', 43, {a: 1}]).value).to eq('a' => 1, '43' => nil) }
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#replace!' do
|
@@ -4,19 +4,46 @@ shared_examples :query_storage do |param_name|
|
|
4
4
|
subject { described_class.new(must: {foo: 'bar'}, should: {moo: 'baz'}) }
|
5
5
|
|
6
6
|
describe '#initialize' do
|
7
|
-
specify
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
specify do
|
8
|
+
expect(described_class.new.value.to_h)
|
9
|
+
.to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
|
10
|
+
end
|
11
|
+
specify do
|
12
|
+
expect(described_class.new(nil).value.to_h)
|
13
|
+
.to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
|
14
|
+
end
|
15
|
+
specify do
|
16
|
+
expect(described_class.new(foobar: {}).value.to_h)
|
17
|
+
.to eq(must: [{foobar: {}}], should: [], must_not: [], minimum_should_match: nil)
|
18
|
+
end
|
19
|
+
specify do
|
20
|
+
expect(described_class.new(must: {}, should: {}, must_not: {}).value.to_h)
|
21
|
+
.to eq(must: [], should: [], must_not: [], minimum_should_match: nil)
|
22
|
+
end
|
11
23
|
specify do
|
12
24
|
expect(described_class.new(must: {foo: 'bar'}, should: {foo: 'bar'}, foobar: {}).value.to_h)
|
13
25
|
.to eq(must: [{foo: 'bar'}], should: [{foo: 'bar'}], must_not: [], minimum_should_match: nil)
|
14
26
|
end
|
15
|
-
specify
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
specify
|
27
|
+
specify do
|
28
|
+
expect(subject.value.to_h)
|
29
|
+
.to eq(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
30
|
+
end
|
31
|
+
specify do
|
32
|
+
expect(described_class.new(proc { match foo: 'bar' }).value.to_h)
|
33
|
+
.to eq(must: [match: {foo: 'bar'}], should: [], must_not: [], minimum_should_match: nil)
|
34
|
+
end
|
35
|
+
specify do
|
36
|
+
expect(described_class.new(must: proc { match foo: 'bar' }).value.to_h)
|
37
|
+
.to eq(must: [match: {foo: 'bar'}], should: [], must_not: [], minimum_should_match: nil)
|
38
|
+
end
|
39
|
+
specify do
|
40
|
+
expect(described_class.new(minimum_should_match: 3).value.to_h)
|
41
|
+
.to eq(must: [], should: [], must_not: [], minimum_should_match: 3)
|
42
|
+
end
|
43
|
+
specify do
|
44
|
+
expect(described_class.new(must: {foo: 'bar'}, minimum_should_match: 3).value.to_h)
|
45
|
+
.to eq(must: [{foo: 'bar'}], should: [], must_not: [], minimum_should_match: 3)
|
46
|
+
end
|
20
47
|
specify do
|
21
48
|
expect(described_class.new(must: [proc { match foo: 'bar' }, {moo: 'baz'}]).value.to_h)
|
22
49
|
.to eq(must: [{match: {foo: 'bar'}}, {moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
|
@@ -73,14 +100,16 @@ shared_examples :query_storage do |param_name|
|
|
73
100
|
expect { subject.and(moo: 'baz') }
|
74
101
|
.to change { subject.value.to_h }
|
75
102
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
76
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
103
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
104
|
+
{moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
|
77
105
|
end
|
78
106
|
|
79
107
|
specify do
|
80
108
|
expect { subject.and([{moo: 'baz'}, {doo: 'scooby'}]) }
|
81
109
|
.to change { subject.value.to_h }
|
82
110
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
83
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
111
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
112
|
+
bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}], should: [], must_not: [], minimum_should_match: nil)
|
84
113
|
end
|
85
114
|
|
86
115
|
specify do
|
@@ -93,7 +122,8 @@ shared_examples :query_storage do |param_name|
|
|
93
122
|
expect { subject.and(should: {foo: 'bar'}) }
|
94
123
|
.to change { subject.value.to_h }
|
95
124
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
96
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
125
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
126
|
+
{bool: {should: {foo: 'bar'}}}], should: [], must_not: [], minimum_should_match: nil)
|
97
127
|
end
|
98
128
|
|
99
129
|
context do
|
@@ -113,14 +143,16 @@ shared_examples :query_storage do |param_name|
|
|
113
143
|
expect { subject.or(moo: 'baz') }
|
114
144
|
.to change { subject.value.to_h }
|
115
145
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
116
|
-
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
146
|
+
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
147
|
+
{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
117
148
|
end
|
118
149
|
|
119
150
|
specify do
|
120
151
|
expect { subject.or([{moo: 'baz'}, {doo: 'scooby'}]) }
|
121
152
|
.to change { subject.value.to_h }
|
122
153
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
123
|
-
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
154
|
+
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
155
|
+
bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}], must_not: [], minimum_should_match: nil)
|
124
156
|
end
|
125
157
|
|
126
158
|
specify do
|
@@ -133,7 +165,8 @@ shared_examples :query_storage do |param_name|
|
|
133
165
|
expect { subject.or(should: {foo: 'bar'}) }
|
134
166
|
.to change { subject.value.to_h }
|
135
167
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
136
|
-
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
168
|
+
.to(must: [], should: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
169
|
+
{bool: {should: {foo: 'bar'}}}], must_not: [], minimum_should_match: nil)
|
137
170
|
end
|
138
171
|
|
139
172
|
context do
|
@@ -160,7 +193,12 @@ shared_examples :query_storage do |param_name|
|
|
160
193
|
expect { subject.not([{moo: 'baz'}, {doo: 'scooby'}]) }
|
161
194
|
.to change { subject.value.to_h }
|
162
195
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
163
|
-
.to(
|
196
|
+
.to(
|
197
|
+
must: [{foo: 'bar'}],
|
198
|
+
should: [{moo: 'baz'}],
|
199
|
+
must_not: [{bool: {must: [{moo: 'baz'}, {doo: 'scooby'}]}}],
|
200
|
+
minimum_should_match: nil
|
201
|
+
)
|
164
202
|
end
|
165
203
|
|
166
204
|
specify do
|
@@ -173,7 +211,11 @@ shared_examples :query_storage do |param_name|
|
|
173
211
|
expect { subject.not(should: {foo: 'bar'}) }
|
174
212
|
.to change { subject.value.to_h }
|
175
213
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
176
|
-
.to(
|
214
|
+
.to(
|
215
|
+
must: [{foo: 'bar'}], should: [{moo: 'baz'}],
|
216
|
+
must_not: [{bool: {should: {foo: 'bar'}}}],
|
217
|
+
minimum_should_match: nil
|
218
|
+
)
|
177
219
|
end
|
178
220
|
|
179
221
|
context do
|
@@ -223,7 +265,8 @@ shared_examples :query_storage do |param_name|
|
|
223
265
|
expect { subject.update!(must: proc { match foo: 'bar' }) }
|
224
266
|
.to change { subject.value.to_h }
|
225
267
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
226
|
-
.to(must: [{foo: 'bar'},
|
268
|
+
.to(must: [{foo: 'bar'},
|
269
|
+
{match: {foo: 'bar'}}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
227
270
|
end
|
228
271
|
|
229
272
|
specify do
|
@@ -237,7 +280,8 @@ shared_examples :query_storage do |param_name|
|
|
237
280
|
expect { subject.update!(foobar: {foo: 'bar'}) }
|
238
281
|
.to change { subject.value.to_h }
|
239
282
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
240
|
-
.to(must: [{foo: 'bar'},
|
283
|
+
.to(must: [{foo: 'bar'},
|
284
|
+
{foobar: {foo: 'bar'}}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
241
285
|
end
|
242
286
|
|
243
287
|
specify do
|
@@ -279,7 +323,8 @@ shared_examples :query_storage do |param_name|
|
|
279
323
|
expect { subject.merge!(described_class.new(moo: 'baz')) }
|
280
324
|
.to change { subject.value.to_h }
|
281
325
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
282
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
326
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
327
|
+
{moo: 'baz'}], should: [], must_not: [], minimum_should_match: nil)
|
283
328
|
end
|
284
329
|
|
285
330
|
specify do
|
@@ -292,7 +337,8 @@ shared_examples :query_storage do |param_name|
|
|
292
337
|
expect { subject.merge!(described_class.new(should: {foo: 'bar'})) }
|
293
338
|
.to change { subject.value.to_h }
|
294
339
|
.from(must: [{foo: 'bar'}], should: [{moo: 'baz'}], must_not: [], minimum_should_match: nil)
|
295
|
-
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
340
|
+
.to(must: [{bool: {must: {foo: 'bar'}, should: {moo: 'baz'}}},
|
341
|
+
{bool: {should: {foo: 'bar'}}}], should: [], must_not: [], minimum_should_match: nil)
|
296
342
|
end
|
297
343
|
|
298
344
|
context do
|
@@ -20,7 +20,10 @@ describe Chewy::Search::Parameters::SearchAfter do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#merge!' do
|
23
|
-
specify
|
23
|
+
specify do
|
24
|
+
expect { subject.merge!(described_class.new(:baz)) }
|
25
|
+
.to change { subject.value }.from([:foo, 42]).to([:baz])
|
26
|
+
end
|
24
27
|
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from([:foo, 42]) }
|
25
28
|
end
|
26
29
|
|
@@ -12,8 +12,14 @@ describe Chewy::Search::Parameters::Source do
|
|
12
12
|
specify { expect(described_class.new(true).value).to eq(includes: [], excludes: [], enabled: true) }
|
13
13
|
specify { expect(described_class.new(a: 1).value).to eq(includes: [], excludes: [], enabled: true) }
|
14
14
|
specify { expect(described_class.new(includes: :foo).value).to eq(includes: %w[foo], excludes: [], enabled: true) }
|
15
|
-
specify
|
16
|
-
|
15
|
+
specify do
|
16
|
+
expect(described_class.new(includes: :foo, excludes: 42).value)
|
17
|
+
.to eq(includes: %w[foo], excludes: %w[42], enabled: true)
|
18
|
+
end
|
19
|
+
specify do
|
20
|
+
expect(described_class.new(includes: :foo, excludes: 42, enabled: false).value)
|
21
|
+
.to eq(includes: %w[foo], excludes: %w[42], enabled: true)
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
describe '#replace!' do
|
@@ -55,7 +55,10 @@ describe Chewy::Search::Parameters do
|
|
55
55
|
subject { described_class.new(limit: 10, offset: 20, order: :foo) }
|
56
56
|
|
57
57
|
specify { expect { subject.only!([:limit]) }.to change { subject.clone }.to(described_class.new(limit: 10)) }
|
58
|
-
specify
|
58
|
+
specify do
|
59
|
+
expect { subject.only!(%i[offset order]) }
|
60
|
+
.to change { subject.clone }.to(described_class.new(offset: 20, order: :foo))
|
61
|
+
end
|
59
62
|
specify { expect { subject.only!(%i[limit something]) }.to raise_error NameError }
|
60
63
|
specify { expect { subject.only!([]) }.to raise_error ArgumentError }
|
61
64
|
end
|
@@ -63,8 +66,14 @@ describe Chewy::Search::Parameters do
|
|
63
66
|
describe '#except!' do
|
64
67
|
subject { described_class.new(limit: 10, offset: 20, order: :foo) }
|
65
68
|
|
66
|
-
specify
|
67
|
-
|
69
|
+
specify do
|
70
|
+
expect { subject.except!([:limit]) }
|
71
|
+
.to change { subject.clone }.to(described_class.new(offset: 20, order: :foo))
|
72
|
+
end
|
73
|
+
specify do
|
74
|
+
expect { subject.except!(%i[offset order]) }
|
75
|
+
.to change { subject.clone }.to(described_class.new(limit: 10))
|
76
|
+
end
|
68
77
|
specify { expect { subject.except!(%i[limit something]) }.to raise_error NameError }
|
69
78
|
specify { expect { subject.except!([]) }.to raise_error ArgumentError }
|
70
79
|
end
|
@@ -8,41 +8,86 @@ describe Chewy::Search::QueryProxy do
|
|
8
8
|
|
9
9
|
describe '#must' do
|
10
10
|
specify { expect { subject.must }.to raise_error ArgumentError }
|
11
|
-
specify
|
12
|
-
|
11
|
+
specify do
|
12
|
+
expect(subject.must(multi_match: {foo: 'bar'}).render[:body])
|
13
|
+
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
|
14
|
+
end
|
15
|
+
specify do
|
16
|
+
expect(subject.must(multi_match: {foo: 'bar'}).render[:body])
|
17
|
+
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
describe '#should' do
|
16
22
|
specify { expect { subject.should }.to raise_error ArgumentError }
|
17
|
-
specify
|
18
|
-
|
23
|
+
specify do
|
24
|
+
expect(subject.should(multi_match: {foo: 'bar'}).render[:body])
|
25
|
+
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, should: {multi_match: {foo: 'bar'}}}})
|
26
|
+
end
|
27
|
+
specify do
|
28
|
+
expect(subject.should(multi_match: {foo: 'bar'}).render[:body])
|
29
|
+
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, should: {multi_match: {foo: 'bar'}}}})
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
33
|
describe '#must_not' do
|
22
34
|
specify { expect { subject.must_not }.to raise_error ArgumentError }
|
23
|
-
specify
|
24
|
-
|
35
|
+
specify do
|
36
|
+
expect(subject.must_not(multi_match: {foo: 'bar'}).render[:body])
|
37
|
+
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
|
38
|
+
end
|
39
|
+
specify do
|
40
|
+
expect(subject.must_not(multi_match: {foo: 'bar'}).render[:body])
|
41
|
+
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
|
42
|
+
end
|
25
43
|
end
|
26
44
|
|
27
45
|
describe '#and' do
|
28
46
|
specify { expect { subject.and }.to raise_error ArgumentError }
|
29
|
-
specify
|
30
|
-
|
31
|
-
|
47
|
+
specify do
|
48
|
+
expect(subject.and(multi_match: {foo: 'bar'}).render[:body])
|
49
|
+
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
|
50
|
+
end
|
51
|
+
specify do
|
52
|
+
expect(subject.and(multi_match: {foo: 'bar'}).render[:body])
|
53
|
+
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
|
54
|
+
end
|
55
|
+
specify do
|
56
|
+
expect(subject.and(scope).render[:body])
|
57
|
+
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {bool: {must_not: {match: {foo: 'bar'}}}}]}})
|
58
|
+
end
|
32
59
|
end
|
33
60
|
|
34
61
|
describe '#or' do
|
35
62
|
specify { expect { subject.or }.to raise_error ArgumentError }
|
36
|
-
specify
|
37
|
-
|
38
|
-
|
63
|
+
specify do
|
64
|
+
expect(subject.or(multi_match: {foo: 'bar'}).render[:body])
|
65
|
+
.to eq(query: {bool: {should: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
|
66
|
+
end
|
67
|
+
specify do
|
68
|
+
expect(subject.or(multi_match: {foo: 'bar'}).render[:body])
|
69
|
+
.to eq(query: {bool: {should: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
|
70
|
+
end
|
71
|
+
specify do
|
72
|
+
expect(subject.or(scope).render[:body])
|
73
|
+
.to eq(query: {bool: {should: [{match: {foo: 'bar'}}, {bool: {must_not: {match: {foo: 'bar'}}}}]}})
|
74
|
+
end
|
39
75
|
end
|
40
76
|
|
41
77
|
describe '#not' do
|
42
78
|
specify { expect { subject.not }.to raise_error ArgumentError }
|
43
|
-
specify
|
44
|
-
|
45
|
-
|
79
|
+
specify do
|
80
|
+
expect(subject.not(multi_match: {foo: 'bar'}).render[:body])
|
81
|
+
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
|
82
|
+
end
|
83
|
+
specify do
|
84
|
+
expect(subject.not(multi_match: {foo: 'bar'}).render[:body])
|
85
|
+
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
|
86
|
+
end
|
87
|
+
specify do
|
88
|
+
expect(subject.not(scope).render[:body])
|
89
|
+
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {bool: {must_not: {match: {foo: 'bar'}}}}}})
|
90
|
+
end
|
46
91
|
end
|
47
92
|
|
48
93
|
describe '#minimum_should_match' do
|
@@ -53,7 +98,10 @@ describe Chewy::Search::QueryProxy do
|
|
53
98
|
Chewy::Search::Request.new(ProductsIndex)
|
54
99
|
.query.should(match: {foo: 'bar'})
|
55
100
|
end
|
56
|
-
specify
|
101
|
+
specify do
|
102
|
+
expect(subject.minimum_should_match('100%').render[:body])
|
103
|
+
.to eq(query: {bool: {should: {match: {foo: 'bar'}}, minimum_should_match: '100%'}})
|
104
|
+
end
|
57
105
|
end
|
58
106
|
|
59
107
|
context do
|
@@ -62,7 +110,10 @@ describe Chewy::Search::QueryProxy do
|
|
62
110
|
.query.should(match: {foo: 'bar'})
|
63
111
|
.query.minimum_should_match(2)
|
64
112
|
end
|
65
|
-
specify
|
113
|
+
specify do
|
114
|
+
expect(subject.minimum_should_match(nil).render[:body])
|
115
|
+
.to eq(query: {bool: {should: {match: {foo: 'bar'}}}})
|
116
|
+
end
|
66
117
|
end
|
67
118
|
end
|
68
119
|
end
|
@@ -5,23 +5,17 @@ describe Chewy::Search::Request do
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
stub_index(:products) do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
field :age, type: :integer
|
12
|
-
end
|
8
|
+
field :id, type: :integer
|
9
|
+
field :name
|
10
|
+
field :age, type: :integer
|
13
11
|
end
|
14
12
|
|
15
13
|
stub_index(:cities) do
|
16
|
-
|
17
|
-
field :id, type: :integer
|
18
|
-
end
|
14
|
+
field :id, type: :integer
|
19
15
|
end
|
20
16
|
|
21
17
|
stub_index(:countries) do
|
22
|
-
|
23
|
-
field :id, type: :integer
|
24
|
-
end
|
18
|
+
field :id, type: :integer
|
25
19
|
end
|
26
20
|
end
|
27
21
|
|
@@ -31,11 +25,17 @@ describe Chewy::Search::Request do
|
|
31
25
|
specify { expect(described_class.new(ProductsIndex)).to eq(described_class.new(ProductsIndex)) }
|
32
26
|
specify { expect(described_class.new(ProductsIndex)).not_to eq(described_class.new(CitiesIndex)) }
|
33
27
|
specify { expect(described_class.new(ProductsIndex)).not_to eq(described_class.new(ProductsIndex, CitiesIndex)) }
|
34
|
-
specify
|
35
|
-
|
28
|
+
specify do
|
29
|
+
expect(described_class.new(CitiesIndex, ProductsIndex)).to eq(described_class.new(ProductsIndex, CitiesIndex))
|
30
|
+
end
|
31
|
+
specify do
|
32
|
+
expect(described_class.new(ProductsIndex, CitiesIndex)).to eq(described_class.new(CitiesIndex, ProductsIndex))
|
33
|
+
end
|
36
34
|
|
37
35
|
specify { expect(described_class.new(ProductsIndex).limit(10)).to eq(described_class.new(ProductsIndex).limit(10)) }
|
38
|
-
specify
|
36
|
+
specify do
|
37
|
+
expect(described_class.new(ProductsIndex).limit(10)).not_to eq(described_class.new(ProductsIndex).limit(20))
|
38
|
+
end
|
39
39
|
|
40
40
|
specify { expect(ProductsIndex.limit(10)).to eq(ProductsIndex.limit(10)) }
|
41
41
|
specify { expect(ProductsIndex.limit(10)).not_to eq(CitiesIndex.limit(10)) }
|
@@ -64,50 +64,103 @@ describe Chewy::Search::Request do
|
|
64
64
|
|
65
65
|
%i[query post_filter].each do |name|
|
66
66
|
describe "##{name}" do
|
67
|
-
specify
|
67
|
+
specify do
|
68
|
+
expect(subject.send(name, match: {foo: 'bar'}).render[:body])
|
69
|
+
.to include(name => {match: {foo: 'bar'}})
|
70
|
+
end
|
68
71
|
specify { expect(subject.send(name, nil)).to be_a described_class }
|
69
|
-
specify
|
72
|
+
specify do
|
73
|
+
expect(subject.send(name) { match foo: 'bar' }.render[:body])
|
74
|
+
.to include(name => {match: {foo: 'bar'}})
|
75
|
+
end
|
70
76
|
specify do
|
71
77
|
expect(subject.send(name, match: {foo: 'bar'}).send(name) { multi_match foo: 'bar' }.render[:body])
|
72
78
|
.to include(name => {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
|
73
79
|
end
|
74
80
|
specify { expect { subject.send(name, match: {foo: 'bar'}) }.not_to change { subject.render } }
|
75
81
|
specify do
|
76
|
-
expect(
|
77
|
-
.
|
82
|
+
expect(
|
83
|
+
subject.send(name).should(match: {foo: 'bar'}).send(name).must_not { multi_match foo: 'bar' }.render[:body]
|
84
|
+
).to include(name => {bool: {should: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
|
78
85
|
end
|
79
86
|
|
80
87
|
context do
|
81
88
|
let(:other_scope) { subject.send(name).should { multi_match foo: 'bar' }.send(name) { match foo: 'bar' } }
|
82
89
|
|
83
90
|
specify do
|
84
|
-
expect(
|
85
|
-
.
|
91
|
+
expect(
|
92
|
+
subject.send(name).not(other_scope).render[:body]
|
93
|
+
).to include(
|
94
|
+
name => {
|
95
|
+
bool: {
|
96
|
+
must_not: {
|
97
|
+
bool: {
|
98
|
+
must: {match: {foo: 'bar'}},
|
99
|
+
should: {multi_match: {foo: 'bar'}}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
)
|
86
105
|
end
|
87
106
|
end
|
88
107
|
end
|
89
108
|
end
|
90
109
|
|
91
110
|
describe '#filter' do
|
92
|
-
specify
|
111
|
+
specify do
|
112
|
+
expect(subject.filter(match: {foo: 'bar'}).render[:body])
|
113
|
+
.to include(query: {bool: {filter: {match: {foo: 'bar'}}}})
|
114
|
+
end
|
93
115
|
specify { expect(subject.filter(nil)).to be_a described_class }
|
94
|
-
specify
|
116
|
+
specify do
|
117
|
+
expect(subject.filter(match: {foo: 'bar'}).render[:body])
|
118
|
+
.to include(query: {bool: {filter: {match: {foo: 'bar'}}}})
|
119
|
+
end
|
95
120
|
specify do
|
96
121
|
expect(subject.filter(match: {foo: 'bar'}).filter { multi_match foo: 'bar' }.render[:body])
|
97
122
|
.to include(query: {bool: {filter: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
|
98
123
|
end
|
99
124
|
specify { expect { subject.filter(match: {foo: 'bar'}) }.not_to change { subject.render } }
|
100
125
|
specify do
|
101
|
-
expect(
|
102
|
-
.
|
126
|
+
expect(
|
127
|
+
subject.filter.should(match: {foo: 'bar'}).filter.must_not { multi_match foo: 'bar' }.render[:body]
|
128
|
+
).to include(
|
129
|
+
query: {
|
130
|
+
bool: {
|
131
|
+
filter: {
|
132
|
+
bool: {
|
133
|
+
should: {match: {foo: 'bar'}},
|
134
|
+
must_not: {multi_match: {foo: 'bar'}}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
)
|
103
140
|
end
|
104
141
|
|
105
142
|
context do
|
106
143
|
let(:other_scope) { subject.filter.should { multi_match foo: 'bar' }.filter { match foo: 'bar' } }
|
107
144
|
|
108
145
|
specify do
|
109
|
-
expect(
|
110
|
-
.
|
146
|
+
expect(
|
147
|
+
subject.filter.not(other_scope).render[:body]
|
148
|
+
).to include(
|
149
|
+
query: {
|
150
|
+
bool: {
|
151
|
+
filter: {
|
152
|
+
bool: {
|
153
|
+
must_not: {
|
154
|
+
bool: {
|
155
|
+
must: {match: {foo: 'bar'}},
|
156
|
+
should: {multi_match: {foo: 'bar'}}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
)
|
111
164
|
end
|
112
165
|
end
|
113
166
|
end
|
@@ -175,23 +228,53 @@ describe Chewy::Search::Request do
|
|
175
228
|
specify { expect(subject.source(:foo, :bar).source(nil).render[:body]).to include(_source: %w[foo bar]) }
|
176
229
|
specify { expect(subject.source(%i[foo bar]).source(nil).render[:body]).to include(_source: %w[foo bar]) }
|
177
230
|
specify { expect(subject.source(excludes: :foo).render[:body]).to include(_source: {excludes: %w[foo]}) }
|
178
|
-
specify
|
179
|
-
|
180
|
-
|
231
|
+
specify do
|
232
|
+
expect(subject.source(excludes: :foo).source(excludes: %i[foo bar]).render[:body])
|
233
|
+
.to include(_source: {excludes: %w[foo bar]})
|
234
|
+
end
|
235
|
+
specify do
|
236
|
+
expect(subject.source(excludes: :foo).source(excludes: %i[foo bar]).render[:body])
|
237
|
+
.to include(_source: {excludes: %w[foo bar]})
|
238
|
+
end
|
239
|
+
specify do
|
240
|
+
expect(subject.source(excludes: :foo).source(:bar).render[:body])
|
241
|
+
.to include(_source: {includes: %w[bar], excludes: %w[foo]})
|
242
|
+
end
|
181
243
|
specify { expect(subject.source(excludes: :foo).source(false).render[:body]).to include(_source: false) }
|
182
|
-
specify
|
183
|
-
|
244
|
+
specify do
|
245
|
+
expect(subject.source(excludes: :foo).source(false).source(excludes: :bar).render[:body])
|
246
|
+
.to include(_source: {excludes: %w[foo bar]})
|
247
|
+
end
|
248
|
+
specify do
|
249
|
+
expect(subject.source(excludes: :foo).source(false).source(true).render[:body])
|
250
|
+
.to include(_source: {excludes: %w[foo]})
|
251
|
+
end
|
184
252
|
specify { expect(subject.source(nil).render[:body]).to be_blank }
|
185
253
|
specify { expect { subject.source(:foo) }.not_to change { subject.render } }
|
186
254
|
end
|
187
255
|
|
188
256
|
describe '#stored_fields' do
|
189
257
|
specify { expect(subject.stored_fields(:foo).render[:body]).to include(stored_fields: ['foo']) }
|
190
|
-
specify
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
specify
|
258
|
+
specify do
|
259
|
+
expect(subject.stored_fields(%i[foo bar]).stored_fields(nil).render[:body])
|
260
|
+
.to include(stored_fields: %w[foo bar])
|
261
|
+
end
|
262
|
+
specify do
|
263
|
+
expect(subject.stored_fields(:foo).stored_fields(:foo, :bar).render[:body])
|
264
|
+
.to include(stored_fields: %w[foo bar])
|
265
|
+
end
|
266
|
+
specify do
|
267
|
+
expect(subject.stored_fields(:foo).stored_fields(false).render[:body])
|
268
|
+
.to include(stored_fields: '_none_')
|
269
|
+
end
|
270
|
+
specify do
|
271
|
+
expect(subject.stored_fields(:foo).stored_fields(false).stored_fields(:bar).render[:body])
|
272
|
+
.to include(stored_fields: %w[foo bar])
|
273
|
+
end
|
274
|
+
specify do
|
275
|
+
expect(subject.stored_fields(:foo).stored_fields(false).stored_fields(true).render[:body])
|
276
|
+
.to include(stored_fields: %w[foo])
|
277
|
+
end
|
195
278
|
specify { expect(subject.stored_fields(nil).render[:body]).to be_blank }
|
196
279
|
specify { expect { subject.stored_fields(:foo) }.not_to change { subject.render } }
|
197
280
|
end
|
@@ -199,8 +282,14 @@ describe Chewy::Search::Request do
|
|
199
282
|
%i[script_fields highlight].each do |name|
|
200
283
|
describe "##{name}" do
|
201
284
|
specify { expect(subject.send(name, foo: {bar: 42}).render[:body]).to include(name => {'foo' => {bar: 42}}) }
|
202
|
-
specify
|
203
|
-
|
285
|
+
specify do
|
286
|
+
expect(subject.send(name, foo: {bar: 42}).send(name, moo: {baz: 43}).render[:body])
|
287
|
+
.to include(name => {'foo' => {bar: 42}, 'moo' => {baz: 43}})
|
288
|
+
end
|
289
|
+
specify do
|
290
|
+
expect(subject.send(name, foo: {bar: 42}).send(name, nil).render[:body])
|
291
|
+
.to include(name => {'foo' => {bar: 42}})
|
292
|
+
end
|
204
293
|
specify { expect { subject.send(name, foo: {bar: 42}) }.not_to change { subject.render } }
|
205
294
|
end
|
206
295
|
end
|
@@ -208,16 +297,28 @@ describe Chewy::Search::Request do
|
|
208
297
|
%i[suggest aggs].each do |name|
|
209
298
|
describe "##{name}" do
|
210
299
|
specify { expect(subject.send(name, foo: {bar: 42}).render[:body]).to include(name => {'foo' => {bar: 42}}) }
|
211
|
-
specify
|
212
|
-
|
300
|
+
specify do
|
301
|
+
expect(subject.send(name, foo: {bar: 42}).send(name, moo: {baz: 43}).render[:body])
|
302
|
+
.to include(name => {'foo' => {bar: 42}, 'moo' => {baz: 43}})
|
303
|
+
end
|
304
|
+
specify do
|
305
|
+
expect(subject.send(name, foo: {bar: 42}).send(name, nil).render[:body])
|
306
|
+
.to include(name => {'foo' => {bar: 42}})
|
307
|
+
end
|
213
308
|
specify { expect { subject.send(name, foo: {bar: 42}) }.not_to change { subject.render } }
|
214
309
|
end
|
215
310
|
end
|
216
311
|
|
217
312
|
describe '#docvalue_fields' do
|
218
313
|
specify { expect(subject.docvalue_fields(:foo).render[:body]).to include(docvalue_fields: ['foo']) }
|
219
|
-
specify
|
220
|
-
|
314
|
+
specify do
|
315
|
+
expect(subject.docvalue_fields(%i[foo bar]).docvalue_fields(nil).render[:body])
|
316
|
+
.to include(docvalue_fields: %w[foo bar])
|
317
|
+
end
|
318
|
+
specify do
|
319
|
+
expect(subject.docvalue_fields(:foo).docvalue_fields(:foo, :bar).render[:body])
|
320
|
+
.to include(docvalue_fields: %w[foo bar])
|
321
|
+
end
|
221
322
|
specify { expect(subject.docvalue_fields(nil).render[:body]).to be_blank }
|
222
323
|
specify { expect { subject.docvalue_fields(:foo) }.not_to change { subject.render } }
|
223
324
|
end
|
@@ -232,14 +333,23 @@ describe Chewy::Search::Request do
|
|
232
333
|
|
233
334
|
describe '#indices_boost' do
|
234
335
|
specify { expect(subject.indices_boost(foo: 1.2).render[:body]).to include(indices_boost: [{'foo' => 1.2}]) }
|
235
|
-
specify
|
236
|
-
|
336
|
+
specify do
|
337
|
+
expect(subject.indices_boost(foo: 1.2).indices_boost(moo: 1.3).render[:body])
|
338
|
+
.to include(indices_boost: [{'foo' => 1.2}, {'moo' => 1.3}])
|
339
|
+
end
|
340
|
+
specify do
|
341
|
+
expect(subject.indices_boost(foo: 1.2).indices_boost(nil).render[:body])
|
342
|
+
.to include(indices_boost: [{'foo' => 1.2}])
|
343
|
+
end
|
237
344
|
specify { expect { subject.indices_boost(foo: 1.2) }.not_to change { subject.render } }
|
238
345
|
end
|
239
346
|
|
240
347
|
describe '#rescore' do
|
241
348
|
specify { expect(subject.rescore(foo: 42).render[:body]).to include(rescore: [{foo: 42}]) }
|
242
|
-
specify
|
349
|
+
specify do
|
350
|
+
expect(subject.rescore(foo: 42).rescore(moo: 43).render[:body])
|
351
|
+
.to include(rescore: [{foo: 42}, {moo: 43}])
|
352
|
+
end
|
243
353
|
specify { expect(subject.rescore(foo: 42).rescore(nil).render[:body]).to include(rescore: [{foo: 42}]) }
|
244
354
|
specify { expect { subject.rescore(foo: 42) }.not_to change { subject.render } }
|
245
355
|
end
|
@@ -253,7 +363,10 @@ describe Chewy::Search::Request do
|
|
253
363
|
|
254
364
|
describe '#search_after' do
|
255
365
|
specify { expect(subject.search_after(:foo, :bar).render[:body]).to include(search_after: %i[foo bar]) }
|
256
|
-
specify
|
366
|
+
specify do
|
367
|
+
expect(subject.search_after(%i[foo bar]).search_after(:baz).render[:body])
|
368
|
+
.to include(search_after: [:baz])
|
369
|
+
end
|
257
370
|
specify { expect(subject.search_after(:foo).search_after(nil).render[:body]).to be_blank }
|
258
371
|
specify { expect { subject.search_after(:foo) }.not_to change { subject.render } }
|
259
372
|
end
|
@@ -264,15 +377,13 @@ describe Chewy::Search::Request do
|
|
264
377
|
stub_model(:country)
|
265
378
|
|
266
379
|
stub_index(:places) do
|
267
|
-
|
268
|
-
|
269
|
-
end
|
380
|
+
index_scope City
|
381
|
+
field :rating, type: 'integer'
|
270
382
|
end
|
271
383
|
|
272
384
|
stub_index(:countries) do
|
273
|
-
|
274
|
-
|
275
|
-
end
|
385
|
+
index_scope Country
|
386
|
+
field :rating, type: 'integer'
|
276
387
|
end
|
277
388
|
end
|
278
389
|
|
@@ -290,7 +401,7 @@ describe Chewy::Search::Request do
|
|
290
401
|
|
291
402
|
describe '#load' do
|
292
403
|
specify { expect(subject.load(only: 'city')).to eq([*cities]) }
|
293
|
-
specify { expect(subject.load(only: 'city').map(&:class).uniq).to eq([PlacesIndex
|
404
|
+
specify { expect(subject.load(only: 'city').map(&:class).uniq).to eq([PlacesIndex]) }
|
294
405
|
specify { expect(subject.load(only: 'city').objects).to eq([*cities]) }
|
295
406
|
end
|
296
407
|
end
|
@@ -310,7 +421,9 @@ describe Chewy::Search::Request do
|
|
310
421
|
|
311
422
|
context do
|
312
423
|
let(:first_scope) { subject.query(foo: 'bar').filter.should(moo: 'baz').post_filter.must_not(boo: 'baf').limit(10) }
|
313
|
-
let(:second_scope)
|
424
|
+
let(:second_scope) do
|
425
|
+
subject.filter(foo: 'bar').post_filter.should(moo: 'baz').query.must_not(boo: 'baf').limit(20)
|
426
|
+
end
|
314
427
|
|
315
428
|
describe '#and' do
|
316
429
|
specify do
|
@@ -379,13 +492,17 @@ describe Chewy::Search::Request do
|
|
379
492
|
|
380
493
|
context 'integration' do
|
381
494
|
let(:products_count) { 9 }
|
382
|
-
let(:products)
|
495
|
+
let(:products) do
|
496
|
+
Array.new(products_count) do |i|
|
497
|
+
{id: i.next.to_i, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys!
|
498
|
+
end
|
499
|
+
end
|
383
500
|
let(:cities) { Array.new(3) { |i| {id: (i.next + 9).to_i}.stringify_keys! } }
|
384
501
|
let(:countries) { Array.new(3) { |i| {id: (i.next + 12).to_i}.stringify_keys! } }
|
385
502
|
before do
|
386
|
-
ProductsIndex
|
387
|
-
CountriesIndex
|
388
|
-
CitiesIndex
|
503
|
+
ProductsIndex.import!(products.map { |h| double(h) })
|
504
|
+
CountriesIndex.import!(countries.map { |h| double(h) })
|
505
|
+
CitiesIndex.import!(cities.map { |h| double(h) })
|
389
506
|
end
|
390
507
|
|
391
508
|
specify { expect(subject[0]._data).to be_a Hash }
|
@@ -425,9 +542,18 @@ describe Chewy::Search::Request do
|
|
425
542
|
|
426
543
|
describe '#highlight' do
|
427
544
|
specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name).to eq('Name3') }
|
428
|
-
specify
|
429
|
-
|
430
|
-
|
545
|
+
specify do
|
546
|
+
expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name_highlight)
|
547
|
+
.to eq('<em>Name3</em>')
|
548
|
+
end
|
549
|
+
specify do
|
550
|
+
expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name_highlights)
|
551
|
+
.to eq(['<em>Name3</em>'])
|
552
|
+
end
|
553
|
+
specify do
|
554
|
+
expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first._data['_source']['name'])
|
555
|
+
.to eq('Name3')
|
556
|
+
end
|
431
557
|
end
|
432
558
|
|
433
559
|
describe '#suggest' do
|
@@ -513,7 +639,7 @@ describe Chewy::Search::Request do
|
|
513
639
|
context do
|
514
640
|
before { expect(Chewy.client).to receive(:search).once.and_call_original }
|
515
641
|
|
516
|
-
specify { expect(subject.first).to be_a(ProductsIndex
|
642
|
+
specify { expect(subject.first).to be_a(ProductsIndex).and have_attributes(id: 9) }
|
517
643
|
specify { expect(subject.first(3).map(&:id)).to eq([9, 8, 7]) }
|
518
644
|
specify { expect(subject.first(10).map(&:id)).to have(9).items }
|
519
645
|
specify { expect(subject.limit(5).first(10).map(&:id)).to have(9).items }
|
@@ -526,7 +652,7 @@ describe Chewy::Search::Request do
|
|
526
652
|
expect(Chewy.client).not_to receive(:search)
|
527
653
|
end
|
528
654
|
|
529
|
-
specify { expect(subject.first).to be_a(ProductsIndex
|
655
|
+
specify { expect(subject.first).to be_a(ProductsIndex).and have_attributes(id: 9) }
|
530
656
|
specify { expect(subject.first(3).map(&:id)).to eq([9, 8, 7]) }
|
531
657
|
specify { expect(subject.first(10).map(&:id)).to have(9).items }
|
532
658
|
|
@@ -547,16 +673,34 @@ describe Chewy::Search::Request do
|
|
547
673
|
end
|
548
674
|
|
549
675
|
describe '#find' do
|
550
|
-
specify { expect(subject.find('1')).to be_a(ProductsIndex
|
551
|
-
specify { expect(subject.find { |w| w.id == 2 }).to be_a(ProductsIndex
|
676
|
+
specify { expect(subject.find('1')).to be_a(ProductsIndex).and have_attributes(id: 1) }
|
677
|
+
specify { expect(subject.find { |w| w.id == 2 }).to be_a(ProductsIndex).and have_attributes(id: 2) }
|
552
678
|
specify { expect(subject.limit(2).find('1', '3', '7').map(&:id)).to contain_exactly(1, 3, 7) }
|
553
679
|
specify { expect(subject.find(1, 3, 7).map(&:id)).to contain_exactly(1, 3, 7) }
|
554
|
-
specify
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
specify
|
559
|
-
|
680
|
+
specify do
|
681
|
+
expect { subject.find('1', '3', '42') }
|
682
|
+
.to raise_error Chewy::DocumentNotFound, 'Could not find documents for ids: 42'
|
683
|
+
end
|
684
|
+
specify do
|
685
|
+
expect { subject.find(1, 3, 42) }
|
686
|
+
.to raise_error Chewy::DocumentNotFound, 'Could not find documents for ids: 42'
|
687
|
+
end
|
688
|
+
specify do
|
689
|
+
expect { subject.query(match: {name: 'name3'}).find('1', '3') }
|
690
|
+
.to raise_error Chewy::DocumentNotFound, 'Could not find documents for ids: 1'
|
691
|
+
end
|
692
|
+
specify do
|
693
|
+
expect { subject.query(match: {name: 'name2'}).find('1', '3') }
|
694
|
+
.to raise_error Chewy::DocumentNotFound, 'Could not find documents for ids: 1 and 3'
|
695
|
+
end
|
696
|
+
specify do
|
697
|
+
expect { subject.filter(match: {name: 'name2'}).find('1', '3') }
|
698
|
+
.to raise_error Chewy::DocumentNotFound, 'Could not find documents for ids: 1 and 3'
|
699
|
+
end
|
700
|
+
specify do
|
701
|
+
expect { subject.post_filter(match: {name: 'name2'}).find('1', '3') }
|
702
|
+
.to raise_error Chewy::DocumentNotFound, 'Could not find documents for ids: 1 and 3'
|
703
|
+
end
|
560
704
|
|
561
705
|
context 'make sure it returns everything' do
|
562
706
|
let(:products_count) { 12 }
|
@@ -570,14 +714,18 @@ describe Chewy::Search::Request do
|
|
570
714
|
before { expect(Chewy.client).to receive(:scroll).once.and_call_original }
|
571
715
|
|
572
716
|
specify { expect(subject.find((1..9).to_a)).to have(9).items }
|
573
|
-
specify { expect(subject.find((1..9).to_a)).to all be_a(Chewy::
|
717
|
+
specify { expect(subject.find((1..9).to_a)).to all be_a(Chewy::Index) }
|
574
718
|
end
|
575
719
|
end
|
576
720
|
|
577
721
|
describe '#pluck' do
|
578
722
|
specify { expect(subject.limit(5).pluck(:_id)).to eq(%w[1 2 3 4 5]) }
|
579
|
-
specify
|
580
|
-
|
723
|
+
specify do
|
724
|
+
expect(subject.limit(5).pluck(:_id, :age)).to eq([['1', 10], ['2', 20], ['3', 30], ['4', 40], ['5', 50]])
|
725
|
+
end
|
726
|
+
specify do
|
727
|
+
expect(subject.limit(5).source(:name).pluck(:id, :age)).to eq([[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]])
|
728
|
+
end
|
581
729
|
specify do
|
582
730
|
expect(subject.limit(5).pluck(:_index, :name)).to eq([
|
583
731
|
%w[products Name1],
|