redi_search 2.0.2 → 5.0.0

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +13 -11
  3. data/.github/workflows/tests.yml +19 -14
  4. data/.rubocop.yml +71 -5
  5. data/Appraisals +8 -4
  6. data/Gemfile +3 -2
  7. data/README.md +15 -33
  8. data/Rakefile +1 -0
  9. data/bin/console +6 -2
  10. data/gemfiles/{activerecord_51.gemfile → activerecord_60.gemfile} +4 -2
  11. data/gemfiles/{activerecord_52.gemfile → activerecord_61.gemfile} +4 -2
  12. data/gemfiles/activerecord_70.gemfile +15 -0
  13. data/lib/redi_search/add_field.rb +1 -1
  14. data/lib/redi_search/client/response.rb +1 -1
  15. data/lib/redi_search/client.rb +15 -5
  16. data/lib/redi_search/create.rb +2 -1
  17. data/lib/redi_search/document/display.rb +4 -4
  18. data/lib/redi_search/document/finder.rb +12 -50
  19. data/lib/redi_search/document.rb +11 -16
  20. data/lib/redi_search/hset.rb +28 -0
  21. data/lib/redi_search/index.rb +19 -17
  22. data/lib/redi_search/lazily_load.rb +2 -2
  23. data/lib/redi_search/log_subscriber.rb +7 -6
  24. data/lib/redi_search/model.rb +4 -10
  25. data/lib/redi_search/schema/field.rb +10 -2
  26. data/lib/redi_search/schema/geo_field.rb +1 -1
  27. data/lib/redi_search/schema/numeric_field.rb +1 -1
  28. data/lib/redi_search/schema/tag_field.rb +5 -1
  29. data/lib/redi_search/schema/text_field.rb +1 -1
  30. data/lib/redi_search/schema.rb +10 -5
  31. data/lib/redi_search/search/clauses/boolean.rb +4 -4
  32. data/lib/redi_search/search/clauses/or.rb +1 -1
  33. data/lib/redi_search/search/result.rb +2 -2
  34. data/lib/redi_search/search.rb +1 -1
  35. data/lib/redi_search/spellcheck/result.rb +4 -4
  36. data/lib/redi_search/spellcheck.rb +1 -1
  37. data/lib/redi_search/version.rb +1 -1
  38. data/redi_search.gemspec +3 -3
  39. metadata +15 -14
  40. data/lib/redi_search/add.rb +0 -67
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b7bc12a1d3a50de259ae10c27658e164d3ef84b65f0c4108c925138e53c1239
4
- data.tar.gz: 899ac067a70ee3f5d43c833a59aa32546ca4e18a57beaba3bccabc496ffff96a
3
+ metadata.gz: 140fad214c11689ac648949c29c17409c96164ca68e9c6cc5cb694b291aa685c
4
+ data.tar.gz: 7ba282b0a28eb08c5a8064d3d26afd6c1b97935991f55bd5b69ff50c5a3b7eec
5
5
  SHA512:
6
- metadata.gz: 131f1b1c9a4e2dad0740da6398a41a5ea01725e6e7dc02b9d604b252d3ad2612d3d23946fa1029e2d897c879b9b8c1c2951a73b1d7e4bca415d65998c0d8d0b8
7
- data.tar.gz: c1a6d747b27f77054c797feee442359306a36609fe1d8d8483467df93916ea4b2e7af7a1db5c3bd442aba04e54dad0131ac673dc6aa10ddba89b63ef48dbad37
6
+ metadata.gz: df96fa21f24f4fec24c66c64b447775a01eb9de86fbf5b30fd028a101363f8036e612d2a2d9b49ed4f09c6dcc14bbcbe7f9a9893be5dcc4dcec7aa4a75db9c95
7
+ data.tar.gz: 63c12659be3dc7fdfd790c5f4bab980e970ae5943273c2bda750ba0b43c0ddab50390cb718193130ee7658dd6b6384eed96881619ce49699bb7914c5687643fc
@@ -1,20 +1,22 @@
1
1
  name: lint
2
2
 
3
- on: [push]
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
4
8
 
5
9
  jobs:
6
10
  lint:
7
11
  runs-on: ubuntu-latest
8
12
  steps:
9
- - uses: actions/checkout@v1
10
- - name: Set up Ruby 2.7
11
- uses: actions/setup-ruby@v1
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 3.0
15
+ uses: ruby/setup-ruby@v1
12
16
  with:
