Commit c8e6b60b07226b496a979d5c74e3e538ab9d8727
1 parent
c41e6c2f
Exists in
master
and in
21 other branches
Added exact matches
Showing
6 changed files
with
24 additions
and
3 deletions
Show diff stats
CHANGELOG.md
README.md
lib/searchkick/query.rb
... | ... | @@ -100,7 +100,15 @@ module Searchkick |
100 | 100 | ] |
101 | 101 | end |
102 | 102 | else |
103 | - analyzer = field.match(/\.word_(start|middle|end)\z/) ? "searchkick_word_search" : "searchkick_autocomplete_search" | |
103 | + analyzer = | |
104 | + case field | |
105 | + when /\.word_(start|middle|end)\z/ | |
106 | + "searchkick_word_search" | |
107 | + when /\.text_(start|middle|end)\z/ | |
108 | + "searchkick_autocomplete_search" | |
109 | + else | |
110 | + "keyword" | |
111 | + end | |
104 | 112 | queries << {multi_match: shared_options.merge(analyzer: analyzer)} |
105 | 113 | end |
106 | 114 | end | ... | ... |
lib/searchkick/reindex.rb
... | ... | @@ -156,6 +156,9 @@ module Searchkick |
156 | 156 | type: "custom", |
157 | 157 | tokenizer: "standard", |
158 | 158 | filter: ["lowercase", "asciifolding", "reverse", "searchkick_edge_ngram", "reverse"] |
159 | + }, | |
160 | + searchkick_exact_index: { | |
161 | + type: "keyword" | |
159 | 162 | } |
160 | 163 | }, |
161 | 164 | filter: { |
... | ... | @@ -245,7 +248,7 @@ module Searchkick |
245 | 248 | end |
246 | 249 | |
247 | 250 | mapping_options = Hash[ |
248 | - [:autocomplete, :suggest, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end] | |
251 | + [:autocomplete, :suggest, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :exact] | |
249 | 252 | .map{|type| [type, (options[type] || []).map(&:to_s)] } |
250 | 253 | ] |
251 | 254 | ... | ... |
test/autocomplete_test.rb
... | ... | @@ -57,4 +57,11 @@ class TestAutocomplete < Minitest::Unit::TestCase |
57 | 57 | assert_search "dark grey", ["Dark Grey"], fields: [{name: :word_start}] |
58 | 58 | end |
59 | 59 | |
60 | + # TODO find a better place | |
61 | + | |
62 | + def test_exact | |
63 | + store_names ["hi@example.org"] | |
64 | + assert_search "hi@example.org", ["hi@example.org"], fields: [{name: :exact}] | |
65 | + end | |
66 | + | |
60 | 67 | end | ... | ... |
test/test_helper.rb