redi_search 6.0.0 → 6.1.1

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: 44546188ac7648ecd413eea9c79c93fc76c23009476f585a2bf600e2da4afe3b
4
- data.tar.gz: eb8b6db657a5f671a8d0da0f69653d97301f8c2d116cfc9427b5105133312495
3
+ metadata.gz: 779fa58ead3f1109819deb5b8884eb9bbcfccbd34017a8288450f19077abdac6
4
+ data.tar.gz: caad3d0dec14dfea3ad2098d406a90c1c3f2afa99c416379726f4361f41c7eb2
5
5
  SHA512:
6
- metadata.gz: adda3ec25f90ea2a4b372549c1d1903a48774b890c9fd589e43ef87c7bccb11f19282f0e5b34df46026c7fffd4e3826ec4d6ef9d1a0216100846f5ece6f1bab7
7
- data.tar.gz: a1dc85af4e881b0ad63ae54f4b36cbaead28f2558fdf48674d82ef996bd7bc4482f417c92df920ca4480a20ad05fc190c14300c45467b35c91db23b296fa6d0e
6
+ metadata.gz: 778f9c57db20bde51dc953baa1c73deb54f2fe4c7783c017e3f5c76ab1c9b467bc10359ae1614e0fab512acfb170e3f3565edb600b87d580a6e7d82c766875b9
7
+ data.tar.gz: 850c1f47ffadcadb6fd98de2fc7a550d1d770179c14e99ffd1fa81e6a9147c6dcbc632f6e798c53437d4997b381dbc273263000b33472a4dd89991d4dccf1433
@@ -31,7 +31,7 @@ jobs:
31
31
  runs-on: ubuntu-latest
32
32
  strategy:
33
33
  matrix:
34
- redisearch: [ '2.0.14', '2.2.7' ]
34
+ redisearch: [ '2.4.7' ]
35
35
  services:
36
36
  redisearch:
37
37
  image: redislabs/redisearch:${{ matrix.redisearch }}
data/.rubocop.yml CHANGED
@@ -619,10 +619,6 @@ Lint/BinaryOperatorWithIdenticalOperands:
619
619
  Description: Checks for comparison of something with itself.
620
620
  Enabled: true
621
621
 
622
- Lint/UselessElseWithoutRescue:
623
- Description: Checks for useless `else` in `begin..end` without `rescue`.
624
- Enabled: true
625
-
626
622
  Lint/ReturnInVoidContext:
627
623
  Description: Checks for return in void context.
628
624
  Enabled: true
data/Gemfile CHANGED
@@ -17,4 +17,4 @@ gem "rubocop-rake"
17
17
  gem "simplecov"
18
18
  gem "sqlite3"
19
19
 
20
- gem "activerecord", "~> 6.1"
20
+ gem "activerecord", "~> 7.0"
data/README.md CHANGED
@@ -6,9 +6,6 @@
6
6
 
7
7
  # RediSearch
8
8
 
