Commit ff407187088e5ee870bebca684412ec4078fee25

Authored by Andrew
1 parent 3b0eb3c6

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

README.md
... ... @@ -299,6 +299,8 @@ end
299 299  
300 300 Call `Product.reindex` after changing synonyms.
301 301  
  302 +Synonyms cannot be more than two words at the moment.
  303 +
302 304 To read synonyms from a file, use:
303 305  
304 306 ```ruby
... ...
lib/searchkick/index_options.rb
... ... @@ -174,7 +174,8 @@ module Searchkick
174 174 if synonyms.any?
175 175 settings[:analysis][:filter][:searchkick_synonym] = {
176 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 180 # choosing a place for the synonym filter when stemming is not easy
180 181 # https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8
... ...
test/test_helper.rb
... ... @@ -399,7 +399,7 @@ class Product
399 399 synonyms: [
400 400 ["clorox", "bleach"],
401 401 ["scallion", "greenonion"],
402   - ["saranwrap", "plasticwrap"],
  402 + ["saran wrap", "plastic wrap"],
403 403 ["qtip", "cottonswab"],
404 404 ["burger", "hamburger"],
405 405 ["bandaid", "bandag"],
... ...