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,7 +100,15 @@ module Searchkick | ||
100 | ] | 100 | ] |
101 | end | 101 | end |
102 | else | 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 | queries << {multi_match: shared_options.merge(analyzer: analyzer)} | 112 | queries << {multi_match: shared_options.merge(analyzer: analyzer)} |
105 | end | 113 | end |
106 | end | 114 | end |
lib/searchkick/reindex.rb
@@ -156,6 +156,9 @@ module Searchkick | @@ -156,6 +156,9 @@ module Searchkick | ||
156 | type: "custom", | 156 | type: "custom", |
157 | tokenizer: "standard", | 157 | tokenizer: "standard", |
158 | filter: ["lowercase", "asciifolding", "reverse", "searchkick_edge_ngram", "reverse"] | 158 | filter: ["lowercase", "asciifolding", "reverse", "searchkick_edge_ngram", "reverse"] |
159 | + }, | ||
160 | + searchkick_exact_index: { | ||
161 | + type: "keyword" | ||
159 | } | 162 | } |
160 | }, | 163 | }, |
161 | filter: { | 164 | filter: { |
@@ -245,7 +248,7 @@ module Searchkick | @@ -245,7 +248,7 @@ module Searchkick | ||
245 | end | 248 | end |
246 | 249 | ||
247 | mapping_options = Hash[ | 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 | .map{|type| [type, (options[type] || []).map(&:to_s)] } | 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,4 +57,11 @@ class TestAutocomplete < Minitest::Unit::TestCase | ||
57 | assert_search "dark grey", ["Dark Grey"], fields: [{name: :word_start}] | 57 | assert_search "dark grey", ["Dark Grey"], fields: [{name: :word_start}] |
58 | end | 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 | end | 67 | end |
test/test_helper.rb
@@ -119,7 +119,8 @@ class Product | @@ -119,7 +119,8 @@ class Product | ||
119 | text_end: [:name], | 119 | text_end: [:name], |
120 | word_start: [:name], | 120 | word_start: [:name], |
121 | word_middle: [:name], | 121 | word_middle: [:name], |
122 | - word_end: [:name] | 122 | + word_end: [:name], |
123 | + exact: [:name] | ||
123 | 124 | ||
124 | attr_accessor :conversions, :user_ids | 125 | attr_accessor :conversions, :user_ids |
125 | 126 |