9
- ![Build Status](https://github.com/npezza93/redi_search/workflows/tests/badge.svg)
10
- [![Maintainability](https://api.codeclimate.com/v1/badges/c6437acac5684de2549d/maintainability)](https://codeclimate.com/github/npezza93/redi_search/maintainability)
11
-
12
9
  A simple, but powerful, Ruby wrapper around RediSearch, a search engine on top of
13
10
  Redis.
14
11
 
@@ -53,7 +53,7 @@ module RediSearch
53
53
 
54
54
  @loaded = true
55
55
 
56
- call!.yield_self do |response|
56
+ call!.then do |response|
57
57
  parse_response(response)
58
58
  end
59
59
  end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/version"
3
4
  require "active_support/log_subscriber"
5
+ if ActiveSupport::VERSION::MAJOR > 6
6
+ require "active_support/isolated_execution_state"
7
+ end
4
8
 
5
9
  module RediSearch
6
10
  class LogSubscriber < ActiveSupport::LogSubscriber
@@ -43,8 +43,8 @@ module RediSearch
43
43
  search_index.spellcheck(term, distance: distance)
44
44
  end
45
45
 
46
- def reindex(recreate: false, only: [])
47
- search_import.find_in_batches.all? do |group|
46
+ def reindex(recreate: false, only: [], batch_size: 1000)
47
+ search_import.find_in_batches(batch_size: batch_size).all? do |group|
48
48
  search_index.reindex(
49
49
  group.map { |record| record.search_document(only: only) },
50
50
  recreate: recreate
@@ -11,6 +11,10 @@ module RediSearch
11
11
  value
12
12
  end
13
13
 
14
+ def cast(value)
15
+ value
16
+ end
17
+
14
18
  def serialize(record)
15
19
  if value_block
16
20
  record.instance_exec(&value_block)
@@ -19,10 +23,6 @@ module RediSearch
19
23
  end
20
24
  end
21
25
 
22
- def tag?
23
- false
24
- end
25
-
26
26
  private
27
27
 
28
28
  attr_reader :value_block
@@ -17,6 +17,14 @@ module RediSearch
17
17
  query
18
18
  end
19
19
 
20
+ def cast(value)
21
+ if value.to_s.include?(".")
22
+ value.to_f
23
+ else
24
+ value.to_i
25
+ end
26
+ end
27
+
20
28
  private
21
29
 
22
30
  attr_reader :sortable, :no_index
@@ -24,8 +24,8 @@ module RediSearch
24
24
  value.join(separator)
25
25
  end
26
26
 
27
- def tag?
28
- true
27
+ def cast(value)
28
+ value.split(separator)
29
29
  end
30
30
 
31
31
  private
@@ -40,7 +40,7 @@ module RediSearch
40
40
  end
41
41
 
42
42
  def [](name)
43
- fields.find { |field| field.name == name }
43
+ fields.find { |field| field.name.to_sym == name.to_sym }
44
44
  end
45
45
 
46
46
  private
@@ -21,6 +21,8 @@ module RediSearch
21
21
  end
22
22
 
23
23
  def_delegators :results, :each, :empty?, :[], :last
24
+ def_delegator :search, :index
25
+ def_delegator :index, :schema
24
26
 
25
27
  def inspect
26
28
  results
@@ -58,9 +60,17 @@ module RediSearch
58
60
  fields = slice.last unless no_content?
59
61
  score = slice[1].to_f if with_scores?
60
62
 
61
- Document.new(search.index, document_id, Hash[*fields.to_a], score)
63
+ parse_result(document_id, fields, score)
62
64
  end
63
65
  end
66
+
67
+ def parse_result(document_id, fields, score)
68
+ field_values = fields.to_a.each_slice(2).to_h do |name, value|
69
+ [name, schema[name].cast(value)]
70
+ end
71
+
72
+ Document.new(search.index, document_id, field_values, score)
73
+ end
64
74
  end
65
75
  end
66
76
  end
@@ -20,7 +20,7 @@ module RediSearch
20
20
 
21
21
  def to_s
22
22
  if term.is_a?(Range) then stringify_range
23
- elsif !field.nil? && field.tag? then stringify_tag
23
+ elsif field.is_a?(Schema::TagField) then stringify_tag
24
24
  else
25
25
  stringify_query
26
26
  end
@@ -53,18 +53,14 @@ module RediSearch
53
53
  def stringify_query
54
54
  term.to_s.
55
55
  tr("`", "\`").
56
- yield_self { |str| "#{fuzzy_operator}#{str}#{fuzzy_operator}" }.
57
- yield_self { |str| "#{optional_operator}#{str}" }.
58
- yield_self { |str| "#{str}#{prefix_operator}" }.
59
- yield_self { |str| "`#{str}`" }
56
+ then { |str| "#{fuzzy_operator}#{str}#{fuzzy_operator}" }.
57
+ then { |str| "#{optional_operator}#{str}" }.
58
+ then { |str| "#{str}#{prefix_operator}" }.
59
+ then { |str| "`#{str}`" }
60
60
  end
61
61
 
62
62
  def stringify_tag
63
- if term.is_a?(Array)
64
- "{ #{term.join(' | ')} }"
65
- else
66
- "{ #{term} }"
67
- end
63
+ "{ #{Array(term).join(' | ')} }"
68
64
  end
69
65
 
70
66
  def stringify_range
@@ -31,7 +31,7 @@ module RediSearch
31
31
 
32
32
  @loaded = true
33
33
 
34
- RediSearch.client.call!(*command).yield_self do |response|
34
+ RediSearch.client.call!(*command).then do |response|
35
35
  parse_response(response)
36
36
  end
37
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RediSearch
4
- VERSION = "6.0.0"
4
+ VERSION = "6.1.1"
5
5
  end
data/lib/redi_search.rb CHANGED
@@ -30,7 +30,7 @@ module RediSearch
30
30
  end
31
31
 
32
32
  def env
33
- ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
33
+ ENV.fetch("RAILS_ENV") { ENV.fetch("RACK_ENV", "development") }
34
34
  end
35
35
  end
36
36
  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: 6.0.0
4
+ version: 6.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-05 00:00:00.000000000 Z
11
+ date: 2022-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  - !ruby/object:Gem::Version
211
211
  version: '0'
212
212
  requirements: []
213
- rubygems_version: 3.2.22
213
+ rubygems_version: 3.3.7
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: RediSearch ruby wrapper that can integrate with Rails