redi_search 1.0.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -156
  3. data/.travis.yml +47 -15
  4. data/Appraisals +4 -8
  5. data/Gemfile +3 -4
  6. data/README.md +74 -73
  7. data/Rakefile +15 -3
  8. data/bin/console +36 -0
  9. data/gemfiles/{rails_6.gemfile → activerecord_51.gemfile} +1 -5
  10. data/gemfiles/{rails_51.gemfile → activerecord_52.gemfile} +1 -5
  11. data/lib/redi_search.rb +6 -7
  12. data/lib/redi_search/add.rb +9 -5
  13. data/lib/redi_search/{alter.rb → add_field.rb} +13 -5
  14. data/lib/redi_search/client.rb +8 -6
  15. data/lib/redi_search/client/response.rb +4 -0
  16. data/lib/redi_search/configuration.rb +1 -11
  17. data/lib/redi_search/create.rb +6 -4
  18. data/lib/redi_search/document.rb +5 -4
  19. data/lib/redi_search/document/display.rb +9 -9
  20. data/lib/redi_search/document/finder.rb +10 -2
  21. data/lib/redi_search/index.rb +9 -9
  22. data/lib/redi_search/lazily_load.rb +6 -11
  23. data/lib/redi_search/log_subscriber.rb +23 -52
  24. data/lib/redi_search/model.rb +43 -39
  25. data/lib/redi_search/schema.rb +3 -3
  26. data/lib/redi_search/schema/tag_field.rb +1 -1
  27. data/lib/redi_search/schema/text_field.rb +1 -1
  28. data/lib/redi_search/search.rb +12 -25
  29. data/lib/redi_search/search/clauses.rb +6 -7
  30. data/lib/redi_search/search/clauses/application_clause.rb +20 -5
  31. data/lib/redi_search/search/clauses/boolean.rb +5 -5
  32. data/lib/redi_search/search/clauses/highlight.rb +18 -2
  33. data/lib/redi_search/search/clauses/limit.rb +7 -5
  34. data/lib/redi_search/search/clauses/return.rb +1 -1
  35. data/lib/redi_search/search/clauses/slop.rb +1 -1
  36. data/lib/redi_search/search/clauses/sort_by.rb +1 -1
  37. data/lib/redi_search/search/clauses/where.rb +10 -2
  38. data/lib/redi_search/search/result.rb +9 -9
  39. data/lib/redi_search/search/term.rb +7 -6
  40. data/lib/redi_search/spellcheck.rb +3 -4
  41. data/lib/redi_search/spellcheck/result.rb +1 -1
  42. data/lib/redi_search/validatable.rb +49 -0
  43. data/lib/redi_search/validations/inclusion.rb +26 -0
  44. data/lib/redi_search/validations/numericality.rb +45 -0
  45. data/lib/redi_search/validations/presence.rb +29 -0
  46. data/lib/redi_search/version.rb +1 -1
  47. data/redi_search.gemspec +0 -2
  48. metadata +9 -41
  49. data/bin/test +0 -7
  50. data/gemfiles/rails_52.gemfile +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79588edd4be4e064382eae3f180e5f0448088fef9d5e0759b80dd413e2067dad
4
- data.tar.gz: fcfb7f850fa181ac8404b7d3ff3d69a5f064c49c6fc359453782265c00fb7ab9
3
+ metadata.gz: dcdb3e3aebb8594a2cb2f927576bc7aba11a0a8df65bc0cbbbc180a73c77abd0
4
+ data.tar.gz: ec7beac2eb361645edefae2f6ae2606dc464c9867044a6995fddf17f3c72238f
5
5
  SHA512:
