Commit a62efa364c6eb5af834022eeae8087a115593914
1 parent
a91714e8
Exists in
master
and in
21 other branches
Added support for directional synonyms - closes #731
Showing
4 changed files
with
13 additions
and
2 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/index_options.rb
... | ... | @@ -179,7 +179,7 @@ module Searchkick |
179 | 179 | if synonyms.any? |
180 | 180 | settings[:analysis][:filter][:searchkick_synonym] = { |
181 | 181 | type: "synonym", |
182 | - synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.join(",") } | |
182 | + synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s } | |
183 | 183 | } |
184 | 184 | # choosing a place for the synonym filter when stemming is not easy |
185 | 185 | # https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8 | ... | ... |
test/synonyms_test.rb
... | ... | @@ -51,4 +51,12 @@ class SynonymsTest < Minitest::Test |
51 | 51 | store_names ["Creature", "Beast", "Dragon"], Animal |
52 | 52 | assert_search "animal", ["Creature", "Beast"], {}, Animal |
53 | 53 | end |
54 | + | |
55 | + def test_directional | |
56 | + store_names ["Lightbulb", "Green Onions", "Led"] | |
57 | + assert_search "led", ["Lightbulb", "Led"] | |
58 | + assert_search "Lightbulb", ["Lightbulb"] | |
59 | + assert_search "Halogen Lamp", ["Lightbulb"] | |
60 | + assert_search "onions", ["Green Onions"] | |
61 | + end | |
54 | 62 | end | ... | ... |
test/test_helper.rb
... | ... | @@ -273,7 +273,9 @@ class Product |
273 | 273 | ["saranwrap", "plasticwrap"], |
274 | 274 | ["qtip", "cottonswab"], |
275 | 275 | ["burger", "hamburger"], |
276 | - ["bandaid", "bandag"] | |
276 | + ["bandaid", "bandag"], | |
277 | + "lightbulb => led,lightbulb", | |
278 | + "lightbulb => halogenlamp" | |
277 | 279 | ], |
278 | 280 | autocomplete: [:name], |
279 | 281 | suggest: [:name, :color], | ... | ... |