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
@@ -20,7 +20,7 @@ module RediSearch
20
20
 
21
21
  private
22
22
 
23
- attr_reader :name, :sortable, :no_index
23
+ attr_reader :sortable, :no_index
24
24
 
25
25
  def boolean_options
26
26
  %i(sortable no_index)
@@ -20,7 +20,7 @@ module RediSearch
20
20
 
21
21
  private
22
22
 
23
- attr_reader :name, :sortable, :no_index
23
+ attr_reader :sortable, :no_index
24
24
 
25
25
  def boolean_options
26
26
  %i(sortable no_index)
@@ -20,9 +20,13 @@ module RediSearch
20
20
  query
21
21
  end
22
22
 
23
+ def serialize(value)
24
+ value.join(separator)
25
+ end
26
+
23
27
  private
24
28
 
25
- attr_reader :name, :separator, :sortable, :no_index
29
+ attr_reader :separator, :sortable, :no_index
26
30
 
27
31
  def boolean_options
28
32
  %i(sortable no_index)
@@ -24,7 +24,7 @@ module RediSearch
24
24
 
25
25
  private
26
26
 
27
- attr_reader :name, :weight, :phonetic, :sortable, :no_index, :no_stem
27
+ attr_reader :weight, :phonetic, :sortable, :no_index, :no_stem
28
28
 
29
29
  def boolean_options
30
30
  %i(sortable no_index no_stem)
@@ -12,7 +12,7 @@ module RediSearch
12
12
  schema, options = options.to_a.flatten
13
13
 
14
14
  Object.const_get("RediSearch::Schema::#{schema.to_s.capitalize}Field").
15
- new(field_name, **options.to_h).to_a
15
+ new(field_name, **options.to_h)
16
16
  end
17
17
 
18
18
  def initialize(raw)
@@ -20,17 +20,22 @@ module RediSearch
20
20
  end
21
21
 
22
22
  def to_a
23
- raw.map do |field_name, options|
24
- self.class.make_field(field_name, options)
25
- end.flatten
23
+ fields.map(&:to_a).flatten
24
+ end
25
+
26
+ def [](field)
27
+ fields.group_by(&:name)[field]&.first
26
28
  end
27
29
 
28
30
  def fields
29
- raw.keys
31
+ @fields ||= raw.map do |field_name, options|
32
+ self.class.make_field(field_name, options)
33
+ end.flatten
30
34
  end
31
35
 
32
36
  def add_field(field_name, options)
33
37
  raw[field_name] = options
38
+ @fields = nil
34
39
  self
35
40
  end
36
41
 
@@ -48,7 +48,7 @@ module RediSearch
48
48
  @term = if term.is_a? RediSearch::Search
49
49
  term
50
50
  else
51
- Term.new(term, term_options)
51
+ Term.new(term, **term_options)
52
52
  end
53
53
  end
54
54
 
@@ -65,10 +65,10 @@ module RediSearch
65
65
  end
66
66
 
67
67
  def queryify_search
68
- if !term.term_clause.is_a?(RediSearch::Search::Clauses::Where)
69
- "(#{term.term_clause})"
70
- else
68
+ if term.term_clause.is_a?(RediSearch::Search::Clauses::Where)
71
69
  term.term_clause
70
+ else
71
+ "(#{term.term_clause})"
72
72
  end
73
73
  end
74
74
  end
@@ -7,7 +7,7 @@ module RediSearch
7
7
  module Clauses
8
8
  class Or < Boolean
9
9
  def where(**condition)
10
- @term = search.dup.where(condition)
10
+ @term = search.dup.where(**condition)
11
11
 
12
12
  search
13
13
  end
@@ -26,11 +26,11 @@ module RediSearch
26
26
  results
27
27
  end
28
28
 
29
- #:nocov:
29
+ # :nocov:
30
30
  def pretty_print(printer)
31
31
  printer.pp(results)
32
32
  end
33
- #:nocov:
33
+ # :nocov:
34
34
 
35
35
  private
36
36
 
@@ -54,7 +54,7 @@ module RediSearch
54
54
  end
55
55
 
56
56
  def parse_response(response)
57
- @documents = Result.new(self, response[0], response[1..-1])
57
+ @documents = Result.new(self, response[0], response[1..])
58
58
  end
59
59
 
60
60
  def valid?
@@ -15,14 +15,14 @@ module RediSearch
15
15
  end
16
16
 
17
17
  def inspect
18
- inspection = %w(term suggestions).map do |field_name|
18
+ inspection = %w(term suggestions).filter_map do |field_name|
19
19
  "#{field_name}: #{public_send(field_name)}"
20
- end.compact.join(", ")
20
+ end.join(", ")
21
21
 
22
22
  "#<#{self.class} #{inspection}>"
23
23
  end
24
24
 
25
- #:nocov:
25
+ # :nocov:
26
26
  def pretty_print(printer) # rubocop:disable Metrics/MethodLength
27
27
  printer.object_address_group(self) do