6
- metadata.gz: a7c367a8419bbcf861f7faf4be8d795e93b1e544617803f5e3a59bde73afb07b53f32a170829748a713d5b7aadabeac62a63dc1c04804fc8b0500feb71e55b19
7
- data.tar.gz: b1fb48fd95bce904fad5f710f0af6f6997bfa5b7e3fd83275fb387e97153abb5c38cae4218c626605ff75c5454a535c2a04e4b75807e2c8e249215dd3673b3b1
6
+ metadata.gz: 44ee5394b472b68d3a07871ccd43512a671edf90a915359d1df168fee72f5c8300d6b2fbcfd4c8dc5c37f099d18bc4c86df5ad40218d79138b2a13494d160c9f
7
+ data.tar.gz: c5ab674e0e0dea86814c4350ae0227ca105d4eacada549d084f150799f692ce8874008e47f7a2ed8035d22852f04efc20bac18c476c2bacbe52afc977cae7474
data/.rubocop.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  require:
2
2
  - rubocop-performance
3
- - rubocop-rails
4
3
  AllCops:
5
4
  Exclude:
6
5
  - vendor/**/*
@@ -873,161 +872,6 @@ Performance/UriDefaultParser:
873
872
  Description: Use `URI::DEFAULT_PARSER` instead of `URI::Parser.new`.
874
873
  Enabled: true
875
874
 
