From ff407187088e5ee870bebca684412ec4078fee25 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 14 Feb 2018 21:28:31 -0800 Subject: [PATCH] Strip spaces from synonyms and added notice about two word max - fixes #913 --- README.md | 2 ++ lib/searchkick/index_options.rb | 3 ++- test/test_helper.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2af68a6..a2c1919 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,8 @@ end Call `Product.reindex` after changing synonyms. +Synonyms cannot be more than two words at the moment. + To read synonyms from a file, use: ```ruby diff --git a/lib/searchkick/index_options.rb b/lib/searchkick/index_options.rb index 225cbdc..1cf0d75 100644 --- a/lib/searchkick/index_options.rb +++ b/lib/searchkick/index_options.rb @@ -174,7 +174,8 @@ module Searchkick if synonyms.any? settings[:analysis][:filter][:searchkick_synonym] = { type: "synonym", - synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }.map(&:downcase) + # only remove a single space from synonyms so three-word synonyms will fail noisily instead of silently + synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.map { |s| s.sub(/\s+/, "") }.join(",") : s }.map(&:downcase) } # choosing a place for the synonym filter when stemming is not easy # https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8 diff --git a/test/test_helper.rb b/test/test_helper.rb index 1e4272d..b22b63b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -399,7 +399,7 @@ class Product synonyms: [ ["clorox", "bleach"], ["scallion", "greenonion"], - ["saranwrap", "plasticwrap"], + ["saran wrap", "plastic wrap"], ["qtip", "cottonswab"], ["burger", "hamburger"], ["bandaid", "bandag"], -- libgit2 0.21.0