Commit c56b1051ceadca7e2b0724af0f633b8b8a0249e8
1 parent
f739ce41
Exists in
search_as_you_type
Added synonyms
Showing
4 changed files
with
19 additions
and
6 deletions
Show diff stats
lib/searchkick/index_options.rb
... | ... | @@ -109,11 +109,16 @@ module Searchkick |
109 | 109 | tokenizer: "standard", |
110 | 110 | filter: ["lowercase", "asciifolding", "reverse", "searchkick_edge_ngram", "reverse"] |
111 | 111 | }, |
112 | - searchkick_search_as_you_type: { | |
112 | + searchkick_search_as_you_type_index: { | |
113 | 113 | type: "custom", |
114 | 114 | tokenizer: "standard", |
115 | 115 | filter: ["lowercase", "asciifolding"] |
116 | 116 | }, |
117 | + searchkick_search_as_you_type_search: { | |
118 | + type: "custom", | |
119 | + tokenizer: "standard", | |
120 | + filter: ["lowercase", "asciifolding"] | |
121 | + } | |
117 | 122 | }, |
118 | 123 | filter: { |
119 | 124 | searchkick_index_shingle: { |
... | ... | @@ -330,7 +335,7 @@ module Searchkick |
330 | 335 | mapping_options[:searchable].delete("_all") |
331 | 336 | |
332 | 337 | analyzed_field_options = {type: default_type, index: true, analyzer: default_analyzer} |
333 | - search_as_you_type_options = {type: "search_as_you_type", analyzer: "searchkick_search_as_you_type"} | |
338 | + search_as_you_type_options = {type: "search_as_you_type", analyzer: "searchkick_search_as_you_type_index"} | |
334 | 339 | |
335 | 340 | mapping_options.values.flatten.uniq.each do |field| |
336 | 341 | fields = {} |
... | ... | @@ -483,7 +488,7 @@ module Searchkick |
483 | 488 | end |
484 | 489 | settings[:analysis][:filter][:searchkick_synonym_graph] = synonym_graph |
485 | 490 | |
486 | - [:searchkick_search2, :searchkick_word_search].each do |analyzer| | |
491 | + [:searchkick_search2, :searchkick_word_search, :searchkick_search_as_you_type_search].each do |analyzer| | |
487 | 492 | settings[:analysis][:analyzer][analyzer][:filter].insert(2, "searchkick_synonym_graph") |
488 | 493 | end |
489 | 494 | end | ... | ... |
lib/searchkick/query.rb
... | ... | @@ -367,9 +367,9 @@ module Searchkick |
367 | 367 | exclude_analyzer = "keyword" |
368 | 368 | elsif field.end_with?(".search_as_you_type") |
369 | 369 | queries_to_add << { |
370 | - multi_match: shared_options.merge(type: "bool_prefix", fields: [field, "#{field}._2gram", "#{field}._3gram"]) | |
370 | + multi_match: shared_options.merge(type: "bool_prefix", analyzer: "searchkick_search_as_you_type_search", fields: [field, "#{field}._2gram", "#{field}._3gram"]) | |
371 | 371 | } |
372 | - exclude_analyzer = "searchkick_search_as_you_type" | |
372 | + exclude_analyzer = "searchkick_search_as_you_type_search" | |
373 | 373 | else |
374 | 374 | analyzer = field =~ /\.word_(start|middle|end)\z/ ? "searchkick_word_search" : "searchkick_autocomplete_search" |
375 | 375 | qs << shared_options.merge(analyzer: analyzer) | ... | ... |
test/models/item.rb
test/search_as_you_type_test.rb
... | ... | @@ -31,6 +31,12 @@ class SearchAsYouTypeTest < Minitest::Test |
31 | 31 | assert_order "one two three", expected |
32 | 32 | end |
33 | 33 | |
34 | + # search time synonyms do not match partial words | |
35 | + def test_search_synonyms | |
36 | + store_names ["Hello", "Goodbye"] | |
37 | + assert_search "greeting", ["Hello"] | |
38 | + end | |
39 | + | |
34 | 40 | def default_model |
35 | 41 | Item |
36 | 42 | end | ... | ... |