chewy 5.2.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +36 -10
- data/CHANGELOG.md +219 -326
- data/Gemfile +1 -1
- data/README.md +9 -21
- data/chewy.gemspec +1 -1
- data/gemfiles/rails.6.1.activerecord.gemfile +1 -1
- data/lib/chewy/config.rb +2 -20
- data/lib/chewy/fields/base.rb +0 -6
- data/lib/chewy/index.rb +2 -0
- data/lib/chewy/index/actions.rb +5 -1
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/search.rb +1 -4
- data/lib/chewy/search/pagination/will_paginate.rb +1 -1
- data/lib/chewy/search/parameters/none.rb +1 -3
- data/lib/chewy/search/request.rb +25 -24
- data/lib/chewy/search/scrolling.rb +4 -1
- data/lib/chewy/type.rb +4 -1
- data/lib/chewy/type/adapter/orm.rb +6 -3
- data/lib/chewy/type/import.rb +1 -0
- data/lib/chewy/type/syncer.rb +4 -5
- data/lib/chewy/type/witchcraft.rb +3 -1
- data/lib/chewy/type/wrapper.rb +11 -1
- data/lib/chewy/version.rb +1 -1
- data/migration_guide.md +18 -0
- data/spec/chewy/config_spec.rb +0 -21
- data/spec/chewy/index/actions_spec.rb +24 -0
- data/spec/chewy/index_spec.rb +16 -39
- data/spec/chewy/journal_spec.rb +21 -17
- data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
- data/spec/chewy/multi_search_spec.rb +85 -0
- data/spec/chewy/rake_helper_spec.rb +102 -87
- data/spec/chewy/rspec/update_index_spec.rb +47 -46
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/parameters/indices_spec.rb +6 -7
- data/spec/chewy/search/parameters/none_spec.rb +1 -1
- data/spec/chewy/search/parameters_spec.rb +1 -1
- data/spec/chewy/search/request_spec.rb +82 -67
- data/spec/chewy/search/response_spec.rb +19 -15
- data/spec/chewy/search/scrolling_spec.rb +25 -16
- data/spec/chewy/search_spec.rb +45 -41
- data/spec/chewy/stash_spec.rb +14 -12
- data/spec/chewy/type/adapter/active_record_spec.rb +13 -1
- data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
- data/spec/chewy/type/import/journal_builder_spec.rb +9 -7
- data/spec/chewy/type/mapping_spec.rb +3 -1
- data/spec/chewy/type/witchcraft_spec.rb +15 -0
- data/spec/chewy/type/wrapper_spec.rb +3 -1
- data/spec/chewy_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -7
- data/spec/support/active_record.rb +20 -0
- metadata +8 -78
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/ruby3.gemfile +0 -10
- data/lib/chewy/query.rb +0 -1142
- data/lib/chewy/query/compose.rb +0 -68
- data/lib/chewy/query/criteria.rb +0 -191
- data/lib/chewy/query/filters.rb +0 -244
- data/lib/chewy/query/loading.rb +0 -110
- data/lib/chewy/query/nodes/and.rb +0 -25
- data/lib/chewy/query/nodes/base.rb +0 -17
- data/lib/chewy/query/nodes/bool.rb +0 -34
- data/lib/chewy/query/nodes/equal.rb +0 -34
- data/lib/chewy/query/nodes/exists.rb +0 -20
- data/lib/chewy/query/nodes/expr.rb +0 -28
- data/lib/chewy/query/nodes/field.rb +0 -110
- data/lib/chewy/query/nodes/has_child.rb +0 -15
- data/lib/chewy/query/nodes/has_parent.rb +0 -15
- data/lib/chewy/query/nodes/has_relation.rb +0 -59
- data/lib/chewy/query/nodes/match_all.rb +0 -11
- data/lib/chewy/query/nodes/missing.rb +0 -20
- data/lib/chewy/query/nodes/not.rb +0 -25
- data/lib/chewy/query/nodes/or.rb +0 -25
- data/lib/chewy/query/nodes/prefix.rb +0 -19
- data/lib/chewy/query/nodes/query.rb +0 -20
- data/lib/chewy/query/nodes/range.rb +0 -63
- data/lib/chewy/query/nodes/raw.rb +0 -15
- data/lib/chewy/query/nodes/regexp.rb +0 -35
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination.rb +0 -25
- data/spec/chewy/query/criteria_spec.rb +0 -700
- data/spec/chewy/query/filters_spec.rb +0 -201
- data/spec/chewy/query/loading_spec.rb +0 -124
- data/spec/chewy/query/nodes/and_spec.rb +0 -12
- data/spec/chewy/query/nodes/bool_spec.rb +0 -14
- data/spec/chewy/query/nodes/equal_spec.rb +0 -32
- data/spec/chewy/query/nodes/exists_spec.rb +0 -18
- data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -16
- data/spec/chewy/query/nodes/not_spec.rb +0 -14
- data/spec/chewy/query/nodes/or_spec.rb +0 -12
- data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
- data/spec/chewy/query/nodes/query_spec.rb +0 -12
- data/spec/chewy/query/nodes/range_spec.rb +0 -32
- data/spec/chewy/query/nodes/raw_spec.rb +0 -11
- data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
- data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
- data/spec/chewy/query/pagination_spec.rb +0 -39
- data/spec/chewy/query_spec.rb +0 -637
@@ -4,7 +4,9 @@ describe :update_index do
|
|
4
4
|
before do
|
5
5
|
stub_index(:dummies) do
|
6
6
|
define_type :dummy
|
7
|
-
|
7
|
+
end
|
8
|
+
stub_index(:dummies2) do
|
9
|
+
define_type :dummy
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
@@ -13,19 +15,18 @@ describe :update_index do
|
|
13
15
|
DummiesIndex.create!
|
14
16
|
end
|
15
17
|
|
16
|
-
specify { expect {}.not_to update_index(DummiesIndex
|
17
|
-
specify { expect { DummiesIndex::Dummy.bulk body: [] }.not_to update_index(DummiesIndex
|
18
|
+
specify { expect {}.not_to update_index(DummiesIndex) }
|
19
|
+
specify { expect { DummiesIndex::Dummy.bulk body: [] }.not_to update_index(DummiesIndex) }
|
18
20
|
|
19
21
|
specify do
|
20
|
-
expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.not_to update_index(DummiesIndex
|
22
|
+
expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.not_to update_index(DummiesIndex) }
|
21
23
|
.to fail_with(/Expected index .* not to be updated, but it was with/)
|
22
24
|
end
|
23
25
|
|
24
26
|
specify do
|
25
27
|
expect do
|
26
28
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
27
|
-
|
28
|
-
end.to update_index(DummiesIndex::Dummy).and_reindex(41, 42).only
|
29
|
+
end.to update_index(DummiesIndex).and_reindex(41, 42).only
|
29
30
|
end
|
30
31
|
|
31
32
|
context do
|
@@ -33,7 +34,7 @@ describe :update_index do
|
|
33
34
|
expect do
|
34
35
|
expect do
|
35
36
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}, {index: {_id: 41}}, {index: {_id: 42}}]
|
36
|
-
end.not_to update_index(DummiesIndex
|
37
|
+
end.not_to update_index(DummiesIndex)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -45,60 +46,60 @@ describe :update_index do
|
|
45
46
|
specify do
|
46
47
|
expect do
|
47
48
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
48
|
-
|
49
|
-
end.to update_index(DummiesIndex
|
50
|
-
.and update_index(
|
49
|
+
Dummies2Index::Dummy.bulk body: [{index: {_id: 43, data: {}}}]
|
50
|
+
end.to update_index(DummiesIndex).and_reindex(41, 42).only
|
51
|
+
.and update_index(Dummies2Index).and_reindex(43).only
|
51
52
|
end
|
52
53
|
|
53
54
|
context do
|
54
55
|
let(:expectation) do
|
55
56
|
expect do
|
56
57
|
expect do
|
57
|
-
|
58
|
-
end.to update_index(DummiesIndex
|
59
|
-
.and update_index(
|
58
|
+
Dummies2Index::Dummy.bulk body: [{index: {_id: 43, data: {}}}]
|
59
|
+
end.to update_index(DummiesIndex).and_reindex(41, 42).only
|
60
|
+
.and update_index(Dummies2Index).and_reindex(43).only
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
|
-
specify { expectation.to fail_matching 'Expected index `DummiesIndex
|
64
|
+
specify { expectation.to fail_matching 'Expected index `DummiesIndex` to be updated' }
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
67
68
|
context '#only' do
|
68
69
|
specify do
|
69
70
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
|
70
|
-
.to update_index(DummiesIndex
|
71
|
+
.to update_index(DummiesIndex).and_reindex(41, 42).only
|
71
72
|
end
|
72
73
|
specify do
|
73
74
|
expect do
|
74
75
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
|
75
|
-
.to update_index(DummiesIndex
|
76
|
+
.to update_index(DummiesIndex).and_reindex(41).only
|
76
77
|
end
|
77
78
|
.to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
|
78
79
|
end
|
79
80
|
specify do
|
80
81
|
expect do
|
81
82
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
|
82
|
-
.to update_index(DummiesIndex
|
83
|
+
.to update_index(DummiesIndex).and_reindex(41, times: 2).only
|
83
84
|
end
|
84
85
|
.to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
|
85
86
|
end
|
86
87
|
|
87
88
|
specify do
|
88
89
|
expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
|
89
|
-
.to update_index(DummiesIndex
|
90
|
+
.to update_index(DummiesIndex).and_delete(41, 42).only
|
90
91
|
end
|
91
92
|
specify do
|
92
93
|
expect do
|
93
94
|
expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
|
94
|
-
.to update_index(DummiesIndex
|
95
|
+
.to update_index(DummiesIndex).and_delete(41).only
|
95
96
|
end
|
96
97
|
.to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
|
97
98
|
end
|
98
99
|
specify do
|
99
100
|
expect do
|
100
101
|
expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
|
101
|
-
.to update_index(DummiesIndex
|
102
|
+
.to update_index(DummiesIndex).and_delete(41, times: 2).only
|
102
103
|
end
|
103
104
|
.to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
|
104
105
|
end
|
@@ -106,57 +107,57 @@ describe :update_index do
|
|
106
107
|
specify do
|
107
108
|
expect do
|
108
109
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
|
109
|
-
.to update_index(DummiesIndex
|
110
|
+
.to update_index(DummiesIndex).and_reindex(42).only
|
110
111
|
end
|
111
112
|
.to fail_matching 'to update documents ["42"] only, but ["41"] was deleted also'
|
112
113
|
end
|
113
114
|
specify do
|
114
115
|
expect do
|
115
116
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}, {delete: {_id: 41}}] }
|
116
|
-
.to update_index(DummiesIndex
|
117
|
+
.to update_index(DummiesIndex).and_reindex(42).only
|
117
118
|
end
|
118
119
|
.to fail_matching 'to update documents ["42"] only, but ["43"] was updated and ["41"] was deleted also'
|
119
120
|
end
|
120
121
|
specify do
|
121
122
|
expect do
|
122
123
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
|
123
|
-
.to update_index(DummiesIndex
|
124
|
+
.to update_index(DummiesIndex).and_delete(41).only
|
124
125
|
end
|
125
126
|
.to fail_matching 'to delete documents ["41"] only, but ["42"] was updated also'
|
126
127
|
end
|
127
128
|
specify do
|
128
129
|
expect do
|
129
130
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}, {delete: {_id: 43}}] }
|
130
|
-
.to update_index(DummiesIndex
|
131
|
+
.to update_index(DummiesIndex).and_delete(41).only
|
131
132
|
end
|
132
133
|
.to fail_matching 'to delete documents ["41"] only, but ["42"] was updated and ["43"] was deleted also'
|
133
134
|
end
|
134
135
|
end
|
135
136
|
|
136
137
|
context '#and_reindex' do
|
137
|
-
specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.to update_index(DummiesIndex
|
138
|
+
specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.to update_index(DummiesIndex) }
|
138
139
|
specify do
|
139
140
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}] }
|
140
|
-
.to update_index(DummiesIndex
|
141
|
+
.to update_index(DummiesIndex).and_reindex(42)
|
141
142
|
end
|
142
143
|
specify do
|
143
144
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
|
144
|
-
.to update_index(DummiesIndex
|
145
|
+
.to update_index(DummiesIndex).and_reindex(double(id: 42))
|
145
146
|
end
|
146
147
|
specify do
|
147
148
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
|
148
|
-
.to update_index(DummiesIndex
|
149
|
+
.to update_index(DummiesIndex).and_reindex(double(id: 42), double(id: 43))
|
149
150
|
end
|
150
151
|
specify do
|
151
152
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
|
152
|
-
.to update_index(DummiesIndex
|
153
|
+
.to update_index(DummiesIndex).and_reindex([double(id: 42), 43])
|
153
154
|
end
|
154
155
|
|
155
156
|
specify do
|
156
157
|
expect do
|
157
158
|
expect do
|
158
159
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
|
159
|
-
end.to update_index(DummiesIndex
|
160
|
+
end.to update_index(DummiesIndex).and_reindex([44, 43])
|
160
161
|
end.to fail_matching 'Expected document with id `44` to be reindexed, but it was not'
|
161
162
|
end
|
162
163
|
|
@@ -165,7 +166,7 @@ describe :update_index do
|
|
165
166
|
expect do
|
166
167
|
expect do
|
167
168
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
|
168
|
-
end.to update_index(DummiesIndex
|
169
|
+
end.to update_index(DummiesIndex).and_reindex(44, double(id: 47)) end
|
169
170
|
end
|
170
171
|
|
171
172
|
specify { expectation.to fail_matching('Expected document with id `44` to be reindexed, but it was not') }
|
@@ -177,13 +178,13 @@ describe :update_index do
|
|
177
178
|
expect do
|
178
179
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
|
179
180
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
|
180
|
-
end.to update_index(DummiesIndex
|
181
|
+
end.to update_index(DummiesIndex).and_reindex(42, 44, times: 1).and_reindex(43, times: 2) end
|
181
182
|
|
182
183
|
specify do
|
183
184
|
expect do
|
184
185
|
expect do
|
185
186
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
|
186
|
-
end.to update_index(DummiesIndex
|
187
|
+
end.to update_index(DummiesIndex).and_reindex(42, times: 3)
|
187
188
|
end.to fail_matching('Expected document with id `42` to be reindexed, but it was not') end
|
188
189
|
|
189
190
|
context do
|
@@ -192,7 +193,7 @@ describe :update_index do
|
|
192
193
|
expect do
|
193
194
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
|
194
195
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
|
195
|
-
end.to update_index(DummiesIndex
|
196
|
+
end.to update_index(DummiesIndex).and_reindex(42, times: 3).and_reindex(44, 43, times: 4) end
|
196
197
|
end
|
197
198
|
|
198
199
|
specify { expectation.to fail_matching 'Expected document with id `44` to be reindexed' }
|
@@ -206,18 +207,18 @@ describe :update_index do
|
|
206
207
|
specify do
|
207
208
|
expect do
|
208
209
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
|
209
|
-
end.to update_index(DummiesIndex
|
210
|
+
end.to update_index(DummiesIndex).and_reindex(42, with: {a: 2}) end
|
210
211
|
|
211
212
|
specify do
|
212
213
|
expect do
|
213
214
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'b' => 2}}}]
|
214
|
-
end.to update_index(DummiesIndex
|
215
|
+
end.to update_index(DummiesIndex).and_reindex(42, with: {a: '1', b: 2}) end
|
215
216
|
|
216
217
|
specify do
|
217
218
|
expect do
|
218
219
|
expect do
|
219
220
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
|
220
|
-
end.to update_index(DummiesIndex
|
221
|
+
end.to update_index(DummiesIndex).and_reindex(42, with: {a: 1})
|
221
222
|
end.to fail_matching('Expected document with id `42` to be reindexed, but it was not') end
|
222
223
|
|
223
224
|
[
|
@@ -230,7 +231,7 @@ describe :update_index do
|
|
230
231
|
specify do
|
231
232
|
expect do
|
232
233
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: data}}]
|
233
|
-
end.to update_index(DummiesIndex
|
234
|
+
end.to update_index(DummiesIndex).and_reindex(42, with: with) end
|
234
235
|
end
|
235
236
|
|
236
237
|
[
|
@@ -244,7 +245,7 @@ describe :update_index do
|
|
244
245
|
expect do
|
245
246
|
expect do
|
246
247
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: data}}]
|
247
|
-
end.to update_index(DummiesIndex
|
248
|
+
end.to update_index(DummiesIndex).and_reindex(42, with: with)
|
248
249
|
end.to fail_matching('Expected document with id `42` to be reindexed') end
|
249
250
|
end
|
250
251
|
|
@@ -253,7 +254,7 @@ describe :update_index do
|
|
253
254
|
expect do
|
254
255
|
expect do
|
255
256
|
DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
|
256
|
-
end.to update_index(DummiesIndex
|
257
|
+
end.to update_index(DummiesIndex).and_reindex(43, times: 2, with: {a: 2}) end
|
257
258
|
end
|
258
259
|
|
259
260
|
specify { expectation.to fail_matching 'Expected document with id `43` to be reindexed' }
|
@@ -266,26 +267,26 @@ describe :update_index do
|
|
266
267
|
context '#and_delete' do
|
267
268
|
specify do
|
268
269
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
|
269
|
-
.to update_index(DummiesIndex
|
270
|
+
.to update_index(DummiesIndex).and_reindex(42).and_delete(double(id: 43))
|
270
271
|
end
|
271
272
|
specify do
|
272
273
|
expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
|
273
|
-
.to update_index(DummiesIndex
|
274
|
+
.to update_index(DummiesIndex).and_delete(42).and_delete(double(id: 43))
|
274
275
|
end
|
275
276
|
specify do
|
276
277
|
expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
|
277
|
-
.to update_index(DummiesIndex
|
278
|
+
.to update_index(DummiesIndex).and_delete(42, double(id: 43))
|
278
279
|
end
|
279
280
|
specify do
|
280
281
|
expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
|
281
|
-
.to update_index(DummiesIndex
|
282
|
+
.to update_index(DummiesIndex).and_delete([43, double(id: 42)])
|
282
283
|
end
|
283
284
|
|
284
285
|
context do
|
285
286
|
let(:expectation) do
|
286
287
|
expect do
|
287
288
|
expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
|
288
|
-
.to update_index(DummiesIndex
|
289
|
+
.to update_index(DummiesIndex).and_reindex(43).and_delete(double(id: 42))
|
289
290
|
end
|
290
291
|
end
|
291
292
|
|
@@ -297,7 +298,7 @@ describe :update_index do
|
|
297
298
|
let(:expectation) do
|
298
299
|
expect do
|
299
300
|
expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42, data: {}}}, {delete: {_id: 42}}] }
|
300
|
-
.to update_index(DummiesIndex
|
301
|
+
.to update_index(DummiesIndex).and_delete(44, times: 2).and_delete(double(id: 42), times: 3)
|
301
302
|
end
|
302
303
|
end
|
303
304
|
|
data/spec/chewy/runtime_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Chewy::Runtime do
|
4
4
|
describe '.version' do
|
5
5
|
specify { expect(described_class.version).to be_a(described_class::Version) }
|
6
|
-
specify { expect(described_class.version).to be >= '
|
7
|
-
specify { expect(described_class.version).to be < '
|
6
|
+
specify { expect(described_class.version).to be >= '5.6' }
|
7
|
+
specify { expect(described_class.version).to be < '7.0' }
|
8
8
|
end
|
9
9
|
end
|
@@ -4,7 +4,6 @@ describe Chewy::Search::Parameters::Indices do
|
|
4
4
|
before do
|
5
5
|
stub_index(:first) do
|
6
6
|
define_type :one
|
7
|
-
define_type :two
|
8
7
|
end
|
9
8
|
|
10
9
|
stub_index(:second) do
|
@@ -70,7 +69,7 @@ describe Chewy::Search::Parameters::Indices do
|
|
70
69
|
specify do
|
71
70
|
expect(described_class.new(
|
72
71
|
indices: FirstIndex
|
73
|
-
).render).to eq(index: %w[first], type: %w[one
|
72
|
+
).render).to eq(index: %w[first], type: %w[one])
|
74
73
|
end
|
75
74
|
specify do
|
76
75
|
expect(described_class.new(
|
@@ -90,7 +89,7 @@ describe Chewy::Search::Parameters::Indices do
|
|
90
89
|
specify do
|
91
90
|
expect(described_class.new(
|
92
91
|
indices: FirstIndex, types: SecondIndex::Three
|
93
|
-
).render).to eq(index: %w[first second], type: %w[one three
|
92
|
+
).render).to eq(index: %w[first second], type: %w[one three])
|
94
93
|
end
|
95
94
|
specify do
|
96
95
|
expect(described_class.new(
|
@@ -100,7 +99,7 @@ describe Chewy::Search::Parameters::Indices do
|
|
100
99
|
specify do
|
101
100
|
expect(described_class.new(
|
102
101
|
indices: FirstIndex, types: :whatever
|
103
|
-
).render).to eq(index: %w[first], type: %w[one
|
102
|
+
).render).to eq(index: %w[first], type: %w[one])
|
104
103
|
end
|
105
104
|
specify do
|
106
105
|
expect(described_class.new(
|
@@ -130,7 +129,7 @@ describe Chewy::Search::Parameters::Indices do
|
|
130
129
|
specify do
|
131
130
|
expect(described_class.new(
|
132
131
|
indices: FirstIndex, types: [SecondIndex::Three, :whatever]
|
133
|
-
).render).to eq(index: %w[first second], type: %w[one three
|
132
|
+
).render).to eq(index: %w[first second], type: %w[one three])
|
134
133
|
end
|
135
134
|
specify do
|
136
135
|
expect(described_class.new(
|
@@ -151,7 +150,7 @@ describe Chewy::Search::Parameters::Indices do
|
|
151
150
|
.to eq(described_class.new(indices: SecondIndex, types: :whatever))
|
152
151
|
end
|
153
152
|
specify do
|
154
|
-
expect(described_class.new(indices: :first, types: %w[one
|
153
|
+
expect(described_class.new(indices: :first, types: %w[one]))
|
155
154
|
.to eq(described_class.new(indices: FirstIndex))
|
156
155
|
end
|
157
156
|
specify do
|
@@ -175,7 +174,7 @@ describe Chewy::Search::Parameters::Indices do
|
|
175
174
|
indices: [FirstIndex, :whatever],
|
176
175
|
types: [SecondIndex::Three, :whatever]
|
177
176
|
).types).to contain_exactly(
|
178
|
-
FirstIndex::One,
|
177
|
+
FirstIndex::One, SecondIndex::Three
|
179
178
|
)
|
180
179
|
end
|
181
180
|
|
@@ -141,7 +141,7 @@ describe Chewy::Search::Parameters do
|
|
141
141
|
|
142
142
|
context do
|
143
143
|
subject { described_class.new(filter: {moo: 'baz'}, none: true) }
|
144
|
-
specify { expect(subject.render).to eq(body: {query: {
|
144
|
+
specify { expect(subject.render).to eq(body: {query: {match_none: {}}}) }
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
@@ -10,17 +10,19 @@ describe Chewy::Search::Request do
|
|
10
10
|
field :name
|
11
11
|
field :age, type: :integer
|
12
12
|
end
|
13
|
+
end
|
14
|
+
|
15
|
+
stub_index(:cities) do
|
13
16
|
define_type :city do
|
14
17
|
field :id, type: :integer
|
15
18
|
end
|
19
|
+
end
|
20
|
+
|
21
|
+
stub_index(:countries) do
|
16
22
|
define_type :country do
|
17
23
|
field :id, type: :integer
|
18
24
|
end
|
19
25
|
end
|
20
|
-
|
21
|
-
stub_index(:cities) do
|
22
|
-
define_type :city
|
23
|
-
end
|
24
26
|
end
|
25
27
|
|
26
28
|
subject { described_class.new(ProductsIndex) }
|
@@ -30,11 +32,7 @@ describe Chewy::Search::Request do
|
|
30
32
|
specify { expect(described_class.new(ProductsIndex)).not_to eq(described_class.new(CitiesIndex)) }
|
31
33
|
specify { expect(described_class.new(ProductsIndex)).not_to eq(described_class.new(ProductsIndex, CitiesIndex)) }
|
32
34
|
specify { expect(described_class.new(CitiesIndex, ProductsIndex)).to eq(described_class.new(ProductsIndex, CitiesIndex)) }
|
33
|
-
specify { expect(described_class.new(ProductsIndex
|
34
|
-
specify { expect(described_class.new(ProductsIndex::Product)).not_to eq(described_class.new(ProductsIndex::City)) }
|
35
|
-
specify { expect(described_class.new(ProductsIndex::Product)).not_to eq(described_class.new(ProductsIndex::Product, ProductsIndex::City)) }
|
36
|
-
specify { expect(described_class.new(ProductsIndex::City, ProductsIndex::Product)).to eq(described_class.new(ProductsIndex::Product, ProductsIndex::City)) }
|
37
|
-
specify { expect(described_class.new(ProductsIndex::City, CitiesIndex::City)).to eq(described_class.new(CitiesIndex::City, ProductsIndex::City)) }
|
35
|
+
specify { expect(described_class.new(ProductsIndex, CitiesIndex)).to eq(described_class.new(CitiesIndex, ProductsIndex)) }
|
38
36
|
|
39
37
|
specify { expect(described_class.new(ProductsIndex).limit(10)).to eq(described_class.new(ProductsIndex).limit(10)) }
|
40
38
|
specify { expect(described_class.new(ProductsIndex).limit(10)).not_to eq(described_class.new(ProductsIndex).limit(20)) }
|
@@ -48,7 +46,7 @@ describe Chewy::Search::Request do
|
|
48
46
|
expect(subject.render)
|
49
47
|
.to match(
|
50
48
|
index: %w[products],
|
51
|
-
type: array_including(%w[product
|
49
|
+
type: array_including(%w[product]),
|
52
50
|
body: {}
|
53
51
|
)
|
54
52
|
end
|
@@ -57,11 +55,11 @@ describe Chewy::Search::Request do
|
|
57
55
|
describe '#inspect' do
|
58
56
|
specify do
|
59
57
|
expect(described_class.new(ProductsIndex).inspect)
|
60
|
-
.to eq('<Chewy::Search::Request {:index=>["products"], :type=>["
|
58
|
+
.to eq('<Chewy::Search::Request {:index=>["products"], :type=>["product"], :body=>{}}>')
|
61
59
|
end
|
62
60
|
specify do
|
63
61
|
expect(ProductsIndex.limit(10).inspect)
|
64
|
-
.to eq('<ProductsIndex::Query {:index=>["products"], :type=>["
|
62
|
+
.to eq('<ProductsIndex::Query {:index=>["products"], :type=>["product"], :body=>{:size=>10}}>')
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
@@ -235,9 +233,8 @@ describe Chewy::Search::Request do
|
|
235
233
|
|
236
234
|
describe '#types' do
|
237
235
|
specify { expect(subject.types(:product).render[:type]).to contain_exactly('product') }
|
238
|
-
specify { expect(
|
239
|
-
specify { expect(subject.types(
|
240
|
-
specify { expect(subject.types(:product).types(:product, :city, :something).render[:type]).to match_array(%w[product city]) }
|
236
|
+
specify { expect(subject.types(%i[product city]).types(nil).render[:type]).to match_array(%w[product]) }
|
237
|
+
specify { expect(subject.types(:product).types(:product, :city, :something).render[:type]).to match_array(%w[product]) }
|
241
238
|
specify { expect(subject.types(nil).render[:body]).to be_blank }
|
242
239
|
specify { expect { subject.types(:product) }.not_to change { subject.render } }
|
243
240
|
end
|
@@ -279,14 +276,16 @@ describe Chewy::Search::Request do
|
|
279
276
|
define_type City do
|
280
277
|
field :rating, type: 'integer'
|
281
278
|
end
|
279
|
+
end
|
282
280
|
|
281
|
+
stub_index(:countries) do
|
283
282
|
define_type Country do
|
284
283
|
field :rating, type: 'integer'
|
285
284
|
end
|
286
285
|
end
|
287
286
|
end
|
288
287
|
|
289
|
-
before { PlacesIndex.import!(cities
|
288
|
+
before { PlacesIndex.import!(cities) }
|
290
289
|
|
291
290
|
let(:cities) { Array.new(2) { |i| City.create!(rating: i) } }
|
292
291
|
let(:countries) { Array.new(2) { |i| Country.create!(rating: i + 2) } }
|
@@ -294,14 +293,14 @@ describe Chewy::Search::Request do
|
|
294
293
|
subject { described_class.new(PlacesIndex).order(:rating) }
|
295
294
|
|
296
295
|
describe '#objects' do
|
297
|
-
specify { expect(subject.objects).to eq([*cities
|
296
|
+
specify { expect(subject.objects).to eq([*cities]) }
|
298
297
|
specify { expect(subject.objects.class).to eq(Array) }
|
299
298
|
end
|
300
299
|
|
301
300
|
describe '#load' do
|
302
|
-
specify { expect(subject.load(only: 'city')).to eq([*cities
|
303
|
-
specify { expect(subject.load(only: 'city').map(&:class).uniq).to eq([PlacesIndex::City
|
304
|
-
specify { expect(subject.load(only: 'city').objects).to eq([*cities
|
301
|
+
specify { expect(subject.load(only: 'city')).to eq([*cities]) }
|
302
|
+
specify { expect(subject.load(only: 'city').map(&:class).uniq).to eq([PlacesIndex::City]) }
|
303
|
+
specify { expect(subject.load(only: 'city').objects).to eq([*cities]) }
|
305
304
|
end
|
306
305
|
end
|
307
306
|
|
@@ -388,13 +387,13 @@ describe Chewy::Search::Request do
|
|
388
387
|
end
|
389
388
|
|
390
389
|
context 'integration' do
|
391
|
-
let(:
|
392
|
-
let(:
|
393
|
-
let(:
|
390
|
+
let(:products_count) { 9 }
|
391
|
+
let(:products) { Array.new(products_count) { |i| {id: i.next.to_i, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
392
|
+
let(:cities) { Array.new(3) { |i| {id: (i.next + 9).to_i}.stringify_keys! } }
|
393
|
+
let(:countries) { Array.new(3) { |i| {id: (i.next + 12).to_i}.stringify_keys! } }
|
394
394
|
before do
|
395
395
|
ProductsIndex::Product.import!(products.map { |h| double(h) })
|
396
|
-
|
397
|
-
ProductsIndex::Country.import!(countries.map { |h| double(h) })
|
396
|
+
CountriesIndex::Country.import!(countries.map { |h| double(h) })
|
398
397
|
CitiesIndex::City.import!(cities.map { |h| double(h) })
|
399
398
|
end
|
400
399
|
|
@@ -407,18 +406,11 @@ describe Chewy::Search::Request do
|
|
407
406
|
specify { expect(subject.size).to eq(3) }
|
408
407
|
end
|
409
408
|
|
410
|
-
context '
|
411
|
-
subject { described_class.new(
|
409
|
+
context 'mixed indexes' do
|
410
|
+
subject { described_class.new(CitiesIndex, ProductsIndex) }
|
412
411
|
|
413
|
-
specify { expect(subject.count).to eq(
|
414
|
-
specify { expect(subject.size).to eq(
|
415
|
-
end
|
416
|
-
|
417
|
-
context 'mixed types' do
|
418
|
-
subject { described_class.new(CitiesIndex, ProductsIndex::Product) }
|
419
|
-
|
420
|
-
specify { expect(subject.count).to eq(9) }
|
421
|
-
specify { expect(subject.size).to eq(9) }
|
412
|
+
specify { expect(subject.count).to eq(12) }
|
413
|
+
specify { expect(subject.size).to eq(10) } # pagination limit
|
422
414
|
end
|
423
415
|
|
424
416
|
context 'instrumentation' do
|
@@ -431,9 +423,9 @@ describe Chewy::Search::Request do
|
|
431
423
|
expect(outer_payload).to eq(
|
432
424
|
index: ProductsIndex,
|
433
425
|
indexes: [ProductsIndex],
|
434
|
-
request: {index: ['products'], type: %w[
|
435
|
-
type:
|
436
|
-
types: [ProductsIndex::Product
|
426
|
+
request: {index: ['products'], type: %w[product], body: {query: {match: {name: 'name3'}}}},
|
427
|
+
type: ProductsIndex::Product,
|
428
|
+
types: [ProductsIndex::Product]
|
437
429
|
)
|
438
430
|
end
|
439
431
|
end
|
@@ -445,10 +437,13 @@ describe Chewy::Search::Request do
|
|
445
437
|
describe '#highlight' do
|
446
438
|
specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name).to eq('Name3') }
|
447
439
|
specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name_highlight).to eq('<em>Name3</em>') }
|
440
|
+
specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name_highlights).to eq(['<em>Name3</em>']) }
|
448
441
|
specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first._data['_source']['name']).to eq('Name3') }
|
449
442
|
end
|
450
443
|
|
451
444
|
describe '#suggest' do
|
445
|
+
let(:products_count) { 3 }
|
446
|
+
|
452
447
|
specify do
|
453
448
|
expect(subject.suggest(
|
454
449
|
foo: {
|
@@ -470,7 +465,7 @@ describe Chewy::Search::Request do
|
|
470
465
|
describe '#aggs' do
|
471
466
|
specify do
|
472
467
|
expect(subject.aggs(avg_age: {avg: {field: :age}}).aggs)
|
473
|
-
.to eq('avg_age' => {'value' =>
|
468
|
+
.to eq('avg_age' => {'value' => 50.0})
|
474
469
|
end
|
475
470
|
end
|
476
471
|
|
@@ -490,8 +485,7 @@ describe Chewy::Search::Request do
|
|
490
485
|
specify { expect(subject.count).to eq(9) }
|
491
486
|
specify { expect(subject.limit(6).count).to eq(9) }
|
492
487
|
specify { expect(subject.offset(6).count).to eq(9) }
|
493
|
-
specify { expect(subject.
|
494
|
-
specify { expect(subject.types(:product, :country).count).to eq(6) }
|
488
|
+
specify { expect(subject.indices(:products, CountriesIndex).count).to eq(12) }
|
495
489
|
specify { expect(subject.filter(term: {age: 10}).count).to eq(1) }
|
496
490
|
specify { expect(subject.query(term: {age: 10}).count).to eq(1) }
|
497
491
|
specify { expect(subject.order(nil).count).to eq(9) }
|
@@ -530,7 +524,7 @@ describe Chewy::Search::Request do
|
|
530
524
|
context do
|
531
525
|
before { expect(Chewy.client).to receive(:search).once.and_call_original }
|
532
526
|
|
533
|
-
specify { expect(subject.first).to be_a(ProductsIndex::
|
527
|
+
specify { expect(subject.first).to be_a(ProductsIndex::Product).and have_attributes(id: 9) }
|
534
528
|
specify { expect(subject.first(3).map(&:id)).to eq([9, 8, 7]) }
|
535
529
|
specify { expect(subject.first(10).map(&:id)).to have(9).items }
|
536
530
|
specify { expect(subject.limit(5).first(10).map(&:id)).to have(9).items }
|
@@ -543,7 +537,7 @@ describe Chewy::Search::Request do
|
|
543
537
|
expect(Chewy.client).not_to receive(:search)
|
544
538
|
end
|
545
539
|
|
546
|
-
specify { expect(subject.first).to be_a(ProductsIndex::
|
540
|
+
specify { expect(subject.first).to be_a(ProductsIndex::Product).and have_attributes(id: 9) }
|
547
541
|
specify { expect(subject.first(3).map(&:id)).to eq([9, 8, 7]) }
|
548
542
|
specify { expect(subject.first(10).map(&:id)).to have(9).items }
|
549
543
|
|
@@ -576,7 +570,7 @@ describe Chewy::Search::Request do
|
|
576
570
|
specify { expect { subject.post_filter(match: {name: 'name2'}).find('1', '3') }.to raise_error Chewy::DocumentNotFound, 'Could not find documents for ids: 1 and 3' }
|
577
571
|
|
578
572
|
context 'make sure it returns everything' do
|
579
|
-
let(:
|
573
|
+
let(:products_count) { 12 }
|
580
574
|
before { expect(Chewy.client).not_to receive(:scroll) }
|
581
575
|
|
582
576
|
specify { expect(subject.find((1..12).to_a)).to have(12).items }
|
@@ -593,15 +587,15 @@ describe Chewy::Search::Request do
|
|
593
587
|
|
594
588
|
describe '#pluck' do
|
595
589
|
specify { expect(subject.limit(5).pluck(:_id)).to eq(%w[1 2 3 4 5]) }
|
596
|
-
specify { expect(subject.limit(5).pluck(:_id, :age)).to eq([['1', 10], ['2', 20], ['3', 30], ['4',
|
597
|
-
specify { expect(subject.limit(5).source(:name).pluck(:id, :age)).to eq([[1, 10], [2, 20], [3, 30], [4,
|
590
|
+
specify { expect(subject.limit(5).pluck(:_id, :age)).to eq([['1', 10], ['2', 20], ['3', 30], ['4', 40], ['5', 50]]) }
|
591
|
+
specify { expect(subject.limit(5).source(:name).pluck(:id, :age)).to eq([[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]]) }
|
598
592
|
specify do
|
599
593
|
expect(subject.limit(5).pluck(:_index, :_type, :name)).to eq([
|
600
594
|
%w[products product Name1],
|
601
595
|
%w[products product Name2],
|
602
596
|
%w[products product Name3],
|
603
|
-
[
|
604
|
-
[
|
597
|
+
%w[products product Name4],
|
598
|
+
%w[products product Name5]
|
605
599
|
])
|
606
600
|
end
|
607
601
|
|
@@ -632,24 +626,12 @@ describe Chewy::Search::Request do
|
|
632
626
|
Chewy.client.indices.refresh(index: 'products')
|
633
627
|
end.to change { described_class.new(ProductsIndex).total_count }.from(9).to(7)
|
634
628
|
end
|
635
|
-
specify do
|
636
|
-
expect do
|
637
|
-
subject.types(:product).delete_all
|
638
|
-
Chewy.client.indices.refresh(index: 'products')
|
639
|
-
end.to change { described_class.new(ProductsIndex::Product).total_entries }.from(3).to(0)
|
640
|
-
end
|
641
629
|
specify do
|
642
630
|
expect do
|
643
631
|
subject.delete_all
|
644
632
|
Chewy.client.indices.refresh(index: 'products')
|
645
633
|
end.to change { described_class.new(ProductsIndex).total }.from(9).to(0)
|
646
634
|
end
|
647
|
-
specify do
|
648
|
-
expect do
|
649
|
-
described_class.new(ProductsIndex::City).delete_all
|
650
|
-
Chewy.client.indices.refresh(index: 'products')
|
651
|
-
end.to change { described_class.new(ProductsIndex).total }.from(9).to(6)
|
652
|
-
end
|
653
635
|
|
654
636
|
specify do
|
655
637
|
outer_payload = nil
|
@@ -660,9 +642,9 @@ describe Chewy::Search::Request do
|
|
660
642
|
expect(outer_payload).to eq(
|
661
643
|
index: ProductsIndex,
|
662
644
|
indexes: [ProductsIndex],
|
663
|
-
request: {index: ['products'], type: %w[
|
664
|
-
type:
|
665
|
-
types: [ProductsIndex::Product
|
645
|
+
request: {index: ['products'], type: %w[product], body: {query: {match: {name: 'name3'}}}, refresh: true},
|
646
|
+
type: ProductsIndex::Product,
|
647
|
+
types: [ProductsIndex::Product]
|
666
648
|
)
|
667
649
|
end
|
668
650
|
|
@@ -675,11 +657,44 @@ describe Chewy::Search::Request do
|
|
675
657
|
expect(outer_payload).to eq(
|
676
658
|
index: ProductsIndex,
|
677
659
|
indexes: [ProductsIndex],
|
678
|
-
request: {index: ['products'], type: %w[
|
679
|
-
type:
|
680
|
-
types: [ProductsIndex::Product
|
660
|
+
request: {index: ['products'], type: %w[product], body: {query: {match: {name: 'name3'}}}, refresh: false},
|
661
|
+
type: ProductsIndex::Product,
|
662
|
+
types: [ProductsIndex::Product]
|
681
663
|
)
|
682
664
|
end
|
683
665
|
end
|
666
|
+
|
667
|
+
describe '#response=' do
|
668
|
+
let(:query) { ProductsIndex.limit(0) }
|
669
|
+
let(:raw_response) { Chewy.client.search(query.render) }
|
670
|
+
|
671
|
+
it 'wraps and assigns the raw response' do
|
672
|
+
query.response = raw_response
|
673
|
+
expect(query.response).to be_a(Chewy::Search::Response)
|
674
|
+
end
|
675
|
+
end
|
676
|
+
|
677
|
+
describe '#performed?' do
|
678
|
+
let(:query) { ProductsIndex.limit(0) }
|
679
|
+
let(:raw_response) { Chewy.client.search(query.render) }
|
680
|
+
|
681
|
+
it 'is false on a new query' do
|
682
|
+
expect(query.performed?).to eq(false)
|
683
|
+
end
|
684
|
+
|
685
|
+
it 'is true after the search request was issued' do
|
686
|
+
expect do
|
687
|
+
# The `response` method has a side effect of performing unperformed
|
688
|
+
# queries.
|
689
|
+
query.response
|
690
|
+
end.to change(query, :performed?).from(false).to(true)
|
691
|
+
end
|
692
|
+
|
693
|
+
it 'is true after assigning a raw response' do
|
694
|
+
expect do
|
695
|
+
query.response = raw_response
|
696
|
+
end.to change(query, :performed?).from(false).to(true)
|
697
|
+
end
|
698
|
+
end
|
684
699
|
end
|
685
700
|
end
|