searchkick 5.1.2 → 5.2.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: 93a4b2478d1c1353f7117fff60a08a50c896a1b78e150abf1a6b328901933e4d
4
- data.tar.gz: 1ff1fac4e47194445ca9f0ec2a470b7f15fe9aeb135960aa874e1a6beff62a2e
3
+ metadata.gz: cd5ad80ede7109fee3886bc0e5c27b8f2e4a39ed9530ac3a0c4683d8281dcd7c
4
+ data.tar.gz: 41c8736fc385b97d14ee1f0aef72cd8fbefad6d171dae879066901af5481fef1
5
5
  SHA512:
6
- metadata.gz: 52f8ccfb7f3615492a1674c7d48878b31bc9fd4e8cb8c411fbb19020d910c1ce395764aa1e378fab8e59294a7f5ef0bd2db0f9cd32c728dd302984ded4c7f20d
7
- data.tar.gz: 0c26ce9bb674b6aa5744edfd8567024a1f1d50fb30b6096abcdfdc23c73a71afbb9310a56809cc135b2d30653e1330cfa057fd9778e005a2aeeb1d354d7686af
6
+ metadata.gz: a8dd0e09fe48cc48e240d295fd350734bfe787e06611a5f3637e4b9d7e81afa327ea42fbe5912024c06bbe6de55ecbb41ecac57d98d6194bf7d94e34d89eb39c
7
+ data.tar.gz: ba98108eda0e4cb2d3884e3402246ad2c269a11438d6eb62ee2346b2cbfe6dd2c4e2865df5ed52bfef6faf3dbc031dc4ca3d6aefb0c5d7487b347b496bd3b29e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 5.2.1 (2023-02-21)
2
+
3
+ - Added support for `redis-client` gem
4
+
5
+ ## 5.2.0 (2023-02-08)
6
+
7
+ - Added model name to warning about missing records
8
+ - Fixed unnecessary data loading when reindexing relations with `:async` and `:queue` modes
9
+
1
10
  ## 5.1.2 (2023-01-29)
2
11
 
3
12
  - Fixed error with missing point in time
data/README.md CHANGED
@@ -1837,6 +1837,10 @@ To query nested data, use dot notation.
1837
1837
  Product.search("san", fields: ["store.city"], where: {"store.zip_code" => 12345})
