searchkick 4.5.0 → 4.5.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: 62e2797b9ad2290378febadeaab675b745b0318cd86a8219cada4774b529e290
4
- data.tar.gz: 8f0956287e802ce93a67940f6283f914b58b38aee2240f3ef101ae08e7428966
3
+ metadata.gz: 44f4a5255a208b7d24aa1b6d668808d3aff83a9ebb9f07a1a1a83fd9e3845738
4
+ data.tar.gz: 0ac096c02151a04a00751de140520547570b9c24fa2fccffd9d4761637b85531
5
5
  SHA512:
6
- metadata.gz: 34a3bf2400766d7a2e95c3ba430a42c08dc1cfeb6c2d26b4d6d2a04828fd5ee296f3b121b076f00502f7c0c849ff27e1e622635a70885ef7f1336f0b4b8709de
7
- data.tar.gz: 1c190e32fa87aa03a025a349dfc200ced4c28069c524acaa7b3c220628c58b9da2742ae4c924a87bc354f920a7486cae176d2bd7078a72a98568a068b20df290
6
+ metadata.gz: ff25ecdd74852fdbca33909d37445adbb42aa76785df75d9f1d9903d1dbee5712507d30a654dfaf829b9b6c0db0148cf48fbb4a257e3decf69e6c316c40b66fc
7
+ data.tar.gz: e07d8ddd9dbcf661db01948a7f20ad0b91d6427adddbbe987d571011983046650bd21726f74a2d0d11caaf9d49cd83b70a92738dc1cb21346e2c74009a1c494c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 4.5.1 (2021-08-03)
2
+
3
+ - Improved performance of reindex queue
4
+
1
5
  ## 4.5.0 (2021-06-07)
2
6
 
3
7
  - Added experimental support for OpenSearch
data/README.md CHANGED
@@ -20,7 +20,7 @@ Plus:
20
20
  - autocomplete
21
21
  - “Did you mean” suggestions
22
22
  - supports many languages
23
- - works with ActiveRecord, Mongoid, and NoBrainer
23
+ - works with Active Record, Mongoid, and NoBrainer
24
24
 
