searchkick 4.3.1 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +33 -10
- data/lib/searchkick/bulk_indexer.rb +1 -1
- data/lib/searchkick/index.rb +7 -0
- data/lib/searchkick/index_options.rb +24 -2
- data/lib/searchkick/model.rb +1 -1
- data/lib/searchkick/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0218ffe2be1e6fcebea56dfa7c8d112e2f43580d69b513d064f48c4905c51934'
|
4
|
+
data.tar.gz: 79b21178f3db14d84179aa3db7cbf5dae4d7adfa98a9a72e7f92991c9bff2ce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce5ec190b6d754210ce88f48197cc0c08a32b6d33cc9a904385613ae3ec5bd7490a1d6c711bcf6cd3645636d64fe0c7e91bc23e009a32416194c8fbbe0119956
|
7
|
+
data.tar.gz: 3b306480292cfbcdc5854cc491f3700ecfd88715d37f879aa5715f0782ac86f380aa4828bec2866d2ea74186e445b9d4380d4696c8c2abcf1404207afa8ede18
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -43,7 +43,7 @@ Plus:
|
|
43
43
|
|
44
44
|
## Getting Started
|
45
45
|
|
46
|
-
[Install Elasticsearch](https://www.elastic.co/
|
46
|
+
[Install Elasticsearch](https://www.elastic.co/downloads/elasticsearch). For Homebrew, use:
|
47
47
|
|
48
48
|
```sh
|
49
49
|
brew install elasticsearch
|
@@ -324,29 +324,52 @@ A few languages require plugins:
|
|
324
324
|
|
325
325
|
```ruby
|
326
326
|
class Product < ApplicationRecord
|
327
|
-
searchkick
|
327
|
+
searchkick search_synonyms: [["pop", "soda"], ["burger", "hamburger"]]
|
328
328
|
end
|
329
329
|
```
|
330
330
|
|
331
|
-
Call `Product.reindex` after changing synonyms.
|
331
|
+
Call `Product.reindex` after changing synonyms. Synonyms are applied at search time before stemming, and can be a single word or multiple words.
|
332
332
|
|
333
|
-
|
333
|
+
For directional synonyms, use:
|
334
|
+
|
335
|
+
```ruby
|
336
|
+
synonyms: ["lightbulb => halogenlamp"]
|
337
|
+
```
|
338
|
+
|
339
|
+
### Dynamic Synonyms
|
340
|
+
|
341
|
+
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.
|
342
|
+
|
343
|
+
#### Elasticsearch 7.3+
|
344
|
+
|
345
|
+
For Elasticsearch 7.3+, we recommend placing synonyms in a file on the Elasticsearch server (in the `config` directory). This allows you to reload synonyms without reindexing.
|
334
346
|
|
335
|
-
|
347
|
+
```txt
|
348
|
+
pop, soda
|
349
|
+
burger, hamburger
|
350
|
+
```
|
351
|
+
|
352
|
+
Then use:
|
336
353
|
|
337
354
|
```ruby
|
338
|
-
|
355
|
+
search_synonyms: "synonyms.txt"
|
339
356
|
```
|
340
357
|
|
341
|
-
|
358
|
+
Add [elasticsearch-xpack](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-xpack) to your Gemfile:
|
342
359
|
|
343
360
|
```ruby
|
344
|
-
|
361
|
+
gem 'elasticsearch-xpack', '>= 7.8.0.pre'
|
362
|
+
```
|
363
|
+
|
364
|
+
And use:
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
Product.search_index.reload_synonyms
|
345
368
|
```
|
346
369
|
|
347
|
-
|
370
|
+
#### Elasticsearch < 7.3
|
348
371
|
|
349
|
-
|
372
|
+
You can use a library like [ActsAsTaggableOn](https://github.com/mbleigh/acts-as-taggable-on) and do:
|
350
373
|
|
351
374
|
```ruby
|
352
375
|
class Product < ApplicationRecord
|
@@ -141,7 +141,7 @@ module Searchkick
|
|
141
141
|
|
142
142
|
def bulk_reindex_job(scope, batch_id, options)
|
143
143
|
Searchkick.with_redis { |r| r.sadd(batches_key, batch_id) }
|
144
|
-
Searchkick::BulkReindexJob.perform_later({
|
144
|
+
Searchkick::BulkReindexJob.perform_later(**{
|
145
145
|
class_name: scope.searchkick_options[:class_name],
|
146
146
|
index_name: index.name,
|
147
147
|
batch_id: batch_id
|
data/lib/searchkick/index.rb
CHANGED
@@ -174,6 +174,13 @@ module Searchkick
|
|
174
174
|
Searchkick.search(like_text, model: record.class, **options)
|
175
175
|
end
|
176
176
|
|
177
|
+
def reload_synonyms
|
178
|
+
require "elasticsearch/xpack"
|
179
|
+
raise Error, "Requires Elasticsearch 7.3+" if Searchkick.server_below?("7.3.0")
|
180
|
+
raise Error, "Requires elasticsearch-xpack 7.8+" unless client.xpack.respond_to?(:indices)
|
181
|
+
client.xpack.indices.reload_search_analyzers(index: name)
|
182
|
+
end
|
183
|
+
|
177
184
|
# queue
|
178
185
|
|
179
186
|
def reindex_queue
|
@@ -7,6 +7,7 @@ module Searchkick
|
|
7
7
|
|
8
8
|
below62 = Searchkick.server_below?("6.2.0")
|
9
9
|
below70 = Searchkick.server_below?("7.0.0")
|
10
|
+
below73 = Searchkick.server_below?("7.3.0")
|
10
11
|
|
11
12
|
if below70
|
12
13
|
index_type = options[:_type]
|
@@ -285,9 +286,7 @@ module Searchkick
|
|
285
286
|
|
286
287
|
# synonyms
|
287
288
|
synonyms = options[:synonyms] || []
|
288
|
-
|
289
289
|
synonyms = synonyms.call if synonyms.respond_to?(:call)
|
290
|
-
|
291
290
|
if synonyms.any?
|
292
291
|
settings[:analysis][:filter][:searchkick_synonym] = {
|
293
292
|
type: "synonym",
|
@@ -310,6 +309,29 @@ module Searchkick
|
|
310
309
|
end
|
311
310
|
end
|
312
311
|
|
312
|
+
search_synonyms = options[:search_synonyms] || []
|
313
|
+
search_synonyms = search_synonyms.call if search_synonyms.respond_to?(:call)
|
314
|
+
if search_synonyms.is_a?(String) || search_synonyms.any?
|
315
|
+
if search_synonyms.is_a?(String)
|
316
|
+
synonym_graph = {
|
317
|
+
type: "synonym_graph",
|
318
|
+
synonyms_path: search_synonyms
|
319
|
+
}
|
320
|
+
synonym_graph[:updateable] = true unless below73
|
321
|
+
else
|
322
|
+
synonym_graph = {
|
323
|
+
type: "synonym_graph",
|
324
|
+
# TODO confirm this is correct
|
325
|
+
synonyms: search_synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }.map(&:downcase)
|
326
|
+
}
|
327
|
+
end
|
328
|
+
settings[:analysis][:filter][:searchkick_synonym_graph] = synonym_graph
|
329
|
+
|
330
|
+
[:searchkick_search2, :searchkick_word_search].each do |analyzer|
|
331
|
+
settings[:analysis][:analyzer][analyzer][:filter].insert(2, "searchkick_synonym_graph")
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
313
335
|
if options[:wordnet]
|
314
336
|
settings[:analysis][:filter][:searchkick_wordnet] = {
|
315
337
|
type: "synonym",
|
data/lib/searchkick/model.rb
CHANGED
@@ -5,7 +5,7 @@ module Searchkick
|
|
5
5
|
|
6
6
|
unknown_keywords = options.keys - [:_all, :_type, :batch_size, :callbacks, :case_sensitive, :conversions, :deep_paging, :default_fields,
|
7
7
|
:filterable, :geo_shape, :highlight, :ignore_above, :index_name, :index_prefix, :inheritance, :language,
|
8
|
-
:locations, :mappings, :match, :merge_mappings, :routing, :searchable, :settings, :similarity,
|
8
|
+
:locations, :mappings, :match, :merge_mappings, :routing, :searchable, :search_synonyms, :settings, :similarity,
|
9
9
|
:special_characters, :stem, :stem_conversions, :suggest, :synonyms, :text_end,
|
10
10
|
:text_middle, :text_start, :word, :wordnet, :word_end, :word_middle, :word_start]
|
11
11
|
raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any?
|
data/lib/searchkick/version.rb
CHANGED
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.
|
4
|
+
version: 4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: elasticsearch-xpack
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 7.8.0.pre
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 7.8.0.pre
|
97
111
|
description:
|
98
112
|
email: andrew@chartkick.com
|
99
113
|
executables: []
|