13
- ruby-version: 2.7.x
14
- - name: Install dependencies
17
+ ruby-version: 3.0
18
+ - name: Install rubocop
15
19
  run: |
16
- sudo apt-get install libsqlite3-dev
17
- gem install bundler --no-document
18
- bundle install
19
- - name: Run tests
20
- run: bundle exec rubocop --config=./.rubocop.yml --parallel
20
+ gem install rubocop rubocop-performance rubocop-minitest rubocop-rake
21
+ - name: Lint
22
+ run: rubocop --config=./.rubocop.yml --parallel
@@ -1,20 +1,25 @@
1
1
  name: tests
2
2
 
3
- on: [push]
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
4
8
 
5
9
  jobs:
6
10
  unit:
7
11
  runs-on: ubuntu-latest
8
12
  strategy:
9
13
  matrix:
10
- ruby: [ '2.5.x', '2.6.x', '2.7.x' ]
11
- gemfile: [ 'Gemfile', 'gemfiles/activerecord_51.gemfile', 'gemfiles/activerecord_52.gemfile' ]
14
+ ruby: [ '2.7', '3.0' ]
15
+ gemfile: [ 'Gemfile', 'gemfiles/activerecord_60.gemfile', 'gemfiles/activerecord_61.gemfile', 'gemfiles/activerecord_70.gemfile' ]
12
16
  steps:
13
- - uses: actions/checkout@v1
17
+ - uses: actions/checkout@v2
14
18
  - name: Set up Ruby ${{ matrix.ruby }}
15
- uses: actions/setup-ruby@v1
19
+ uses: ruby/setup-ruby@v1
16
20
  with:
17
21
  ruby-version: ${{ matrix.ruby }}
22
+ bundler-cache: false
18
23
  - name: Install dependencies
19
24
  run: |
20
25
  sudo apt-get install libsqlite3-dev -y
@@ -24,21 +29,21 @@ jobs:
24
29
  run: BUNDLE_GEMFILE=${{ matrix.gemfile }} bundle exec rake test:unit
25
30
  integration:
26
31
  runs-on: ubuntu-latest
27
- strategy:
28
- matrix:
29
- redi_search: [ '1.4.28', '1.6.13', 'edge' ]
32
+ services:
33
+ redisearch:
34
+ image: redislabs/redisearch:2.0.12
35
+ ports:
36
+ - 6379:6379
30
37
  steps:
31
- - uses: actions/checkout@v1
32
- - name: Set up Ruby 2.7
33
- uses: actions/setup-ruby@v1
38
+ - uses: actions/checkout@v2
39
+ - name: Set up Ruby 3.0
40
+ uses: ruby/setup-ruby@v1
34
41
  with:
35
- ruby-version: 2.7.x
42
+ ruby-version: 3.0
36
43
  - name: Install dependencies
37
44
  run: |
38
45
  sudo apt-get install libsqlite3-dev -y
39
- gem install bundler --no-document
40
46
  bundle install
41
- docker run -d -p 6379:6379 redislabs/redisearch:${{ matrix.redi_search }} --protected-mode no --loadmodule /usr/lib/redis/modules/redisearch.so
42
47
  - name: Run tests
43
48
  run: |
44
49
  bundle exec rake test:integration
data/.rubocop.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  require:
2
+ - rubocop-minitest
2
3
  - rubocop-performance
4
+ - rubocop-rake
3
5
  AllCops:
6
+ NewCops: enable
4
7
  Exclude:
5
8
  - vendor/**/*
6
9
  - Gemfile.lock
@@ -9,7 +12,8 @@ AllCops:
9
12
  - tmp/**/*
10
13
  - test/dummy/db/schema.rb
11
14
  - gemfiles/**/*
12
- TargetRubyVersion: 2.5
15
+ - bin/**/*
16
+ TargetRubyVersion: 2.7
13
17
 
14
18
  # Department Bundler
15
19
  Bundler/DuplicatedGem:
@@ -611,7 +615,7 @@ Lint/UselessAssignment:
611
615
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars
612
616
  Enabled: true
613
617
 
614
- Lint/UselessComparison:
618
+ Lint/BinaryOperatorWithIdenticalOperands:
615
619
  Description: Checks for comparison of something with itself.
616
620
  Enabled: true
617
621
 