28
28
  printer.seplist(
@@ -38,7 +38,7 @@ module RediSearch
38
38
  end
39
39
  end
40
40
  end
41
- #:nocov:
41
+ # :nocov:
42
42
  end
43
43
  end
44
44
  end
@@ -27,7 +27,7 @@ module RediSearch
27
27
  end
28
28
 
29
29
  def parsed_terms
30
- terms.split(Regexp.union(",.<>{}[]\"':;!@#$%^&*()-+=~\s".split("")))
30
+ terms.split(Regexp.union(",.<>{}[]\"':;!@#$%^&*()-+=~\s".chars))
31
31
  end
32
32
 
33
33
  def execute
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RediSearch
4
- VERSION = "2.0.2"
4
+ VERSION = "5.0.0"
5
5
  end
data/redi_search.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.name = "redi_search"
9
9
  spec.version = RediSearch::VERSION
10
10
  spec.authors = "Nick Pezza"
11
- spec.email = "npezza93@gmail.com"
11
+ spec.email = "pezza@hey.com"
12
12
 
13
13
  spec.summary = %q(RediSearch ruby wrapper that can integrate with Rails)
14
14
  spec.homepage = "https://github.com/npezza93/redi_search"
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.metadata["changelog_uri"] =
25
25
  "https://github.com/npezza93/redi_search/releases"
26
26
 
27
- spec.required_ruby_version = ">= 2.5.0"
27
+ spec.required_ruby_version = ">= 2.7.0"
28
28
 
29
- spec.add_runtime_dependency "activesupport", ">= 5.1", "< 6.1"
29
+ spec.add_runtime_dependency "activesupport", ">= 5.1", "< 7.1"
30
30
  spec.add_runtime_dependency "redis", ">= 4.0", "< 5.0"
31
31
 
32
32
  spec.add_development_dependency "bundler", ">= 1.17", "< 3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redi_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: redis
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -98,8 +98,8 @@ dependencies:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
100
  version: '13.0'
101
- description:
102
- email: npezza93@gmail.com
101
+ description:
102
+ email: pezza@hey.com
103
103
  executables: []
104
104
  extensions: []
105
105
  extra_rdoc_files: []
@@ -121,10 +121,10 @@ files:
121
121
  - bin/publish
122
122
  - bin/setup
123
123
  - gemfiles/.bundle/config
124
- - gemfiles/activerecord_51.gemfile
125
- - gemfiles/activerecord_52.gemfile
124
+ - gemfiles/activerecord_60.gemfile
125
+ - gemfiles/activerecord_61.gemfile
126
+ - gemfiles/activerecord_70.gemfile
126
127
  - lib/redi_search.rb
127
- - lib/redi_search/add.rb
128
128
  - lib/redi_search/add_field.rb
129
129
  - lib/redi_search/client.rb
130
130
  - lib/redi_search/client/response.rb
@@ -133,6 +133,7 @@ files:
133
133
  - lib/redi_search/document.rb
134
134
  - lib/redi_search/document/display.rb
135
135
  - lib/redi_search/document/finder.rb
136
+ - lib/redi_search/hset.rb
136
137
  - lib/redi_search/index.rb
137
138
  - lib/redi_search/lazily_load.rb
138
139
  - lib/redi_search/log_subscriber.rb
@@ -179,7 +180,7 @@ metadata:
179
180
  homepage_uri: https://github.com/npezza93/redi_search
180
181
  source_code_uri: https://github.com/npezza93/redi_search
181
182
  changelog_uri: https://github.com/npezza93/redi_search/releases
182
- post_install_message:
183
+ post_install_message:
183
184
  rdoc_options: []
184
185
  require_paths:
185
186
  - lib
@@ -187,15 +188,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
188
  requirements:
188
189
  - - ">="
189
190
  - !ruby/object:Gem::Version
190
- version: 2.5.0
191
+ version: 2.7.0
191
192
  required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  requirements:
193
194
  - - ">="
194
195
  - !ruby/object:Gem::Version
195
196
  version: '0'
196
197
  requirements: []
197
- rubygems_version: 3.1.2
198
- signing_key:
198
+ rubygems_version: 3.2.22
199
+ signing_key:
199
200
  specification_version: 4
200
201
  summary: RediSearch ruby wrapper that can integrate with Rails
201
202
  test_files: []
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "redi_search/validatable"
4
-
5
- module RediSearch
6
- class Add
7
- include Validatable
8
-
9
- validates_numericality_of :score, within: 0.0..1.0
10
-
11
- def initialize(index, document, score: 1.0, replace: {}, language: nil,
12
- no_save: false)
13
- @index = index
14
- @document = document
15
- @score = score || 1.0
16
- @replace = replace
17
- @language = language
18
- @no_save = no_save
19
- end
20
-
21
- def call!
22
- validate!
23
-
24
- RediSearch.client.call!(*command).ok?
25
- end
26
-
27
- def call
28
- call!
29
- rescue Redis::CommandError
30
- false
31
- end
32
-
33
- private
34
-
35
- attr_reader :index, :document, :score, :replace, :language, :no_save
36
-
37
- def command
38
- ["ADD", index.name, document.document_id, score, *extract_options,
39
- "FIELDS", document.redis_attributes].compact
40
- end
41
-
42
- def extract_options
43
- opts = []
44
- opts << ["LANGUAGE", language] if language
45
- opts << "NOSAVE" if no_save
46
- opts << replace_options if replace?
47
- opts
48
- end
49
-
50
- def replace?
51
- if replace.respond_to?(:empty?)
52
- !replace.empty?
53
- else
54
- replace
55
- end
56
- end
57
-
58
- def replace_options
59
- ["REPLACE"].tap do |replace_option|
60
- if replace.is_a?(Hash)
61
- replace_option << "PARTIAL" if replace[:partial]
62
- # replace_option << "NOCREATE" if replace[:no_create]
63
- end
64
- end
65
- end
66
- end
67
- end