876
- # Department Rails
877
- Rails/ActionFilter:
878
- Description: Enforces consistent use of action filter methods.
879
- Enabled: false
880
-
881
- Rails/ApplicationJob:
882
- Description: Check that jobs subclass ApplicationJob.
883
- Enabled: true
884
-
885
- Rails/ApplicationRecord:
886
- Description: Check that models subclass ApplicationRecord.
887
- Enabled: true
888
-
889
- Rails/ActiveSupportAliases:
890
- Description: 'Avoid ActiveSupport aliases of standard ruby methods: `String#starts_with?`, `String#ends_with?`, `Array#append`, `Array#prepend`.'
891
- Enabled: true
892
-
893
- Rails/Blank:
894
- Description: Enforce using `blank?` and `present?`.
895
- Enabled: true
896
- NilOrEmpty: true
897
- NotPresent: true
898
- UnlessPresent: true
899
-
900
- Rails/Date:
901
- Description: Checks the correct usage of date aware methods, such as Date.today, Date.current etc.
902
- Enabled: true
903
-
904
- Rails/Delegate:
905
- Description: Prefer delegate method for delegations.
906
- Enabled: true
907
-
908
- Rails/DelegateAllowBlank:
909
- Description: Do not use allow_blank as an option to delegate.
910
- Enabled: true
911
-
912
- Rails/DynamicFindBy:
913
- Description: Use `find_by` instead of dynamic `find_by_*`.
914
- StyleGuide: https://github.com/bbatsov/rails-style-guide#find_by
915
- Enabled: true
916
-
917
- Rails/EnumUniqueness:
918
- Description: Avoid duplicate integers in hash-syntax `enum` declaration.
919
- Enabled: true
920
-
921
- Rails/Exit:
922
- Description: Favor `fail`, `break`, `return`, etc. over `exit` in application or library code outside of Rake files to avoid exits during unit testing or running in production.
923
- Enabled: true
924
-
925
- Rails/FilePath:
926
- Description: Use `Rails.root.join` for file path joining.
927
- Enabled: true
928
-
929
- Rails/FindBy:
930
- Description: Prefer find_by over where.first.
931
- StyleGuide: https://github.com/bbatsov/rails-style-guide#find_by
932
- Enabled: true
933
-
934
- Rails/FindEach:
935
- Description: Prefer all.find_each over all.find.
936
- StyleGuide: https://github.com/bbatsov/rails-style-guide#find-each
937
- Enabled: true
938
-
939
- Rails/HasAndBelongsToMany:
940
- Description: Prefer has_many :through to has_and_belongs_to_many.
941
- StyleGuide: https://github.com/bbatsov/rails-style-guide#has-many-through
942
- Enabled: true
943
-
944
- Rails/HasManyOrHasOneDependent:
945
- Description: Define the dependent option to the has_many and has_one associations.
946
- StyleGuide: https://github.com/bbatsov/rails-style-guide#has_many-has_one-dependent-option
947
- Enabled: true
948
-
949
- Rails/HttpPositionalArguments:
950
- Description: Use keyword arguments instead of positional arguments in http method calls.
951
- Enabled: true
952
-
953
- Rails/NotNullColumn:
954
- Description: Do not add a NOT NULL column without a default value
955
- Enabled: true
956
-
957
- Rails/Output:
958
- Description: Checks for calls to puts, print, etc.
959
- Enabled: true
960
-
961
- Rails/OutputSafety:
962
- Description: The use of `html_safe` or `raw` may be a security risk.
963
- Enabled: true
964
-
965
- Rails/PluralizationGrammar:
966
- Description: Checks for incorrect grammar when using methods like `3.day.ago`.
967
- Enabled: true
968
-
969
- Rails/Present:
970
- Description: Enforce using `blank?` and `present?`.
971
- Enabled: true
972
- NotNilAndNotEmpty: true
973
- NotBlank: true
974
- UnlessBlank: true
975
-
976
- Rails/ReadWriteAttribute:
977
- Description: Checks for read_attribute(:attr) and write_attribute(:attr, val).
978
- StyleGuide: https://github.com/bbatsov/rails-style-guide#read-attribute
979
- Enabled: false
980
-
981
- Rails/RelativeDateConstant:
982
- Description: Do not assign relative date to constants.
983
- Enabled: true
984
-
985
- Rails/RequestReferer:
986
- Description: Use consistent syntax for request.referer.
987
- Enabled: true
988
-
989
- Rails/ReversibleMigration:
990
- Description: Checks whether the change method of the migration file is reversible.
991
- StyleGuide: https://github.com/bbatsov/rails-style-guide#reversible-migration
992
- Reference: http://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html
993
- Enabled: true
994
-
995
- Rails/SafeNavigation:
996
- Description: Use Ruby's safe navigation operator (`&.`) instead of `try!`
997
- Enabled: true
998
-
999
- Rails/SaveBang:
1000
- Description: Identifies possible cases where Active Record save! or related should be used.
1001
- StyleGuide: https://github.com/bbatsov/rails-style-guide#save-bang
1002
- Enabled: false
1003
-
1004
- Rails/ScopeArgs:
1005
- Description: Checks the arguments of ActiveRecord scopes.
1006
- Enabled: true
1007
-
1008
- Rails/TimeZone:
1009
- Description: Checks the correct usage of time zone aware methods.
1010
- StyleGuide: https://github.com/bbatsov/rails-style-guide#time
1011
- Reference: http://danilenko.org/2012/7/6/rails_timezones
1012
- Enabled: true
1013
-
1014
- Rails/UniqBeforePluck:
1015
- Description: Prefer the use of uniq or distinct before pluck.
1016
- Enabled: true
1017
-
1018
- Rails/UnknownEnv:
1019
- Description: Use correct environment name.
1020
- Enabled: true
1021
-
1022
- Rails/SkipsModelValidations:
1023
- Description: Use methods that skips model validations with caution. See reference for more information.
1024
- Reference: http://guides.rubyonrails.org/active_record_validations.html#skipping-validations
1025
- Enabled: true
1026
-
1027
- Rails/Validation:
1028
- Description: Use validates :attribute, hash of validations.
1029
- Enabled: true
1030
-
1031
875
  # Department Security
1032
876
  Security/Eval:
1033
877
  Description: The use of eval represents a serious security risk.
data/.travis.yml CHANGED
@@ -9,23 +9,55 @@ cache:
9
9
  - gemfiles/vendor/bundle
10
10
  - /home/travis/.rvm/
11
11
  services: docker