1838
1838
  ```
1839
1839
 
1840
+ ## Nearest Neighbors
1841
+
1842
+ You can use custom mapping and searching to index vectors and perform k-nearest neighbor search. See the examples for [Elasticsearch](examples/elasticsearch_knn.rb) and [OpenSearch](examples/opensearch_knn.rb).
1843
+
1840
1844
  ## Reference
1841
1845
 
1842
1846
  Reindex one record
@@ -10,7 +10,7 @@ module Searchkick
10
10
 
11
11
  # supports single and multiple ids
12
12
  def push(record_ids)
13
- Searchkick.with_redis { |r| r.lpush(redis_key, record_ids) }
13
+ Searchkick.with_redis { |r| r.call("LPUSH", redis_key, record_ids) }
14
14
  end
15
15
 
16
16
  def push_records(records)
@@ -34,11 +34,11 @@ module Searchkick
34
34
  # TODO use reliable queuing
35
35
  def reserve(limit: 1000)
36
36
  if supports_rpop_with_count?
37
- Searchkick.with_redis { |r| r.call("rpop", redis_key, limit) }.to_a
37
+ Searchkick.with_redis { |r| r.call("RPOP", redis_key, limit) }.to_a
38
38
  else
39
39
  record_ids = []
40
40
  Searchkick.with_redis do |r|
41
- while record_ids.size < limit && (record_id = r.rpop(redis_key))
41
+ while record_ids.size < limit && (record_id = r.call("RPOP", redis_key))
42
42
  record_ids << record_id
43
43
  end
44
44
  end
@@ -47,11 +47,11 @@ module Searchkick
47
47
  end
48
48
 
49
49
  def clear
50
- Searchkick.with_redis { |r| r.del(redis_key) }
50
+ Searchkick.with_redis { |r| r.call("DEL", redis_key) }
51
51
  end
52
52
 
53
53
  def length
54
- Searchkick.with_redis { |r| r.llen(redis_key) }
54
+ Searchkick.with_redis { |r| r.call("LLEN", redis_key) }
55
55
  end
56
56
 
57
57
  private
@@ -65,7 +65,12 @@ module Searchkick
65
65
  end
66
66
 
67
67
  def redis_version
68
- @redis_version ||= Searchkick.with_redis { |r| Gem::Version.new(r.info["redis_version"]) }
68
+ @redis_version ||=
69
+ Searchkick.with_redis do |r|
70
+ info = r.call("INFO")
71
+ matches = /redis_version:(\S+)/.match(info)
72
+ Gem::Version.new(matches[1])
73
+ end
69
74
  end
70
75
 
71
76
  def escape(value)
@@ -14,12 +14,17 @@ module Searchkick
14
14
  relation = relation.search_import
15
15
  end
16
16
 
17
- # remove unneeded loading for async
18
- if mode == :async
17
+ # remove unneeded loading for async and queue
18
+ if mode == :async || mode == :queue
19
19
  if relation.respond_to?(:primary_key)
20
- relation = relation.select(relation.primary_key).except(:includes, :preload)
20
+ relation = relation.except(:includes, :preload)
21
+ unless mode == :queue && relation.klass.method_defined?(:search_routing)
22
+ relation = relation.except(:select).select(relation.primary_key)
23
+ end
21
24
  elsif relation.respond_to?(:only)
22
- relation = relation.only(:_id)
25
+ unless mode == :queue && relation.klass.method_defined?(:search_routing)
26
+ relation = relation.only(:_id)
27
+ end
23
28
  end
24
29
  end
25
30
 
@@ -42,11 +47,11 @@ module Searchkick
42
47
  end
43
48
 
44
49
  def batches_left
45
- Searchkick.with_redis { |r| r.scard(batches_key) }
50
+ Searchkick.with_redis { |r| r.call("SCARD", batches_key) }
46
51
  end
47
52
 
48
53
  def batch_completed(batch_id)
49
- Searchkick.with_redis { |r| r.srem(batches_key, [batch_id]) }
54
+ Searchkick.with_redis { |r| r.call("SREM", batches_key, [batch_id]) }
50
55
  end
51
56
 
52
57
  private
@@ -134,7 +139,7 @@ module Searchkick
134
139
  end
135
140
 
136
141
  def batch_job(class_name, batch_id, record_ids)
137
- Searchkick.with_redis { |r| r.sadd(batches_key, [batch_id]) }
142
+ Searchkick.with_redis { |r| r.call("SADD", batches_key, [batch_id]) }
138
143
  Searchkick::BulkReindexJob.perform_later(
139
144
  class_name: class_name,
140
145
  index_name: index.name,
@@ -304,7 +304,7 @@ module Searchkick
304
304
  def build_hits
305
305
  @build_hits ||= begin
306
306
  if missing_records.any?
307
- Searchkick.warn("Records in search index do not exist in database: #{missing_records.map { |v| v[:id] }.join(", ")}")
307
+ Searchkick.warn("Records in search index do not exist in database: #{missing_records.map { |v| "#{v[:model].model_name} #{v[:id]}" }.join(", ")}")
308
308
  end
309
309
  with_hit_and_missing_records[0]
310
310
  end
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "5.1.2"
2
+ VERSION = "5.2.1"
3
3
  end
data/lib/searchkick.rb CHANGED
@@ -10,27 +10,27 @@ require "hashie"
10
10
  require "forwardable"
11
11
 
12
12
  # modules
13
- require "searchkick/controller_runtime"
14
- require "searchkick/index"
15
- require "searchkick/index_cache"
16
- require "searchkick/index_options"
17
- require "searchkick/indexer"
18
- require "searchkick/hash_wrapper"
19
- require "searchkick/log_subscriber"
20
- require "searchkick/model"
21
- require "searchkick/multi_search"
22
- require "searchkick/query"
23
- require "searchkick/reindex_queue"
24
- require "searchkick/record_data"
25
- require "searchkick/record_indexer"
26
- require "searchkick/relation"
27
- require "searchkick/relation_indexer"
28
- require "searchkick/results"
29
- require "searchkick/version"
30
- require "searchkick/where"
13
+ require_relative "searchkick/controller_runtime"
14
+ require_relative "searchkick/index"
15
+ require_relative "searchkick/index_cache"
16
+ require_relative "searchkick/index_options"
17
+ require_relative "searchkick/indexer"
18
+ require_relative "searchkick/hash_wrapper"
19
+ require_relative "searchkick/log_subscriber"
20
+ require_relative "searchkick/model"
21
+ require_relative "searchkick/multi_search"
22
+ require_relative "searchkick/query"
23
+ require_relative "searchkick/reindex_queue"
24
+ require_relative "searchkick/record_data"
25
+ require_relative "searchkick/record_indexer"
26
+ require_relative "searchkick/relation"
27
+ require_relative "searchkick/relation_indexer"
28
+ require_relative "searchkick/results"
29
+ require_relative "searchkick/version"
30
+ require_relative "searchkick/where"
31
31
 
32
32
  # integrations
33
- require "searchkick/railtie" if defined?(Rails)
33
+ require_relative "searchkick/railtie" if defined?(Rails)
34
34
 
35
35
  module Searchkick
36
36
  # requires faraday
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 5.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-30 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubygems_version: 3.4.1
95
+ rubygems_version: 3.4.6
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Intelligent search made easy with Rails and Elasticsearch or OpenSearch