Commit a62efa364c6eb5af834022eeae8087a115593914

Authored by Andrew Kane
1 parent a91714e8

Added support for directional synonyms - closes #731

CHANGELOG.md
1 1 ## 1.4.2 [unreleased]
2 2  
  3 +- Added support for directional synonyms
3 4 - Easier AWS setup
4 5  
5 6 ## 1.4.1
... ...
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],
... ...