search_flip 4.0.0.beta2 → 4.0.0.beta3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be586199f9609b395d29218436d8618e283610189dde3805b76145f1c44b3c52
4
- data.tar.gz: 7312acda3dce1c1080cf9c6ee3ca10c3e6aab8556b152c9304c09af25aa61e12
3
+ metadata.gz: c93ffb5c3868ef14b27903734bfb2d77384acc4a52eb529070f8a17a82f323a3
4
+ data.tar.gz: 458f01664f5faf01006eddba2f59cdbcca7e10be22769aafca1084663c242a9b
5
5
  SHA512:
6
- metadata.gz: 813ff8f5a836e56db83cdf11b15c85003a849572df83401411770ceed0309aac7214ed7d1640b843c85e3b4a910a38db3b8c5b6af298e7d8cff950d23a36572e
7
- data.tar.gz: eb564e52771cf80668ae3bdfe145b533580ab04a3120fefdac75e6d661c4512c423606c80daa639940718f9c425d221c51d2e892e0cf184a634e3eead3cf8c06
6
+ metadata.gz: 341783040e3c705d6ac1cb7875dbbb0088efd22439057ced5f9a21c5629eb6f9b4ea7e8e4a23a0368e5ef7c249ad0e6a578a5f0f8a57afb2cb3b649b2db0a22e
7
+ data.tar.gz: fa40baa33a6626af128fdb14713300f55690ee407bec989b1f2bfca3e55a169377e2a0c5f9cefd6107a97ed7aceba290b52a382dcf5bdbf8c6c9389253896df7
data/.rubocop.yml CHANGED
@@ -5,6 +5,9 @@ AllCops:
5
5
  Style/CaseLikeIf:
6
6
  Enabled: false
7
7
 
8
+ Layout/EmptyLineBetweenDefs:
9
+ EmptyLineBetweenClassDefs: false
10
+
8
11
  Lint/EmptyBlock:
9
12
  Exclude:
10
13
  - spec/**/*.rb
data/CHANGELOG.md CHANGED
@@ -11,6 +11,11 @@
11
11
  * Added `SearchFlip::Connection#get_cluster_settings` and
12
12
  `#update_cluster_settings`
13
13
 
14
+ ## v3.2.0
15
+
16
+ * Fix `index_scope` not being passed in `each_record` without block
17
+ * Added `SearchFlip::Criteria#match_none`
18
+
14
19
  ## v3.1.2
15
20
 
16
21
  * Fix ignored false value for source when merging criterias
data/README.md CHANGED
@@ -418,6 +418,14 @@ Simply matches all documents:
418
418
  CommentIndex.match_all
419
419
  ```
420
420
 
421
+ * `match_none`
422
+
423
+ Simply matches none documents at all:
424
+
425
+ ```ruby
426
+ CommentIndex.match_none
427
+ ```
428
+
421
429
  * `all`
422
430
 
423
431
  Simply returns the criteria as is or an empty criteria when called on the index
@@ -925,6 +933,7 @@ require "search_flip/to_json"
925
933
 
926
934
  * for Elasticsearch 2.x, the delete-by-query plugin is required to delete
927
935
  records via queries
936
+ * `#match_none` is only available with Elasticsearch >= 5
928
937
  * `#track_total_hits` is only available with Elasticsearch >= 7
929
938
 
930
939
  ## Keeping your Models and Indices in Sync
@@ -235,6 +235,22 @@ module SearchFlip
235
235
  filter(match_all: options)
236
236
  end
237
237
 
238
+ # Adds a match none filter to the criteria, which simply matches none
239
+ # documents at all. Check out the Elasticsearch docs for further details.
240
+ #
241
+ # @example Basic usage
242
+ # CommentIndex.match_none
243
+ #
244
+ # @example Filter chaining
245
+ # query = CommentIndex.search("...")
246
+ # query = query.match_none unless current_user.admin?
247
+ #
248
+ # @return [SearchFlip::Criteria] A newly created extended criteria
249
+
250
+ def match_none
251
+ filter(match_none: {})
252
+ end
253
+
238
254
  # Adds an exists filter to the criteria, which selects all documents for
239
255
  # which the specified field has a non-null value.
240
256
  #
@@ -247,8 +247,8 @@ module SearchFlip
247
247
  SearchFlip::Criteria.new(target: self)
248
248
  end
249
249
 
250
- def_delegators :criteria, :all, :profile, :where, :where_not, :filter, :range, :match_all, :exists,
251
- :exists_not, :post_where, :post_where_not, :post_range, :post_exists, :post_exists_not,
250
+ def_delegators :criteria, :all, :profile, :where, :where_not, :filter, :range, :match_all, :match_none,
251
+ :exists, :exists_not, :post_where, :post_where_not, :post_range, :post_exists, :post_exists_not,
252
252
  :post_filter, :post_must, :post_must_not, :post_should, :aggregate, :scroll, :source,
253
253
  :includes, :eager_load, :preload, :sort, :resort, :order, :reorder, :offset, :limit, :paginate,