25
25
  Check out [Searchjoy](https://github.com/ankane/searchjoy) for analytics and [Autosuggest](https://github.com/ankane/autosuggest) for query suggestions
26
26
 
@@ -45,11 +45,11 @@ Check out [Searchjoy](https://github.com/ankane/searchjoy) for analytics and [Au
45
45
 
46
46
  ## Getting Started
47
47
 
48
- [Install Elasticsearch](https://www.elastic.co/downloads/elasticsearch). For Homebrew, use:
48
+ Install [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) or [OpenSearch](https://opensearch.org/downloads.html) (OpenSearch support is experimental). For Homebrew, use:
49
49
 
50
50
  ```sh
51
- brew install elasticsearch
52
- brew services start elasticsearch
51
+ brew install elasticsearch # or opensearch
52
+ brew services start elasticsearch # or opensearch
53
53
  ```
54
54
 
55
55
  Add this line to your application’s Gemfile:
@@ -58,7 +58,7 @@ Add this line to your application’s Gemfile:
58
58
  gem 'searchkick'
59
59
  ```
60
60
 
61
- The latest version works with Elasticsearch 6 and 7. For Elasticsearch 5, use version 3.1.3 and [this readme](https://github.com/ankane/searchkick/blob/v3.1.3/README.md).
61
+ The latest version works with Elasticsearch 6 and 7 and OpenSearch 1. For Elasticsearch 5, use version 3.1.3 and [this readme](https://github.com/ankane/searchkick/blob/v3.1.3/README.md).
62
62
 
63
63
  Add searchkick to models you want to search.
64
64
 
@@ -649,7 +649,7 @@ class Product < ApplicationRecord
649
649
  def search_data
650
650
  {
651
651
  name: name,
652
- conversions: searches.group(:query).uniq.count(:user_id)
652
+ conversions: searches.group(:query).distinct.count(:user_id)
653
653
  # {"ice cream" => 234, "chocolate" => 67, "cream" => 2}
654
654
  }
655
655
  end
@@ -1212,12 +1212,18 @@ FactoryBot.create(:product, :some_trait, :reindex, some_attribute: "foo")
1212
1212
 
1213
1213
  ### GitHub Actions
1214
1214
 
1215
- Check out [setup-elasticsearch](https://github.com/ankane/setup-elasticsearch) for an easy way to install Elasticsearch.
1215
+ Check out [setup-elasticsearch](https://github.com/ankane/setup-elasticsearch) for an easy way to install Elasticsearch:
1216
1216
 
1217
1217
  ```yml
1218
1218
  - uses: ankane/setup-elasticsearch@v1
1219
1219
  ```
1220
1220
 
1221
+ And [setup-opensearch](https://github.com/ankane/setup-opensearch) for an easy way to install OpenSearch:
1222
+
1223
+ ```yml
1224
+ - uses: ankane/setup-opensearch@v1
1225
+ ```
1226
+
1221
1227
  ## Deployment
1222
1228
 
1223
1229
  Searchkick uses `ENV["ELASTICSEARCH_URL"]` for the Elasticsearch server. This defaults to `http://localhost:9200`.
@@ -1580,14 +1586,14 @@ class ReindexConversionsJob < ApplicationJob
1580
1586
  # get records that have a recent conversion
1581
1587
  recently_converted_ids =
1582
1588
  Searchjoy::Search.where("convertable_type = ? AND converted_at > ?", class_name, 1.day.ago)
1583
- .order(:convertable_id).uniq.pluck(:convertable_id)
1589
+ .order(:convertable_id).distinct.pluck(:convertable_id)
1584
1590
 
1585
1591
  # split into groups
1586
1592
  recently_converted_ids.in_groups_of(1000, false) do |ids|
1587
1593
  # fetch conversions
1588
1594
  conversions =
1589
1595
  Searchjoy::Search.where(convertable_id: ids, convertable_type: class_name)
1590
- .group(:convertable_id, :query).uniq.count(:user_id)
1596
+ .group(:convertable_id, :query).distinct.count(:user_id)
1591
1597
 
1592
1598
  # group conversions by record
1593
1599
  conversions_by_record = {}
@@ -1839,7 +1845,7 @@ class Product < ApplicationRecord
1839
1845
  def search_data
1840
1846
  {
1841
1847
  name: name,
1842
- unique_user_conversions: searches.group(:query).uniq.count(:user_id),
1848
+ unique_user_conversions: searches.group(:query).distinct.count(:user_id),
1843
1849
  # {"ice cream" => 234, "chocolate" => 67, "cream" => 2}
1844
1850
  total_conversions: searches.group(:query).count
1845
1851
  # {"ice cream" => 412, "chocolate" => 117, "cream" => 6}
@@ -11,7 +11,7 @@ module Searchkick
11
11
  if record_ids.any?
12
12
  batch_options = {
13
13
  class_name: class_name,
14
- record_ids: record_ids,
14
+ record_ids: record_ids.uniq,
15
15
  index_name: index_name
16
16
  }
17
17
 
@@ -864,10 +864,11 @@ module Searchkick
864
864
  }
865
865
  end
866
866
 
867
- # TODO id transformation for arrays
868
867
  def set_order(payload)
869
868
  order = options[:order].is_a?(Enumerable) ? options[:order] : {options[:order] => :asc}
870
869
  id_field = :_id
870
+ # TODO no longer map id to _id in Searchkick 5
871
+ # since sorting on _id is deprecated in Elasticsearch
871
872
  payload[:sort] = order.is_a?(Array) ? order : Hash[order.map { |k, v| [k.to_s == "id" ? id_field : k, v] }]
872
873
  end
873
874
 
@@ -14,11 +14,17 @@ module Searchkick
14
14
 
15
15
  # TODO use reliable queuing
16
16
  def reserve(limit: 1000)
17
- record_ids = Set.new
18
- while record_ids.size < limit && (record_id = Searchkick.with_redis { |r| r.rpop(redis_key) })
19
- record_ids << record_id
17
+ if supports_rpop_with_count?
18
+ Searchkick.with_redis { |r| r.call("rpop", redis_key, limit) }
19
+ else
20
+ record_ids = []
21
+ Searchkick.with_redis do |r|
22
+ while record_ids.size < limit && (record_id = r.rpop(redis_key))
23
+ record_ids << record_id
24
+ end
25
+ end
26
+ record_ids
20
27
  end
21
- record_ids.to_a
22
28
  end
23
29
 
24
30
  def clear
@@ -34,5 +40,13 @@ module Searchkick
34
40
  def redis_key
35
41
  "searchkick:reindex_queue:#{name}"
36
42
  end
43
+
44
+ def supports_rpop_with_count?
45
+ redis_version >= Gem::Version.new("6.2")
46
+ end
47
+
48
+ def redis_version
49
+ @redis_version ||= Searchkick.with_redis { |r| Gem::Version.new(r.info["redis_version"]) }
50
+ end
37
51
  end
38
52
  end
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "4.5.0"
2
+ VERSION = "4.5.1"
3
3
  end
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: 4.5.0
4
+ version: 4.5.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: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.2.3
105
+ rubygems_version: 3.2.22
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Intelligent search made easy with Rails and Elasticsearch