@@ -1197,9 +1201,6 @@ Style/MethodDefParentheses:
1197
1201
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#method-parens
1198
1202
  Enabled: true
1199
1203
 
1200
- Style/MethodMissingSuper:
1201
- Enabled: true
1202
-
1203
1204
  Style/MissingRespondToMissing:
1204
1205
  Enabled: true
1205
1206
 
@@ -1630,5 +1631,70 @@ Style/RedundantRegexpCharacterClass:
1630
1631
  Enabled: true
1631
1632
  Style/RedundantRegexpEscape:
1632
1633
  Enabled: true
1634
+ Lint/MissingSuper:
1635
+ Enabled: false
1636
+
1637
+
1638
+
1639
+ Lint/DuplicateElsifCondition:
1640
+ Enabled: true
1641
+ Lint/DuplicateRescueException:
1642
+ Enabled: true
1643
+ Lint/EmptyConditionalBody:
1644
+ Enabled: true
1645
+ Lint/FloatComparison:
1646
+ Enabled: true
1647
+ Lint/OutOfRangeRegexpRef:
1648
+ Enabled: true
1649
+ Lint/SelfAssignment:
1650
+ Enabled: true
1651
+ Lint/TopLevelReturnWithArgument:
1652
+ Enabled: true
1653
+ Lint/UnreachableLoop:
1654
+ Enabled: true
1655
+ Style/AccessorGrouping:
1656
+ Enabled: true
1657
+ Style/ArrayCoercion:
1658
+ Enabled: true
1659
+ Style/BisectedAttrAccessor:
1660
+ Enabled: true
1661
+ Style/CaseLikeIf:
1662
+ Enabled: true
1663
+ Style/ExplicitBlockArgument:
1664
+ Enabled: false
1665
+ Style/GlobalStdStream:
1666
+ Enabled: true
1667
+ Style/HashAsLastArrayItem:
1668
+ Enabled: false
1669
+ Style/HashLikeCase:
1670
+ Enabled: true
1671
+ Style/OptionalBooleanParameter:
1672
+ Enabled: true
1673
+ Style/RedundantAssignment:
1674
+ Enabled: true
1633
1675
  Style/RedundantFetchBlock:
1634
1676
  Enabled: true
1677
+ Style/RedundantFileExtensionInRequire:
1678
+ Enabled: true
1679
+ Style/SingleArgumentDig:
1680
+ Enabled: true
1681
+ Style/StringConcatenation:
1682
+ Enabled: true
1683
+ Performance/AncestorsInclude:
1684
+ Enabled: true
1685
+ Performance/BigDecimalWithNumericArgument:
1686
+ Enabled: true
1687
+ Performance/RedundantSortBlock:
1688
+ Enabled: true
1689
+ Performance/RedundantStringChars:
1690
+ Enabled: true
1691
+ Performance/ReverseFirst:
1692
+ Enabled: true
1693
+ Performance/SortReverse:
1694
+ Enabled: true
1695
+ Performance/Squeeze:
1696
+ Enabled: true
1697
+ Performance/StringInclude:
1698
+ Enabled: true
1699
+ Minitest/AssertionInLifecycleHook:
1700
+ Enabled: false
data/Appraisals CHANGED
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "activerecord-52" do
4
- gem "activerecord", "< 6.0", ">= 5.2"
3
+ appraise "activerecord-60" do
4
+ gem "activerecord", "< 6.1", ">= 6.0"
5
5
  end
6
6
 
7
- appraise "activerecord-51" do
8
- gem "activerecord", "< 5.2", ">= 5.1"
7
+ appraise "activerecord-61" do
8
+ gem "activerecord", "< 6.2", ">= 6.1"
9
+ end
10
+
11
+ appraise "activerecord-70" do
12
+ gem "activerecord", "~> 7.0.0.alpha1"
9
13
  end
data/Gemfile CHANGED
@@ -9,10 +9,11 @@ gemspec
9
9
  gem "appraisal", "~> 2.2"
10
10
  gem "faker"
11
11
  gem "mocha"
12
- gem "pry"
13
12
  gem "rubocop"
13
+ gem "rubocop-minitest"
14
14
  gem "rubocop-performance"
15
+ gem "rubocop-rake"
15
16
  gem "simplecov"
16
17
  gem "sqlite3"
17
18
 
18
- gem "activerecord", "~> 6.0.0"
19
+ gem "activerecord", "~> 6.1"
data/README.md CHANGED
@@ -7,7 +7,6 @@
7
7
  # RediSearch