254
254
  :page, :per, :search, :highlight, :suggest, :custom, :find_in_batches, :find_results_in_batches,
@@ -34,14 +34,10 @@ module SearchFlip
34
34
  end
35
35
  end
36
36
 
37
- # rubocop:disable Style/MissingSuper
38
-
39
37
  def method_missing(name, *args, &block)
40
38
  self[name.to_s]
41
39
  end
42
40
 
43
- # rubocop:enable Style/MissingSuper
44
-
45
41
  def respond_to_missing?(name, include_private = false)
46
42
  key?(name.to_s) || super
47
43
  end
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "4.0.0.beta2"
2
+ VERSION = "4.0.0.beta3"
3
3
  end
@@ -416,6 +416,18 @@ RSpec.describe SearchFlip::Criteria do
416
416
  end
417
417
  end
418
418
 
419
+ describe "#match_none" do
420
+ it "does not match any documents" do
421
+ if ProductIndex.connection.version.to_i >= 5
422
+ ProductIndex.import create(:product)
423
+
424
+ query = ProductIndex.match_none
425
+
426
+ expect(query.records).to eq([])
427
+ end
428
+ end
429
+ end
430
+
419
431
  describe "#exists" do
420
432
  it "sets up the constraints correctly and is chainable" do
421
433
  product1 = create(:product, title: "title1", description: "description1")
@@ -5,8 +5,8 @@ RSpec.describe SearchFlip::Index do
5
5
  subject { ProductIndex }
6
6
 
7
7
  methods = [
8
- :all, :profile, :where, :where_not, :filter, :range, :match_all, :exists,
9
- :exists_not, :post_where, :post_where_not, :post_filter, :post_must,
8
+ :all, :profile, :where, :where_not, :filter, :range, :match_all, :match_none,
9
+ :exists, :exists_not, :post_where, :post_where_not, :post_filter, :post_must,
10
10
  :post_must_not, :post_should, :post_range, :post_exists, :post_exists_not,
11
11
  :aggregate, :scroll, :source, :includes, :eager_load, :preload, :sort, :resort,
12
12
  :order, :reorder, :offset, :limit, :paginate, :page, :per, :search,
@@ -211,12 +211,18 @@ RSpec.describe SearchFlip::Index do
211
211
  mapping = { properties: { id: { type: "long" } } }
212
212
 
213
213
  allow(TestIndex).to receive(:mapping).and_return(mapping)
214
- allow(TestIndex.connection).to receive(:update_mapping).and_call_original
214
+ allow(TestIndex.connection).to receive(:update_mapping)
215
215
 
216
216
  TestIndex.update_mapping
217
217
 
218
218
  expect(TestIndex.connection).to have_received(:update_mapping).with("test", { "test" => mapping }, type_name: "test")
219
219
  end
220
+
221
+ it "updates the mapping" do
222
+ TestIndex.create_index
223
+
224
+ expect(TestIndex.update_mapping).to eq(true)
225
+ end
220
226
  end
221
227
  end
222
228
 
@@ -258,12 +264,19 @@ RSpec.describe SearchFlip::Index do
258
264
  TestIndex.create_index
259
265
  TestIndex.update_mapping
260
266
 
261
- allow(TestIndex.connection).to receive(:get_mapping).and_call_original
267
+ allow(TestIndex.connection).to receive(:get_mapping)
262
268
 
263
269
  TestIndex.get_mapping
264
270
 
265
271
  expect(TestIndex.connection).to have_received(:get_mapping).with("test", type_name: "test")
266
272
  end
273
+
274
+ it "returns the mapping" do
275
+ TestIndex.create_index
276
+ TestIndex.update_mapping
277
+
278
+ expect(TestIndex.get_mapping).to be_present
279
+ end
267
280
  end
268
281
  end
269
282
 
@@ -7,7 +7,7 @@ RSpec.describe SearchFlip::NullInstrumenter do
7
7
  it "calls start" do
8
8
  allow(subject).to receive(:start)
9
9
 
10
- subject.instrument("name", { key: "value" }) {}
10
+ subject.instrument("name", { key: "value" }) { true }
11
11
 
12
12
  expect(subject).to have_received(:start)
13
13
  end
@@ -15,7 +15,7 @@ RSpec.describe SearchFlip::NullInstrumenter do
15
15
  it "calls finish" do
16
16
  allow(subject).to receive(:finish)
17
17
 
18
- subject.instrument("name", { key: "value" }) {}
18
+ subject.instrument("name", { key: "value" }) { true }
19
19
 
20
20
  expect(subject).to have_received(:finish)
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_flip
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta2
4
+ version: 4.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -274,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  - !ruby/object:Gem::Version
275
275
  version: 1.3.1
276
276
  requirements: []
277
- rubygems_version: 3.0.3
277
+ rubygems_version: 3.2.3
278
278
  signing_key:
279
279
  specification_version: 4
280
280
  summary: Full-Featured Elasticsearch Ruby Client with a Chainable DSL