searchkick 4.6.2 → 4.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +7 -11
- data/lib/searchkick/index.rb +15 -11
- data/lib/searchkick/query.rb +1 -1
- data/lib/searchkick/record_indexer.rb +3 -2
- data/lib/searchkick/results.rb +4 -4
- data/lib/searchkick/version.rb +1 -1
- data/lib/searchkick.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6937cc5456846216a4ea52c2274dfc43220e7f848dde276f0102ce48de3184a6
|
4
|
+
data.tar.gz: 0bfcc6a4e5a893629f9cac734498efba357dbd19e6641c21af7ea8e82f94f1ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e7e41267464a8d32641edf6a578a6c65a97170f40e2f129effc8ff1da4144c30f00b88e52ddf6c51ffba366ec3cdfb263890e1539165ad47581c1723bf6b992
|
7
|
+
data.tar.gz: 49511b973a2fb7dce8d7952c0e5ccd676db357d2d965f46321e1b56bd5213f9f0c44f461f0010344f585e799dcbb13d9c4482772e20ab996462be86430c040cf
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 4.6.3 (2021-11-19)
|
2
|
+
|
3
|
+
- Added support for reloadable synonyms for OpenSearch
|
4
|
+
- Added experimental support for `opensearch` gem
|
5
|
+
- Removed `elasticsearch-xpack` dependency for reloadable synonyms
|
6
|
+
|
1
7
|
## 4.6.2 (2021-11-15)
|
2
8
|
|
3
9
|
- Added support for beginless ranges to `where` option
|
data/README.md
CHANGED
@@ -375,9 +375,9 @@ search_synonyms: ["lightbulb => halogenlamp"]
|
|
375
375
|
|
376
376
|
The above approach works well when your synonym list is static, but in practice, this is often not the case. When you analyze search conversions, you often want to add new synonyms without a full reindex.
|
377
377
|
|
378
|
-
#### Elasticsearch 7.3+
|
378
|
+
#### Elasticsearch 7.3+ or OpenSearch
|
379
379
|
|
380
|
-
For Elasticsearch 7.3
|
380
|
+
For Elasticsearch 7.3+ or OpenSearch, we recommend placing synonyms in a file on the Elasticsearch or OpenSearch server (in the `config` directory). This allows you to reload synonyms without reindexing.
|
381
381
|
|
382
382
|
```txt
|
383
383
|
pop, soda
|
@@ -387,22 +387,18 @@ burger, hamburger
|
|
387
387
|
Then use:
|
388
388
|
|
389
389
|
```ruby
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
Add [elasticsearch-xpack](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-xpack) to your Gemfile:
|
394
|
-
|
395
|
-
```ruby
|
396
|
-
gem 'elasticsearch-xpack', '>= 7.8', '< 7.14'
|
390
|
+
class Product < ApplicationRecord
|
391
|
+
searchkick search_synonyms: "synonyms.txt"
|
392
|
+
end
|
397
393
|
```
|
398
394
|
|
399
|
-
And
|
395
|
+
And reload with:
|
400
396
|
|
401
397
|
```ruby
|
402
398
|
Product.search_index.reload_synonyms
|
403
399
|
```
|
404
400
|
|
405
|
-
#### Elasticsearch < 7.3
|
401
|
+
#### Elasticsearch < 7.3
|
406
402
|
|
407
403
|
You can use a library like [ActsAsTaggableOn](https://github.com/mbleigh/acts-as-taggable-on) and do:
|
408
404
|
|
data/lib/searchkick/index.rb
CHANGED
@@ -84,7 +84,8 @@ module Searchkick
|
|
84
84
|
old_indices =
|
85
85
|
begin
|
86
86
|
client.indices.get_alias(name: name).keys
|
87
|
-
rescue
|
87
|
+
rescue => e
|
88
|
+
raise e unless Searchkick.not_found_error?(e)
|
88
89
|
{}
|
89
90
|
end
|
90
91
|
actions = old_indices.map { |old_name| {remove: {index: old_name, alias: name}} } + [{add: {index: new_name, alias: name}}]
|
@@ -109,7 +110,8 @@ module Searchkick
|
|
109
110
|
else
|
110
111
|
client.indices.get_aliases
|
111
112
|
end
|
112
|
-
rescue
|
113
|
+
rescue => e
|
114
|
+
raise e unless Searchkick.not_found_error?(e)
|
113
115
|
{}
|
114
116
|
end
|
115
117
|
indices = indices.select { |_k, v| v.empty? || v["aliases"].empty? } if unaliased
|
@@ -178,13 +180,15 @@ module Searchkick
|
|
178
180
|
end
|
179
181
|
|
180
182
|
def reload_synonyms
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
183
|
+
if Searchkick.opensearch?
|
184
|
+
client.transport.perform_request "POST", "_plugins/_refresh_search_analyzers/#{CGI.escape(name)}"
|
185
|
+
else
|
186
|
+
raise Error, "Requires Elasticsearch 7.3+" if Searchkick.server_below?("7.3.0")
|
187
|
+
begin
|
188
|
+
client.transport.perform_request("GET", "#{CGI.escape(name)}/_reload_search_analyzers")
|
189
|
+
rescue Elasticsearch::Transport::Transport::Errors::MethodNotAllowed
|
190
|
+
raise Error, "Requires non-OSS version of Elasticsearch"
|
191
|
+
end
|
188
192
|
end
|
189
193
|
end
|
190
194
|
|
@@ -361,8 +365,8 @@ module Searchkick
|
|
361
365
|
index.refresh
|
362
366
|
true
|
363
367
|
end
|
364
|
-
rescue
|
365
|
-
if e.message.include?("No handler for type [text]")
|
368
|
+
rescue => e
|
369
|
+
if Searchkick.transport_error?(e) && e.message.include?("No handler for type [text]")
|
366
370
|
raise UnsupportedVersionError, "This version of Searchkick requires Elasticsearch 6 or greater"
|
367
371
|
end
|
368
372
|
|
data/lib/searchkick/query.rb
CHANGED
@@ -113,7 +113,7 @@ module Searchkick
|
|
113
113
|
|
114
114
|
# no easy way to tell which host the client will use
|
115
115
|
host =
|
116
|
-
if
|
116
|
+
if Searchkick.client.transport.respond_to?(:transport)
|
117
117
|
Searchkick.client.transport.transport.hosts.first
|
118
118
|
else
|
119
119
|
Searchkick.client.transport.hosts.first
|
@@ -64,8 +64,9 @@ module Searchkick
|
|
64
64
|
if record.destroyed? || !record.persisted? || !record.should_index?
|
65
65
|
begin
|
66
66
|
index.remove(record)
|
67
|
-
rescue
|
68
|
-
|
67
|
+
rescue => e
|
68
|
+
raise e unless Searchkick.not_found_error?(e)
|
69
|
+
# do nothing if not found
|
69
70
|
end
|
70
71
|
else
|
71
72
|
if method_name
|
data/lib/searchkick/results.rb
CHANGED
@@ -195,8 +195,8 @@ module Searchkick
|
|
195
195
|
begin
|
196
196
|
# TODO Active Support notifications for this scroll call
|
197
197
|
Searchkick::Results.new(@klass, Searchkick.client.scroll(scroll: options[:scroll], body: {scroll_id: scroll_id}), @options)
|
198
|
-
rescue
|
199
|
-
if e
|
198
|
+
rescue => e
|
199
|
+
if Searchkick.not_found_error?(e) && e.message =~ /search_context_missing_exception/i
|
200
200
|
raise Searchkick::Error, "Scroll id has expired"
|
201
201
|
else
|
202
202
|
raise e
|
@@ -211,8 +211,8 @@ module Searchkick
|
|
211
211
|
# not required as scroll will expire
|
212
212
|
# but there is a cost to open scrolls
|
213
213
|
Searchkick.client.clear_scroll(scroll_id: scroll_id)
|
214
|
-
rescue
|
215
|
-
|
214
|
+
rescue => e
|
215
|
+
raise e unless Searchkick.transport_error?(e)
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
data/lib/searchkick/version.rb
CHANGED
data/lib/searchkick.rb
CHANGED
@@ -34,6 +34,7 @@ module Searchkick
|
|
34
34
|
class Error < StandardError; end
|
35
35
|
class MissingIndexError < Error; end
|
36
36
|
class UnsupportedVersionError < Error; end
|
37
|
+
# TODO switch to Error
|
37
38
|
class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end
|
38
39
|
class DangerousOperation < Error; end
|
39
40
|
class ImportError < Error; end
|
@@ -278,6 +279,18 @@ module Searchkick
|
|
278
279
|
!Mongoid::Threaded.current_scope(klass).nil?
|
279
280
|
end
|
280
281
|
end
|
282
|
+
|
283
|
+
# private
|
284
|
+
def self.not_found_error?(e)
|
285
|
+
(defined?(Elasticsearch) && e.is_a?(Elasticsearch::Transport::Transport::Errors::NotFound)) ||
|
286
|
+
(defined?(OpenSearch) && e.is_a?(OpenSearch::Transport::Transport::Errors::NotFound))
|
287
|
+
end
|
288
|
+
|
289
|
+
# private
|
290
|
+
def self.transport_error?(e)
|
291
|
+
(defined?(Elasticsearch) && e.is_a?(Elasticsearch::Transport::Transport::Error)) ||
|
292
|
+
(defined?(OpenSearch) && e.is_a?(OpenSearch::Transport::Transport::Error))
|
293
|
+
end
|
281
294
|
end
|
282
295
|
|
283
296
|
require "active_model/callbacks"
|
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.6.
|
4
|
+
version: 4.6.3
|
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-11-
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|