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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01c6ee30f8005b48d1bff0515d2c3ad4a01b06aa75367be23ba3846905e2452c
4
- data.tar.gz: 2cd8509ad85e598405f4262f6bcd74d2f14214078b01f927a1e835c1bf2302f6
3
+ metadata.gz: '0218ffe2be1e6fcebea56dfa7c8d112e2f43580d69b513d064f48c4905c51934'
4
+ data.tar.gz: 79b21178f3db14d84179aa3db7cbf5dae4d7adfa98a9a72e7f92991c9bff2ce0
5
5
  SHA512:
6
- metadata.gz: 00fbf37d1aefa95abe59e749dd820992cc87f0ea12d751b37f80d1a734dc2cc7a0bcbc96bcf63f4a73bc874a9fff276c420f02fd6fe901143834f904cf243fc0
7
- data.tar.gz: c0b686a80177fd9d743c1bcea45369d59742e8152890cf70d93c4d3b4a67a72653f07b2daf9e8a464ec4d879207c4dbcddd26cee69377508d14c7dbaeaad6a58
6
+ metadata.gz: ce5ec190b6d754210ce88f48197cc0c08a32b6d33cc9a904385613ae3ec5bd7490a1d6c711bcf6cd3645636d64fe0c7e91bc23e009a32416194c8fbbe0119956
7
+ data.tar.gz: 3b306480292cfbcdc5854cc491f3700ecfd88715d37f879aa5715f0782ac86f380aa4828bec2866d2ea74186e445b9d4380d4696c8c2abcf1404207afa8ede18
@@ -1,3 +1,8 @@
1
+ ## 4.4.0 (2020-06-17)
2
+
3
+ - Added support for reloadable, multi-word, search time synonyms
4
+ - Fixed another deprecation warning in Ruby 2.7
5
+
1
6
  ## 4.3.1 (2020-05-13)
2
7
 
3
8
  - Fixed error with `exclude` in certain cases for Elasticsearch 7.7
data/README.md CHANGED
@@ -43,7 +43,7 @@ Plus:
43
43
 
44
44
  ## Getting Started
45
45
 
46
- [Install Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html). For Homebrew, use:
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 synonyms: [["pop", "soda"], ["burger", "hamburger"]]
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
- Synonyms cannot be multiple words at the moment.
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
- To read synonyms from a file, use:
347
+ ```txt
348
+ pop, soda
349
+ burger, hamburger
350
+ ```
351
+
352
+ Then use:
336
353
 
337
354
  ```ruby
338
- synonyms: -> { CSV.read("/some/path/synonyms.csv") }
355
+ search_synonyms: "synonyms.txt"
339
356
  ```
340
357
 
341
- For directional synonyms, use:
358
+ Add [elasticsearch-xpack](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-xpack) to your Gemfile:
342
359
 
343
360
  ```ruby
344
- synonyms: ["lightbulb => halogenlamp"]
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
- ### Tags and Dynamic Synonyms
370
+ #### Elasticsearch < 7.3
348
371
 
349
- 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 or tags without a full reindex. You can use a library like [ActsAsTaggableOn](https://github.com/mbleigh/acts-as-taggable-on) and do:
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
@@ -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",
@@ -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?
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "4.3.1"
2
+ VERSION = "4.4.0"
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.3.1
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-05-14 00:00:00.000000000 Z
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: []