Commit ff407187088e5ee870bebca684412ec4078fee25

Authored by Andrew
1 parent 3b0eb3c6

Strip spaces from synonyms and added notice about two word max - fixes #913

@@ -299,6 +299,8 @@ end @@ -299,6 +299,8 @@ end
299 299
300 Call `Product.reindex` after changing synonyms. 300 Call `Product.reindex` after changing synonyms.
301 301
  302 +Synonyms cannot be more than two words at the moment.
  303 +
302 To read synonyms from a file, use: 304 To read synonyms from a file, use:
303 305
304 ```ruby 306 ```ruby
lib/searchkick/index_options.rb
@@ -174,7 +174,8 @@ module Searchkick @@ -174,7 +174,8 @@ module Searchkick
174 if synonyms.any? 174 if synonyms.any?
175 settings[:analysis][:filter][:searchkick_synonym] = { 175 settings[:analysis][:filter][:searchkick_synonym] = {
176 type: "synonym", 176 type: "synonym",
177 - synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }.map(&:downcase) 177 + # only remove a single space from synonyms so three-word synonyms will fail noisily instead of silently
  178 + synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.map { |s| s.sub(/\s+/, "") }.join(",") : s }.map(&:downcase)
178 } 179 }
179 # choosing a place for the synonym filter when stemming is not easy 180 # choosing a place for the synonym filter when stemming is not easy
180 # https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8 181 # https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8
test/test_helper.rb
@@ -399,7 +399,7 @@ class Product @@ -399,7 +399,7 @@ class Product
399 synonyms: [ 399 synonyms: [
400 ["clorox", "bleach"], 400 ["clorox", "bleach"],
401 ["scallion", "greenonion"], 401 ["scallion", "greenonion"],
402 - ["saranwrap", "plasticwrap"], 402 + ["saran wrap", "plastic wrap"],
403 ["qtip", "cottonswab"], 403 ["qtip", "cottonswab"],
404 ["burger", "hamburger"], 404 ["burger", "hamburger"],
405 ["bandaid", "bandag"], 405 ["bandaid", "bandag"],