search_flip 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51aeb6ec190e4ee6ff8d291d46e038e55bec7eb2b09cfc5eb410b9f523b75f8a
4
- data.tar.gz: 89882033f77adf5c29104ae35e5c0ee2fd4d4222111ba98ad76cfb508a92da8d
3
+ metadata.gz: 2a1c972daa52dd27bff5ba1d5393f261f63d822df616e1c9c5c1a362ebf7ba6b
4
+ data.tar.gz: 175036020a5b0e6b21aad2b1c6a8a3eb4f26ac65cc48b250455c8dd952c1d72e
5
5
  SHA512:
6
- metadata.gz: 5fd5f110807947f0a1bc9906ced03be0c20a1c79a792321cd472d24b0c50a68e6ed88927f1db087ce64f45fd1544d85a5b434b25365f90f2ef83f9d06a8cb6db
7
- data.tar.gz: cf8e8c77ec27b895249d39e8498207f4a4484776d9f3aefb79f163f5c9e262c80516e4ff99573e833f83ad1de96659a1b2707c1ae7d2786bd72d5d59631ba00b
6
+ metadata.gz: f12ca12f6fd01ab6bd5a6bc81d5a1d520c9fa1feb08157c6fd0abfece940f8307daa7c2eda5fd62bdae36e8be07b3e71b8fa3a515322eb68803721ff65021826
7
+ data.tar.gz: 472b96a7c30a61ad68d48faa01b785831103594e55095b78bf66ee6041b1551dbda239177b1ac41370d7c76e1a9286eb95b6c4c46a10705f4722c44e9af5ee16
@@ -0,0 +1,34 @@
1
+ on: push
2
+ name: test
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ elasticsearch:
10
+ - plainpicture/elasticsearch:2.4.1_delete-by-query
11
+ - elasticsearch:5.4
12
+ - docker.elastic.co/elasticsearch/elasticsearch:6.7.0
13
+ - docker.elastic.co/elasticsearch/elasticsearch:7.0.0
14
+ - docker.elastic.co/elasticsearch/elasticsearch:7.9.0
15
+ ruby:
16
+ - 2.5
17
+ - 2.6
18
+ - 2.7
19
+ services:
20
+ elasticsearch:
21
+ image: ${{ matrix.elasticsearch }}
22
+ env:
23
+ discovery.type: single-node
24
+ ports:
25
+ - 9200:9200
26
+ steps:
27
+ - uses: actions/checkout@v1
28
+ - uses: actions/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ - run: bundle
32
+ - run: sleep 10
33
+ - run: bundle exec rspec
34
+ - run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -2,6 +2,9 @@ AllCops:
2
2
  NewCops: enable
3
3
  TargetRubyVersion: 2.4
4
4
 
5
+ Layout/EmptyLineBetweenDefs:
6
+ EmptyLineBetweenClassDefs: false
7
+
5
8
  Gemspec/RequiredRubyVersion:
6
9
  Enabled: false
7
10
 
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
 
2
2
  # CHANGELOG
3
3
 
4
+ ## v3.2.0
5
+
6
+ * Fix `index_scope` not being passed in `each_record` without block
7
+ * Added `SearchFlip::Criteria#match_none`
8
+
4
9
  ## v3.1.2
5
10
 
6
11
  * Fix ignored false value for source when merging criterias
data/README.md CHANGED
@@ -419,6 +419,14 @@ Simply matches all documents:
419
419
  CommentIndex.match_all
420
420
  ```
421
421
 
422
+ * `match_none`
423
+
424
+ Simply matches none documents at all:
425
+
426
+ ```ruby
427
+ CommentIndex.match_none
428
+ ```
429
+
422
430
  * `all`
423
431
 
424
432
  Simply returns the criteria as is or an empty criteria when called on the index
@@ -926,6 +934,7 @@ require "search_flip/to_json"
926
934
 
927
935
  * for Elasticsearch 2.x, the delete-by-query plugin is required to delete
928
936
  records via queries
937
+ * `#match_none` is only available with Elasticsearch >= 5
929
938
  * `#track_total_hits` is only available with Elasticsearch >= 7
930
939
 
931
940
  ## 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
  #
@@ -153,7 +153,7 @@ module SearchFlip
153
153
  # scope to be applied to the scope
154
154
 
155
155
  def each_record(scope, index_scope: false)
156
- return enum_for(:each_record, scope) unless block_given?
156
+ return enum_for(:each_record, scope, index_scope: index_scope) unless block_given?
157
157
 
158
158
  if scope.respond_to?(:find_each)
159
159
  (index_scope ? self.index_scope(scope) : scope).find_each do |record|
@@ -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,
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "3.1.2"
2
+ VERSION = "3.2.0"
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: 3.1.2
4
+ version: 3.2.0
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-10-02 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
@@ -213,9 +213,9 @@ executables: []
213
213
  extensions: []
214
214
  extra_rdoc_files: []
215
215
  files:
216
+ - ".github/workflows/test.yml"
216
217
  - ".gitignore"
217
218
  - ".rubocop.yml"
218
- - ".travis.yml"
219
219
  - CHANGELOG.md
220
220
  - Gemfile
221
221
  - LICENSE.txt
@@ -287,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
287
  - !ruby/object:Gem::Version
288
288
  version: '0'
289
289
  requirements: []
290
- rubygems_version: 3.0.3
290
+ rubygems_version: 3.2.3
291
291
  signing_key:
292
292
  specification_version: 4
293
293
  summary: Full-Featured Elasticsearch Ruby Client with a Chainable DSL
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- env:
4
- - ES_IMAGE=plainpicture/elasticsearch:2.4.1_delete-by-query
5
- - ES_IMAGE=elasticsearch:5.4
6
- - ES_IMAGE=docker.elastic.co/elasticsearch/elasticsearch:6.7.0
7
- - ES_IMAGE=docker.elastic.co/elasticsearch/elasticsearch:7.0.0
8
- - ES_IMAGE=docker.elastic.co/elasticsearch/elasticsearch:7.9.0
9
- rvm:
10
- - ruby-2.5.3
11
- - ruby-2.6.2
12
- - ruby-2.7.1
13
- before_install:
14
- - docker-compose up -d
15
- - sleep 10
16
- install:
17
- - travis_retry bundle install
18
- script:
19
- - bundle exec rspec
20
- - bundle exec rubocop