Commit cbf2d24b4719a05b079ce883bf0730f2883c4d0b
1 parent
9bdf952e
Exists in
master
and in
21 other branches
Fixed synonyms for word partial matches - #214
Showing
3 changed files
with
14 additions
and
0 deletions
Show diff stats
CHANGELOG.md
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | - Added `below` option to misspellings to improve performance | 3 | - Added `below` option to misspellings to improve performance |
4 | - Added `similarity` option | 4 | - Added `similarity` option |
5 | +- Fixed synonyms for `word_*` partial matches | ||
5 | 6 | ||
6 | ## 1.0.3 | 7 | ## 1.0.3 |
7 | 8 |
lib/searchkick/index.rb
@@ -380,6 +380,10 @@ module Searchkick | @@ -380,6 +380,10 @@ module Searchkick | ||
380 | # - Use directional synonyms where appropriate. You want to make sure that you're not injecting terms that are too general. | 380 | # - Use directional synonyms where appropriate. You want to make sure that you're not injecting terms that are too general. |
381 | settings[:analysis][:analyzer][:default_index][:filter].insert(4, "searchkick_synonym") | 381 | settings[:analysis][:analyzer][:default_index][:filter].insert(4, "searchkick_synonym") |
382 | settings[:analysis][:analyzer][:default_index][:filter] << "searchkick_synonym" | 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 | end | 387 | end |
384 | 388 | ||
385 | if options[:wordnet] | 389 | if options[:wordnet] |
@@ -391,6 +395,10 @@ module Searchkick | @@ -391,6 +395,10 @@ module Searchkick | ||
391 | 395 | ||
392 | settings[:analysis][:analyzer][:default_index][:filter].insert(4, "searchkick_wordnet") | 396 | settings[:analysis][:analyzer][:default_index][:filter].insert(4, "searchkick_wordnet") |
393 | settings[:analysis][:analyzer][:default_index][:filter] << "searchkick_wordnet" | 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 | end | 402 | end |
395 | 403 | ||
396 | if options[:special_characters] == false | 404 | if options[:special_characters] == false |
test/synonyms_test.rb
@@ -41,6 +41,11 @@ class SynonymsTest < Minitest::Test | @@ -41,6 +41,11 @@ class SynonymsTest < Minitest::Test | ||
41 | assert_search "scallions", ["Green Onions"] | 41 | assert_search "scallions", ["Green Onions"] |
42 | end | 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 | def test_wordnet | 49 | def test_wordnet |
45 | skip unless ENV["TEST_WORDNET"] | 50 | skip unless ENV["TEST_WORDNET"] |
46 | store_names ["Creature", "Beast", "Dragon"], Animal | 51 | store_names ["Creature", "Beast", "Dragon"], Animal |