12
- before_script:
13
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
- - chmod +x ./cc-test-reporter
15
- - ./cc-test-reporter before-build
16
- before_install:
17
- - docker run -d -p 6379:6379 redislabs/redisearch:latest --protected-mode no --loadmodule /usr/lib/redis/modules/redisearch.so
18
- after_script:
19
- - if [[ "$TRAVIS_TEST_RESULT" == 0 ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
20
- rvm:
21
- - 2.6
22
- - 2.5
23
- gemfile:
24
- - gemfiles/rails_6.gemfile
25
- - gemfiles/rails_52.gemfile
26
- - gemfiles/rails_51.gemfile
27
12
  jobs:
28
13
  include:
14
+ - stage: Integration Tests
15
+ script: |
16
+ docker run -d -p 6379:6379 redislabs/redisearch:1.4.12 --protected-mode no --loadmodule /usr/lib/redis/modules/redisearch.so
17
+ bundle exec rake test:integration
18
+ rvm: 2.6
19
+ gemfile: Gemfile
20
+ name: RediSearch 1.4.12
21
+ - stage: Integration Tests
22
+ script: |
23
+ docker run -d -p 6379:6379 redislabs/redisearch:1.4.11 --protected-mode no --loadmodule /usr/lib/redis/modules/redisearch.so
24
+ bundle exec rake test:integration
25
+ rvm: 2.6
26
+ gemfile: Gemfile
27
+ name: RediSearch 1.4.11
28
+ - stage: Integration Tests
29
+ script: |
30
+ docker run -d -p 6379:6379 redislabs/redisearch:1.4.10 --protected-mode no --loadmodule /usr/lib/redis/modules/redisearch.so
31
+ bundle exec rake test:integration
32
+ rvm: 2.6
33
+ gemfile: Gemfile
34
+ name: RediSearch 1.4.10
35
+ - stage: Unit Tests
36
+ script: |
37
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
38
+ chmod +x ./cc-test-reporter
39
+ ./cc-test-reporter before-build
40
+ bundle exec rake test:unit
41
+ if [[ "$TRAVIS_TEST_RESULT" == 0 ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
42
+ rvm: 2.6
43
+ gemfile: Gemfile
44
+ name: Ruby 2.6 and Rails 6.0rc2
45
+ - stage: Unit Tests
46
+ script: bundle exec rake test:unit
47
+ rvm: 2.6
48
+ gemfile: gemfiles/activerecord_52.gemfile
49
+ name: Ruby 2.6 and Rails 5.2
50
+ - stage: Unit Tests
51
+ script: bundle exec rake test:unit
52
+ rvm: 2.6
53
+ gemfile: gemfiles/activerecord_51.gemfile
54
+ name: Ruby 2.6 and Rails 5.1
55
+ - stage: Unit Tests
56
+ script: bundle exec rake test:unit
57
+ rvm: 2.5
58
+ gemfile: Gemfile
59
+ name: Ruby 2.5 and Rails 6.0rc2
29
60
  - stage: Lint
30
61
  script: bundle exec rubocop --config=./.rubocop.yml
31
62
  rvm: 2.6
63
+ name: Rubocop
data/Appraisals CHANGED
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "rails-6" do
4
- gem "rails", "6.0.0.rc1"
3
+ appraise "activerecord-52" do
4
+ gem "activerecord", "< 6.0", ">= 5.2"
5
5
  end
6
6
 
7
- appraise "rails-52" do
8
- gem "rails", "< 6.0", ">= 5.2"
9
- end
10
-
11
- appraise "rails-51" do
12
- gem "rails", "< 5.2", ">= 5.1"
7
+ appraise "activerecord-51" do
8
+ gem "activerecord", "< 5.2", ">= 5.1"
13
9
  end
data/Gemfile CHANGED
@@ -2,18 +2,17 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  gemspec
8
8
 
9
+ gem "appraisal", "~> 2.2"
9
10
  gem "faker"
10
11
  gem "mocha"
11
12
  gem "pry"
12
- gem "pry-rails"
13
13
  gem "rubocop"
14
14
  gem "rubocop-performance"
15
- gem "rubocop-rails"
16
15
  gem "simplecov"
17
16
  gem "sqlite3"
18
17
 
19
- gem "rails", "6.0.0.rc1"
18
+ gem "activerecord", "6.0.0.rc2"
data/README.md CHANGED
@@ -24,11 +24,13 @@ macOS or Linux you can install via Homebrew.
24
24
 
25
25
  To install RediSearch check out,
26
26
  [https://oss.redislabs.com/redisearch/Quick_Start.html](https://oss.redislabs.com/redisearch/Quick_Start.html).
27
- Once you have RediSearch built, you can update your redis.conf file to always
28
- load the redisearch module with `loadmodule /path/to/redisearch.so`. (On macOS
29
- the redis.conf file can be found `/usr/local/etc/redis.conf`)
27
+ Once you have RediSearch built, if you are not using Docker, you can update your
28
+ redis.conf file to always load the RediSearch module with
29
+ `loadmodule /path/to/redisearch.so`. (On macOS the redis.conf file can be found
30
+ at `/usr/local/etc/redis.conf`)
30
31
 
31
- After Redis and RediSearch are up and running, add this line to your Gemfile:
32
+ After Redis and RediSearch are up and running, add the following line to your
33
+ Gemfile:
32
34
 
33
35
  ```ruby
34
36
  gem 'redi_search'
@@ -51,7 +53,7 @@ require 'redi_search'
51
53
 
52
54
  Once the gem is installed and required you'll need to configure it with your
53
55
  Redis configuration. If you're on Rails, this should go in an initializer
54
- (`config/initializers/redi_search.rb`)
56
+ (`config/initializers/redi_search.rb`).
55
57
 
56
58
  ```ruby
57
59
  RediSearch.configure do |config|
@@ -74,7 +76,7 @@ end
74
76
 
75
77
  ## Preface
76
78
  RediSearch revolves around a search index, so lets start with
77
- defining what a search index is. According to [Switype](https://swiftype.com):
79
+ defining what a search index is. According to [Swiftype](https://swiftype.com):
78
80
  > A search index is a body of structured data that a search engine refers to
79
81
  > when looking for results that are relevant to a specific query. Indexes are a
80
82
  > critical piece of any search system, since they must be tailored to the
@@ -244,38 +246,38 @@ With no options: `{ place: :geo }`
244
246
 
245
247
  A `Document` is the Ruby representation of a RediSearch document.
246
248
 
247
- You can fetch a `Document` using `.get` or `mget` class methods.
248
- - `get(index, document_id)` fetches a single document in an `Index` for a given
249
- `document_id`.
249
+ You can fetch a `Document` using `.get` or `.mget` class methods.
250
+ - `get(index, document_id)` fetches a single `Document` in an `Index` for a
251
+ given `document_id`.
250
252
  - `mget(index, *document_ids)` fetches a collection of `Document`s
251
253
  in an `Index` for the given `document_ids`.
252
254
 
253
255
  You can also make a `Document` instance using the
254
256
  `.for_object(index, record, serializer: nil, only: [])` class method. It takes
255
- an `Index` instance and a ruby object. That object must respond to all the
256
- fields specified in the indexes schema or pass a serializer class that accepts
257
- the object and responds to all the fields specified in the indexes schema.
258
- `only` accepts an array of fields from the schema and limits the fields that are
259
- passed to the `Document`.
257
+ an `Index` instance and a Ruby object. That object must respond to all the
258
+ fields specified in the `Index`'s `Schema` or pass a serializer class that
259
+ accepts the object and responds to all the fields specified in the `Index`'s
260
+ `Schema`. `only` accepts an array of fields from the schema and limits the
261
+ fields that are passed to the `Document`.
260
262
 
261
263
  Once you have an instance of a `Document`, it responds to all the fields
262
- specified in the indexes schema as methods and `document_id`. `document_id` is
263
- automatically prepended with the indexes names unless it already is to ensure
264
- uniqueness. We prepend the index name because if you have two documents with the
265
- same id in different indexes we don't want the documents to override each other.
266
- There is also a `#document_id_without_index` method which removes the prepended
267
- index name.
264
+ specified in the `Index`'s `Schema` as methods and `document_id`. `document_id`
265
+ is automatically prepended with the `Index`'s names unless it already is to
266
+ ensure uniqueness. We prepend the `Index` name because if you have two
267
+ `Document`s with the same id in different `Index`s we don't want the `Document`s
268
+ to override each other. There is also a `#document_id_without_index` method
269
+ which removes the prepended index name.
268
270
 
269
- Finally there is a `#del` method that will remove the document from the index.
270
- It optionally accepts a `delete_document` named argument that signifies whether
271
- the document should be completely removed from the Redis instance vs just the
272
- index.
271
+ 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`.
273
275
 
274
276
 
275
277
  ## Index
276
278
 
277
- To initialize an index, pass the name of the index as a string or symbol and the
278
- schema.
279
+ To initialize an `Index`, pass the name of the `Index` as a string or symbol
280
+ and the `Schema`.
279
281
 
280
282
  ```ruby
281
283
  RediSearch::Index.new(name_of_index, schema)
@@ -291,7 +293,7 @@ RediSearch::Index.new(name_of_index, schema)
291
293
  - For efficiency, RediSearch encodes indexes differently if they are
292
294
  created with less than 32 text fields. This option forces RediSearch
293
295
  to encode indexes as if there were more than 32 text fields, which
294
- allows you to add additional fields (beyond 32) using `alter`.
296
+ allows you to add additional fields (beyond 32) using `add_field`.
295
297
  - `no_offsets: #{true || false}`
296
298
  - If set, we do not store term offsets for documents (saves memory, does
297
299
  not allow exact searches or highlighting). Implies `no_highlight`.
@@ -313,40 +315,40 @@ RediSearch::Index.new(name_of_index, schema)
313
315
  memory but does not allow sorting based on the frequencies of a given
314
316
  term within the document.
315
317
  - `drop`
316
- - Drops the index from the Redis instance, returns a boolean. Has an
318
+ - Drops the `Index` from the Redis instance, returns a boolean. Has an
317
319
  accompanying bang method that will raise an exception upon failure. Will
318
- return `false` if the index has already been dropped.
320
+ return `false` if the `Index` has already been dropped.
319
321
  - `exist?`
320
- - Returns a boolean signifying index existence.
322
+ - Returns a boolean signifying `Index` existence.
321
323
  - `info`
322
- - Returns a struct object with all the information about the index.
324
+ - Returns a struct object with all the information about the `Index`.
323
325
  - `fields`
324
- - Returns an array of the field names in the index.
326
+ - Returns an array of the field names in the `Index`.
325
327
  - `add(document, score: 1.0, replace: {}, language: nil, no_save: false)`
326
328
  - Takes a `Document` object and options. Has an
327
329
  accompanying bang method that will raise an exception upon failure.
328
- - `score` -> The document's rank, a value between 0.0 and 1.0
330
+ - `score` -> The `Document`'s rank, a value between 0.0 and 1.0
329
331
  - `language` -> Use a stemmer for the supplied language during indexing.
330
- - `no_save` -> Don't save the actual document in the database and only index it.
332
+ - `no_save` -> Don't save the actual `Document` in the database and only index it.
331
333
  - `replace` -> Accepts a boolean or a hash. If a truthy value is passed, we
332
334
  will do an UPSERT style insertion - and delete an older version of the
333
- document if it exists.
335
+ `Document` if it exists.
334
336
  - `replace: { partial: true }` -> Allows you to not have to specify all
335
337
  fields for reindexing. Fields not given to the command will be loaded from
336
- the current version of the document.
337
- - `add_multiple!(documents, score: 1.0, replace: {}, language: nil, no_save: false)`
338
+ the current version of the `Document`.
339
+ - `add_multiple(documents, score: 1.0, replace: {}, language: nil, no_save: false)`
338
340
  - Takes an array of `Document` objects. This provides a more performant way to
339
- add multiple documents to the index. Accepts the same options as `add`.
341
+ add multiple documents to the `Index`. Accepts the same options as `add`.
340
342
  - `del(document, delete_document: false)`
341
- - Removes a document from the index. `delete_document` signifies whether the
342
- document should be completely removed from the Redis instance vs just the
343
- index.
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`.
344
346
  - `document_count`
345
- - Returns the number of documents in the index
346
- - `alter(field_name, schema)`
347
- - Adds a new field to the index. Ex: `index.alter(:first_name, text: { phonetic: "dm:en" })`
347
+ - Returns the number of `Document`s in the `Index`
348
+ - `add_field(field_name, schema)`
349
+ - Adds a new field to the `Index`. Ex: `index.add_field(:first_name, text: { phonetic: "dm:en" })`
348
350
  - `reindex(documents, recreate: false, **options)`
349
- - If `recreate` is `true` the index will be dropped and recreated
351
+ - If `recreate` is `true` the `Index` will be dropped and recreated
350
352
  - `options` accepts the same options as `add`
351
353
 
352
354
 
@@ -354,8 +356,7 @@ RediSearch::Index.new(name_of_index, schema)
354
356
 
355
357
  Searching is initiated off a `RediSearch::Index` instance with clauses that can
356
358
  be chained together. When searching, an array of `Document`s is returned
357
- which has public reader methods for all the schema fields and a `document_id`
358
- method which returns the id of the document prefixed with the index name.
359
+ which has public reader methods for all the schema fields.
359
360
 
360
361
  ```ruby
361
362
  main ❯ index = RediSearch::Index.new("user_idx", name: { text: { phonetic: "dm:en" } })
@@ -440,15 +441,15 @@ index.search.where(number: -Float::INFINITY..0)
440
441
  phrase terms. (i.e the slop for exact phrases is 0)
441
442
  - `in_order`
442
443
  - Usually used in conjunction with `slop`. We make sure the query terms appear
443
- in the same order in the document as in the query, regardless of the offsets
444
- between them.
444
+ in the same order in the `Document` as in the query, regardless of the
445
+ offsets between them.
445
446
  - `no_content`
446
- - Only return the document ids and not the content. This is useful if
447
- RediSearch is being used on a Rails model where the document attributes
448
- don't matter and it's being converted into ActiveRecord objects.
447
+ - Only return the `Document` ids and not the content. This is useful if
448
+ RediSearch is being used on a Rails model where the `Document` attributes
449
+ don't matter and it's being converted into `ActiveRecord` objects.
449
450
  - `language(language)`
450
451
  - Stemmer to use for the supplied language during search for query expansion.
451
- If querying documents in Chinese, this should be set to chinese in order to
452
+ If querying `Document`s in Chinese, this should be set to chinese in order to
452
453
  properly tokenize the query terms. If an unsupported language is sent, the
453
454
  command returns an error.
454
455
  - `sort_by(field, order: :asc)`
@@ -459,7 +460,7 @@ index.search.where(number: -Float::INFINITY..0)
459
460
  - Limit the results to the specified `num` at the `offset`. The default limit
460
461
  is set to `10`.
461
462
  - `count`
462
- - Returns the number of documents found in the search query
463
+ - Returns the number of `Document`s found in the search query
463
464
  - `highlight(fields: [], opening_tag: "<b>", closing_tag: "</b>")`
464
465
  - Use this option to format occurrences of matched text. `fields` are an
465
466
  array of fields to be highlighted.
@@ -469,16 +470,14 @@ index.search.where(number: -Float::INFINITY..0)
469
470
  - `no_stop_words`
470
471
  - Do not filter stopwords from the query.
471
472
  - `with_scores`
472
- - Include the relative internal score of each document. This can be used to
473
+ - Include the relative internal score of each `Document`. This can be used to
473
474
  merge results from multiple instances. This will add a `score` method to the
474
475
  returned `Document` instances.
475
476
  - `return(*fields)`
476
- - Limit which fields from the document are returned.
477
+ - Limit which fields from the `Document` are returned.
477
478
  - `explain`
478
479
  - Returns the execution plan for a complex query. In the returned response,
479
480
  a + on a term is an indication of stemming.
480
- - `to_redis`
481
- - Returns the command to be executed without executing it.
482
481
 
483
482
 
484
483
  ## Spellcheck
@@ -507,8 +506,8 @@ main ❯ index.spellcheck("jimy", distance: 2).first.suggestions
507
506
 
508
507
  ## Rails Integration
509
508
 
510
- Integration with Rails is super easy! Call `redi_search` with the schema keyword
511
- arg from inside your model. Ex:
509
+ Integration with Rails is super easy! Call `redi_search` with the `schema`
510
+ keyword argument from inside your model. Ex:
512
511
 
513
512
  ```ruby
514
513
  class User < ApplicationRecord
@@ -522,8 +521,9 @@ end
522
521
  This will automatically add `User.search` and `User.spellcheck`
523
522
  methods which behave the same as if you called them on an `Index` instance.
524
523
 
525
- `User.reindex(only: [], **options)` is also added and behaves similarly to `RediSearch::Index#reindex`. Some of the differences include:
526
- - By default does an upsert for all documents added using the
524
+ `User.reindex(only: [], **options)` is also added and behaves similarly to
525
+ `RediSearch::Index#reindex`. Some of the differences include:
526
+ - By default, does an upsert for all `Document`s added using the
527
527
  option `replace: { partial: true }`.
528
528
  - `Document`s do not to be passed as the first parameter. The `search_import`
529
529
  scope is automatically called and all the records are converted
@@ -552,8 +552,8 @@ class UserSerializer < SimpleDelegator
552
552
  end
553
553
  ```
554
554
 
555
- You can create a scope on the model to eager load relationships when indexing or
556
- it can be used to limit the records to index.
555
+ You can override the `search_import` scope on the model to eager load
556
+ relationships when indexing or it can be used to limit the records to index.
557
557
 
558
558
  ```ruby
559
559
  class User < ApplicationRecord
@@ -561,7 +561,7 @@ class User < ApplicationRecord
561
561
  end
562
562
  ```
563
563
 
564
- The default index name for model indexes is
564
+ The default `Index` name for model `Index`s is
565
565
  `#{model_name.plural}_#{RediSearch.env}`. The `redi_search` method takes an
566
566
  optional `index_prefix` argument which gets prepended to the index name:
567
567
 
@@ -578,15 +578,16 @@ User.redi_search_index.name
578
578
  ```
579
579
 
580
580
  When integrating RediSearch into a model, records will automatically be indexed
581
- after creating and updating and will be removed from the index upon destruction.
581
+ after creating and updating and will be removed from the `Index` upon
582
+ destruction.
582
583
 
583
- There are few more convenience methods that are publicly available:
584
+ There are a few more convenience methods that are publicly available:
584
585
  - `redi_search_document`
585
586
  - Returns the record as a `RediSearch::Document` instance
586
587
  - `redi_search_delete_document`
587
- - Removes the record from the index
588
+ - Removes the record from the `Index`
588
589
  - `redi_search_add_document`
589
- - Adds the record to the index
590
+ - Adds the record to the `Index`
590
591
  - `redi_search_index`
591
592
  - Returns the `RediSearch::Index` instance
592
593
 
@@ -594,15 +595,15 @@ There are few more convenience methods that are publicly available:
594
595
  ## Development
595
596
 
596
597
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
597
- `rake test` to run the tests. You can also run `bin/console` for an interactive
598
- prompt that will allow you to experiment. You can also start a rails console if
599
- you `cd` into `test/dummy`.
598
+ `rake test` to run the both unit and integration tests. To run them individually
599
+ you can run `rake test:unit` or `rake test:integration`. You can also run
600
+ `bin/console` for an interactive prompt that will allow you to experiment.
600
601
 
601
602
  To install this gem onto your local machine, run `bundle exec rake install`. To
602
603
  release a new version, execute `bin/publish (major|minor|patch)` which will
603
604
  update the version number in `version.rb`, create a git tag for the version,
604
605
  push git commits and tags, and push the `.gem` file to
605
- [rubygems.org](https://rubygems.org).
606
+ [rubygems.org](https://rubygems.org) and GitHub.
606
607
 
607
608
  ## Contributing
608
609