8
8
 
9
9
  ![Build Status](https://github.com/npezza93/redi_search/workflows/tests/badge.svg)
10
- [![Test Coverage](https://api.codeclimate.com/v1/badges/c6437acac5684de2549d/test_coverage)](https://codeclimate.com/github/npezza93/redi_search/test_coverage)
11
10
  [![Maintainability](https://api.codeclimate.com/v1/badges/c6437acac5684de2549d/maintainability)](https://codeclimate.com/github/npezza93/redi_search/maintainability)
12
11
 
13
12
  A simple, but powerful, Ruby wrapper around RediSearch, a search engine on top of
@@ -244,13 +243,11 @@ With no options: `{ place: :geo }`
244
243
 
245
244
  ## Document
246
245
 
247
- A `Document` is the Ruby representation of a RediSearch document.
246
+ A `Document` is the Ruby representation of a Redis hash.
248
247
 
249
- You can fetch a `Document` using `.get` or `.mget` class methods.
248
+ You can fetch a `Document` using `.get` class methods.
250
249
  - `get(index, document_id)` fetches a single `Document` in an `Index` for a
251
250
  given `document_id`.
252
- - `mget(index, *document_ids)` fetches a collection of `Document`s
253
- in an `Index` for the given `document_ids`.
254
251
 
255
252
  You can also make a `Document` instance using the
256
253
  `.for_object(index, record, serializer: nil, only: [])` class method. It takes
@@ -269,10 +266,7 @@ to override each other. There is also a `#document_id_without_index` method
269
266
  which removes the prepended index name.
270
267
 
271
268
  Finally there is a `#del` method that will remove the `Document` from the
272
- `Index`. It optionally accepts a `delete_document` named argument that signifies
273
- whether the `Document` should be completely removed from the Redis instance vs
274
- just the `Index`.
275
-
269
+ `Index`.
276
270
 
277
271
  ## Index
278
272
 
@@ -314,42 +308,32 @@ RediSearch::Index.new(name_of_index, schema)
314
308
  - If set, we avoid saving the term frequencies in the index. This saves
315
309
  memory but does not allow sorting based on the frequencies of a given
316
310
  term within the document.
317
- - `drop`
311
+ - `drop(keep_docs: false)`
318
312
  - Drops the `Index` from the Redis instance, returns a boolean. Has an
319
313
  accompanying bang method that will raise an exception upon failure. Will
320
- return `false` if the `Index` has already been dropped.
314
+ return `false` if the `Index` has already been dropped. Takes an option
315
+ keyword arg, `keep_docs`, that will by default remove all the document
316
+ hashes in Redis.
321
317
  - `exist?`
322
318
  - Returns a boolean signifying `Index` existence.
323
319
  - `info`
324
320
  - Returns a struct object with all the information about the `Index`.
325
321
  - `fields`
326
322
  - Returns an array of the field names in the `Index`.
327
- - `add(document, score: 1.0, replace: {}, language: nil, no_save: false)`
328
- - Takes a `Document` object and options. Has an
323
+ - `add(document)`
324
+ - Takes a `Document` object. Has an
329
325
  accompanying bang method that will raise an exception upon failure.
330
- - `score` -> The `Document`'s rank, a value between 0.0 and 1.0
331
- - `language` -> Use a stemmer for the supplied language during indexing.
332
- - `no_save` -> Don't save the actual `Document` in the database and only index it.
333
- - `replace` -> Accepts a boolean or a hash. If a truthy value is passed, we
334
- will do an UPSERT style insertion - and delete an older version of the
335
- `Document` if it exists.
336
- - `replace: { partial: true }` -> Allows you to not have to specify all
337
- fields for reindexing. Fields not given to the command will be loaded from
338
- the current version of the `Document`.
339
- - `add_multiple(documents, score: 1.0, replace: {}, language: nil, no_save: false)`
326
+ - `add_multiple(documents)`
340
327
  - Takes an array of `Document` objects. This provides a more performant way to
341
328
  add multiple documents to the `Index`. Accepts the same options as `add`.
342
- - `del(document, delete_document: false)`
343
- - Removes a `Document` from the `Index`. `delete_document` signifies whether the
344
- `Document` should be completely removed from the Redis instance vs just the
345
- `Index`.
329
+ - `del(document)`
330
+ - Removes a `Document` from the `Index`.
346
331
  - `document_count`
347
332
  - Returns the number of `Document`s in the `Index`
348
333
  - `add_field(field_name, schema)`
349
334
  - Adds a new field to the `Index`. Ex: `index.add_field(:first_name, text: { phonetic: "dm:en" })`
350
- - `reindex(documents, recreate: false, **options)`
335
+ - `reindex(documents, recreate: false)`
351
336
  - If `recreate` is `true` the `Index` will be dropped and recreated
352
- - `options` accepts the same options as `add`
353
337
 
354
338
 
355
339
  ## Searching
@@ -521,11 +505,9 @@ end
521
505
  This will automatically add `User.search` and `User.spellcheck`
522
506
  methods which behave the same as if you called them on an `Index` instance.
523
507
 
524
- `User.reindex(recreate: false, only: [], **options)` is also added and behaves
508
+ `User.reindex(recreate: false, only: [])` is also added and behaves
525
509
  similarly to `RediSearch::Index#reindex`. Some of the differences include:
526
- - By default, does an upsert for all `Document`s added using the
527
- option `replace: { partial: true }`.
528
- - `Document`s do not to be passed as the first parameter. The `search_import`
510
+ - `Document`s do not need to be passed as the first parameter. The `search_import`
529
511
  scope is automatically called and all the records are converted
530
512
  to `Document`s.
531
513
  - Accepts an optional `only` parameter where you can specify a limited number
data/Rakefile CHANGED
@@ -20,5 +20,6 @@ Rake::TestTask.new("test:integration") do |t|
20
20
  t.test_files = FileList["test/integration/**/*_test.rb"]
21
21
  end
22
22
 
23
+ desc "run all tests"
23
24
  task test: [:default]
24
25
  task default: ["test:integration", "test:unit", :rubocop]
data/bin/console CHANGED
@@ -5,7 +5,7 @@ require "bundler/setup"
5
5
  require "redi_search"
6
6
 
7
7
  require "faker"
8
- require "pry"
8
+ require "irb"
9
9
  require "active_support/logger"
10
10
  require "active_record"
11
11
 
@@ -34,4 +34,8 @@ def seed_users(count = 10_000)
34
34
  User.reindex
35
35
  end
36
36
 
37
- Pry.start
37
+ def reload!
38
+ exec($0)
39
+ end
40
+
41
+ IRB.start
@@ -2,12 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "appraisal", "~> 2.2"
6
+ gem "faker"
5
7
  gem "mocha"
6
- gem "pry"
7
8
  gem "rubocop"
9
+ gem "rubocop-minitest"
8
10
  gem "rubocop-performance"
9
11
  gem "simplecov"
10
12
  gem "sqlite3"
11
- gem "activerecord", "< 5.2", ">= 5.1"
13
+ gem "activerecord", "< 6.1", ">= 6.0"
12
14
 
13
15
  gemspec path: "../"
@@ -2,12 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "appraisal", "~> 2.2"
6
+ gem "faker"
5
7
  gem "mocha"
6
- gem "pry"
7
8
  gem "rubocop"
9
+ gem "rubocop-minitest"
8
10
  gem "rubocop-performance"
9
11
  gem "simplecov"
10
12
  gem "sqlite3"
11
- gem "activerecord", "< 6.0", ">= 5.2"
13
+ gem "activerecord", "< 6.2", ">= 6.1"
12
14
 
13
15
  gemspec path: "../"
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 2.2"
6
+ gem "faker"
7
+ gem "mocha"
8
+ gem "rubocop"
9
+ gem "rubocop-minitest"
10
+ gem "rubocop-performance"
11
+ gem "simplecov"
12
+ gem "sqlite3"
13
+ gem "activerecord", "~> 7.0.0.alpha1"
14
+
15
+ gemspec path: "../"
@@ -29,7 +29,7 @@ module RediSearch
29
29
  end
30
30
 
31
31
  def field_schema
32
- @field_schema ||= Schema.make_field(field_name, raw_schema)
32
+ @field_schema ||= Schema.make_field(field_name, raw_schema).to_a
33
33
  end
34
34
  end
35
35
  end
@@ -6,7 +6,7 @@ module RediSearch
6
6
  def ok?
7
7
  case response
8
8
  when String then response == "OK"
9
- when Integer then response == 1
9
+ when Integer then response >= 1
10
10
  when Array then array_ok?
11
11
  else response
12
12
  end