redi_search 2.0.0 → 4.1.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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "redi_search/add"
3
+ require "redi_search/hset"
4
4
  require "redi_search/create"
5
5
  require "redi_search/schema"
6
6
  require "redi_search/search"
@@ -33,34 +33,36 @@ module RediSearch
33
33
  Create.new(self, schema, options).call!
34
34
  end
35
35
 
36
- def drop
37
- drop!
36
+ def drop(keep_docs: false)
37
+ drop!(keep_docs: keep_docs)
38
38
  rescue Redis::CommandError
39
39
  false
40
40
  end
41
41
 
42
- def drop!
43
- client.call!("DROP", name).ok?
42
+ def drop!(keep_docs: false)
43
+ command = ["DROPINDEX", name]
44
+ command << "DD" unless keep_docs
45
+ client.call!(*command.compact).ok?
44
46
  end
45
47
 
46
- def add(document, **options)
47
- Add.new(self, document, **options).call
48
+ def add(document)
49
+ Hset.new(self, document).call
48
50
  end
49
51
 
50
- def add!(document, **options)
51
- Add.new(self, document, **options).call!
52
+ def add!(document)
53
+ Hset.new(self, document).call!
52
54
  end
53
55
 
54
- def add_multiple(documents, **options)
56
+ def add_multiple(documents)
55
57
  client.multi do
56
58
  documents.each do |document|
57
- add(document, **options)
59
+ add(document)
58
60
  end
59
- end.ok?
61
+ end.all? { |response| response >= 0 }
60
62
  end
61
63
 
62
- def del(document, delete_document: false)
63
- document.del(delete_document: delete_document)
64
+ def del(document)
65
+ document.del
64
66
  end
65
67
 
66
68
  def exist?
@@ -78,14 +80,14 @@ module RediSearch
78
80
  end
79
81
 
80
82
  def fields
81
- schema.fields.map(&:to_s)
83
+ schema.fields.map { |field| field.name.to_s }
82
84
  end
83
85
 
84
- def reindex(documents, recreate: false, **options)
86
+ def reindex(documents, recreate: false)
85
87
  drop if recreate
86
88
  create unless exist?
87
89
 
88
- add_multiple documents, **options
90
+ add_multiple documents
89
91
  end
90
92
 
91
93
  def document_count
@@ -35,23 +35,24 @@ module RediSearch
35
35
  color("#{event.payload[:name]} (#{event.duration.round(1)}ms)", RED, true)
36
36
  end
37
37
 
38
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
38
+ # rubocop:disable Metrics/MethodLength
39
39
  def action_color(action)
40
40
  case action.to_sym
41
41
  when :search, :spellcheck then YELLOW
42
- when :create, :add then GREEN
43
- when :drop, :del then RED
44
- when :get, :mget, :info then CYAN
42
+ when :create, :hset then GREEN
43
+ when :dropindex, :del then RED
44
+ when :hgetall, :info then CYAN
45
45
  when :pipeline then MAGENTA
46
46
  when :explaincli then BLUE
47
47
  end
48
48
  end
49
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
49
+ # rubocop:enable Metrics/MethodLength
50
50
 
51
51
  def command_string(event)
52
52
  event.payload[:query].flatten.map.with_index do |arg, i|
53
53
  arg = "FT.#{arg}" if prepend_ft?(arg, i)
54
54
  arg = arg.inspect if inspect_arg?(event.payload, arg)
55
+ arg = " #{arg}" if event.payload[:inside_pipeline]
55
56
  arg
56
57
  end.join(" ")
57
58
  end
@@ -61,7 +62,7 @@ module RediSearch
61
62
  end
62
63
 
63
64
  def prepend_ft?(arg, index)
64
- index.zero? && !multiword?(arg)
65
+ index.zero? && !multiword?(arg) && %w(HSET HGETALL DEL).exclude?(arg.to_s)
65
66
  end
66
67
 
67
68
  def inspect_arg?(payload, arg)
@@ -48,11 +48,11 @@ module RediSearch
48
48
  redi_search_index.spellcheck(term, distance: distance)
49
49
  end
50
50
 
51
- def reindex(only: [], **options)
51
+ def reindex(recreate: false, only: [])
52
52
  search_import.find_in_batches.all? do |group|
53
53
  redi_search_index.reindex(
54
54
  group.map { |record| record.redi_search_document(only: only) },
55
- **options.deep_merge(replace: { partial: true })
55
+ recreate: recreate
56
56
  )
57
57
  end
58
58
  end
@@ -67,17 +67,11 @@ module RediSearch
67
67
  end
68
68
 
69
69
  def redi_search_delete_document
70
- return unless self.class.redi_search_index.exist?
71
-
72
- self.class.redi_search_index.del(
73
- redi_search_document, delete_document: true
74
- )
70
+ self.class.redi_search_index.del(redi_search_document)
75
71
  end
76
72
 
77
73
  def redi_search_add_document
78
- return unless self.class.redi_search_index.exist?
79
-
80
- self.class.redi_search_index.add(redi_search_document, replace: true)
74
+ self.class.redi_search_index.add(redi_search_document)
81
75
  end
82
76
  end
