Commit cbf2d24b4719a05b079ce883bf0730f2883c4d0b

Authored by Andrew Kane
1 parent 9bdf952e

Fixed synonyms for word partial matches - #214

CHANGELOG.md
... ... @@ -2,6 +2,7 @@
2 2  
3 3 - Added `below` option to misspellings to improve performance
4 4 - Added `similarity` option
  5 +- Fixed synonyms for `word_*` partial matches
5 6  
6 7 ## 1.0.3
7 8  
... ...
lib/searchkick/index.rb
... ... @@ -380,6 +380,10 @@ module Searchkick
380 380 # - Use directional synonyms where appropriate. You want to make sure that you're not injecting terms that are too general.
381 381 settings[:analysis][:analyzer][:default_index][:filter].insert(4, "searchkick_synonym")
382 382 settings[:analysis][:analyzer][:default_index][:filter] << "searchkick_synonym"
  383 +
  384 + %w(word_start word_middle word_end).each do |type|
  385 + settings[:analysis][:analyzer]["searchkick_#{type}_index".to_sym][:filter].insert(2, "searchkick_synonym")
  386 + end
383 387 end
384 388  
385 389 if options[:wordnet]
... ... @@ -391,6 +395,10 @@ module Searchkick
391 395  
392 396 settings[:analysis][:analyzer][:default_index][:filter].insert(4, "searchkick_wordnet")
393 397 settings[:analysis][:analyzer][:default_index][:filter] << "searchkick_wordnet"
  398 +
  399 + %w(word_start word_middle word_end).each do |type|
  400 + settings[:analysis][:analyzer]["searchkick_#{type}_index".to_sym][:filter].insert(2, "searchkick_wordnet")
  401 + end
394 402 end
395 403  
396 404 if options[:special_characters] == false
... ...
test/synonyms_test.rb
... ... @@ -41,6 +41,11 @@ class SynonymsTest &lt; Minitest::Test
41 41 assert_search "scallions", ["Green Onions"]
42 42 end
43 43  
  44 + def test_word_start
  45 + store_names ["Clorox Bleach", "Kroger Bleach"]
  46 + assert_search "clorox", ["Clorox Bleach", "Kroger Bleach"], fields: [{name: :word_start}]
  47 + end
  48 +
44 49 def test_wordnet
45 50 skip unless ENV["TEST_WORDNET"]
46 51 store_names ["Creature", "Beast", "Dragon"], Animal
... ...