Commit 0022afc911229f0ba03b219ee1da2f297618870e
1 parent
695021af
Exists in
master
and in
19 other branches
Fixed tests for ES 2
Showing
2 changed files
with
10 additions
and
3 deletions
Show diff stats
lib/searchkick/query.rb
@@ -335,6 +335,11 @@ module Searchkick | @@ -335,6 +335,11 @@ module Searchkick | ||
335 | 335 | ||
336 | if field.start_with?("*.") | 336 | if field.start_with?("*.") |
337 | q2 = qs.map { |q| {multi_match: q.merge(fields: [field], type: match_type == :match_phrase ? "phrase" : "best_fields")} } | 337 | q2 = qs.map { |q| {multi_match: q.merge(fields: [field], type: match_type == :match_phrase ? "phrase" : "best_fields")} } |
338 | + if below60? | ||
339 | + q2.each do |q| | ||
340 | + q[:multi_match].delete(:fuzzy_transpositions) | ||
341 | + end | ||
342 | + end | ||
338 | else | 343 | else |
339 | q2 = qs.map { |q| {match_type => {field => q}} } | 344 | q2 = qs.map { |q| {match_type => {field => q}} } |
340 | end | 345 | end |
@@ -547,6 +552,8 @@ module Searchkick | @@ -547,6 +552,8 @@ module Searchkick | ||
547 | ["_all.phrase"] | 552 | ["_all.phrase"] |
548 | elsif term == "*" | 553 | elsif term == "*" |
549 | [] | 554 | [] |
555 | + elsif default_match == :exact | ||
556 | + raise ArgumentError, "Must specify fields to search" | ||
550 | else | 557 | else |
551 | [default_match == :word ? "*.analyzed" : "*.#{default_match}"] | 558 | [default_match == :word ? "*.analyzed" : "*.#{default_match}"] |
552 | end | 559 | end |
test/match_test.rb
@@ -180,12 +180,12 @@ class MatchTest < Minitest::Test | @@ -180,12 +180,12 @@ class MatchTest < Minitest::Test | ||
180 | 180 | ||
181 | def test_exclude_butter_exact | 181 | def test_exclude_butter_exact |
182 | store_names ["Butter Tub", "Peanut Butter Tub"] | 182 | store_names ["Butter Tub", "Peanut Butter Tub"] |
183 | - assert_search "butter", [], exclude: ["peanut butter"], match: :exact | 183 | + assert_search "butter", [], exclude: ["peanut butter"], fields: [{name: :exact}] |
184 | end | 184 | end |
185 | 185 | ||
186 | def test_exclude_same_exact | 186 | def test_exclude_same_exact |
187 | store_names ["Butter Tub", "Peanut Butter Tub"] | 187 | store_names ["Butter Tub", "Peanut Butter Tub"] |
188 | - assert_search "Butter Tub", [], exclude: ["Butter Tub"], match: :exact | 188 | + assert_search "Butter Tub", ["Butter Tub"], exclude: ["Peanut Butter Tub"], fields: [{name: :exact}] |
189 | end | 189 | end |
190 | 190 | ||
191 | def test_exclude_egg_word_start | 191 | def test_exclude_egg_word_start |
@@ -242,7 +242,7 @@ class MatchTest < Minitest::Test | @@ -242,7 +242,7 @@ class MatchTest < Minitest::Test | ||
242 | 242 | ||
243 | def test_phrase | 243 | def test_phrase |
244 | store_names ["Fresh Honey", "Honey Fresh"] | 244 | store_names ["Fresh Honey", "Honey Fresh"] |
245 | - assert_search "fresh honey", ["Fresh Honey"], match: :phrase | 245 | + assert_search "fresh honey", ["Fresh Honey"], match: :phrase, fields: [:name] |
246 | end | 246 | end |
247 | 247 | ||
248 | def test_phrase_again | 248 | def test_phrase_again |