83
77
  end
@@ -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
 
@@ -3,6 +3,14 @@
3
3
  module RediSearch
4
4
  class Schema
5
5
  class Field
6
+ def name
7
+ @name&.to_sym
8
+ end
9
+
10
+ def serialize(value)
11
+ value
12
+ end
13
+
6
14
  private
7
15
 
8
16
  FALSES = [
@@ -11,9 +19,8 @@ module RediSearch
11
19
 
12
20
  def boolean_options_string
13
21
  boolean_options.map do |option|
14
- unless FALSES.include?(send(option))
15
- option.to_s.upcase.split("_").join
16
- end
22
+ option.to_s.upcase.split("_").join unless
23
+ FALSES.include?(send(option))
17
24
  end.compact
18
25
  end
19
26
  end
@@ -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)
@@ -13,6 +13,7 @@ module RediSearch
13
13
  include Clauses
14
14
 
15
15
  attr_reader :term_clause, :used_clauses, :index, :clauses
16
+
16
17
  def_delegator :index, :model
17
18
 
18
19
  def initialize(index, term = nil, **term_options)
@@ -26,6 +27,8 @@ module RediSearch
26
27
 
27
28
  def results
28
29
  if model
30
+ no_content unless loaded?
31
+
29
32
  model.where(id: to_a.map(&:document_id_without_index))
30
33
  else
31
34
  to_a
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RediSearch
4
- VERSION = "2.0.0"
4
+ VERSION = "4.1.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"
@@ -26,10 +26,10 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.required_ruby_version = ">= 2.5.0"
28
28
 
29
- spec.add_runtime_dependency "activesupport", ">= 5.1", "< 6.1"
29
+ spec.add_runtime_dependency "activesupport", ">= 5.1", "< 6.2"
30
30
  spec.add_runtime_dependency "redis", ">= 4.0", "< 5.0"
31
31
 
32
32
  spec.add_development_dependency "bundler", ">= 1.17", "< 3"
33
33
  spec.add_development_dependency "minitest", "~> 5.0"
34
- spec.add_development_dependency "rake", "~> 12.0"
34
+ spec.add_development_dependency "rake", "~> 13.0"
35
35
  end
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.0
4
+ version: 4.1.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: 2019-08-03 00:00:00.000000000 Z
11
+ date: 2021-03-14 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: '6.2'
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: '6.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: redis
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -90,16 +90,16 @@ dependencies:
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: '12.0'
93
+ version: '13.0'
94
94
  type: :development
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: '12.0'
101
- description:
102
- email: npezza93@gmail.com
100
+ version: '13.0'
101
+ description:
102
+ email: pezza@hey.com
103
103
  executables: []
104
104
  extensions: []
105
105
  extra_rdoc_files: []
@@ -107,9 +107,10 @@ files:
107
107
  - ".github/ISSUE_TEMPLATE/bug_report.md"
108
108
  - ".github/ISSUE_TEMPLATE/feature_request.md"
109
109
  - ".github/logo.svg"
110
+ - ".github/workflows/lint.yml"
111
+ - ".github/workflows/tests.yml"
110
112
  - ".gitignore"
111
113
  - ".rubocop.yml"
112
- - ".travis.yml"
113
114
  - Appraisals
114
115
  - CODE_OF_CONDUCT.md
115
116
  - Gemfile
@@ -120,10 +121,9 @@ files:
120
121
  - bin/publish
121
122
  - bin/setup
122
123
  - gemfiles/.bundle/config
123
- - gemfiles/activerecord_51.gemfile
124
- - gemfiles/activerecord_52.gemfile
124
+ - gemfiles/activerecord_60.gemfile
125
+ - gemfiles/activerecord_61.gemfile
125
126
  - lib/redi_search.rb
126
- - lib/redi_search/add.rb
127
127
  - lib/redi_search/add_field.rb
128
128
  - lib/redi_search/client.rb
129
129
  - lib/redi_search/client/response.rb
@@ -132,6 +132,7 @@ files:
132
132
  - lib/redi_search/document.rb
133
133
  - lib/redi_search/document/display.rb
134
134
  - lib/redi_search/document/finder.rb
135
+ - lib/redi_search/hset.rb
135
136
  - lib/redi_search/index.rb
136
137
  - lib/redi_search/lazily_load.rb
137
138
  - lib/redi_search/log_subscriber.rb
@@ -178,7 +179,7 @@ metadata:
178
179
  homepage_uri: https://github.com/npezza93/redi_search
179
180
  source_code_uri: https://github.com/npezza93/redi_search
180
181
  changelog_uri: https://github.com/npezza93/redi_search/releases
181
- post_install_message:
182
+ post_install_message:
182
183
  rdoc_options: []
183
184
  require_paths:
184
185
  - lib
@@ -193,8 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  - !ruby/object:Gem::Version
194
195
  version: '0'
195
196
  requirements: []
196
- rubygems_version: 3.0.3
197
- signing_key:
197
+ rubygems_version: 3.2.8
198
+ signing_key:
198
199
  specification_version: 4
199
200
  summary: RediSearch ruby wrapper that can integrate with Rails
200
201
  test_files: []