Commit efb67565650e2cf88d93245b35db133cd49bf78e
1 parent
85b7b4cb
Exists in
master
and in
19 other branches
Fixed exclude case for exact match
Showing
2 changed files
with
10 additions
and
2 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -284,6 +284,7 @@ module Searchkick |
284 | 284 | shared_options[:operator] = operator if match_type == :match |
285 | 285 | |
286 | 286 | exclude_analyzer = nil |
287 | + exclude_field = field | |
287 | 288 | |
288 | 289 | if field == "_all" || field.end_with?(".analyzed") |
289 | 290 | shared_options[:cutoff_frequency] = 0.001 unless operator == "and" || misspellings == false |
... | ... | @@ -295,6 +296,8 @@ module Searchkick |
295 | 296 | elsif field.end_with?(".exact") |
296 | 297 | f = field.split(".")[0..-2].join(".") |
297 | 298 | queries_to_add << {match: {f => shared_options.merge(analyzer: "keyword")}} |
299 | + exclude_field = f | |
300 | + exclude_analyzer = "keyword" | |
298 | 301 | else |
299 | 302 | analyzer = field =~ /\.word_(start|middle|end)\z/ ? "searchkick_word_search" : "searchkick_autocomplete_search" |
300 | 303 | qs << shared_options.merge(analyzer: analyzer) |
... | ... | @@ -323,12 +326,12 @@ module Searchkick |
323 | 326 | queries_to_add.concat(q2) |
324 | 327 | end |
325 | 328 | |
326 | - if options[:exclude] && exclude_analyzer | |
329 | + if options[:exclude] | |
327 | 330 | must_not = |
328 | 331 | options[:exclude].map do |phrase| |
329 | 332 | { |
330 | 333 | match_phrase: { |
331 | - field => { | |
334 | + exclude_field => { | |
332 | 335 | query: phrase, |
333 | 336 | analyzer: exclude_analyzer |
334 | 337 | } | ... | ... |
test/match_test.rb
... | ... | @@ -176,6 +176,11 @@ class MatchTest < Minitest::Test |
176 | 176 | assert_search "butter", [], exclude: ["peanut butter"], match: :exact |
177 | 177 | end |
178 | 178 | |
179 | + def test_exclude_same_exact | |
180 | + store_names ["Butter Tub", "Peanut Butter Tub"] | |
181 | + assert_search "Butter Tub", [], exclude: ["Butter Tub"], match: :exact | |
182 | + end | |
183 | + | |
179 | 184 | def test_exclude_egg_word_start |
180 | 185 | store_names ["eggs", "eggplant"] |
181 | 186 | assert_search "egg", ["eggs"], exclude: ["eggplant"], match: :word_start | ... | ... |