Commit 6c745479f80d3d500b5830f1bc089cd307f56f12
1 parent
56126dbc
Exists in
master
and in
21 other branches
Fixed default operator for partial matches - closes #217
Showing
2 changed files
with
12 additions
and
13 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -74,13 +74,13 @@ module Searchkick |
74 | 74 | else |
75 | 75 | queries = [] |
76 | 76 | fields.each do |field| |
77 | + shared_options = { | |
78 | + fields: [field], | |
79 | + query: term, | |
80 | + use_dis_max: false, | |
81 | + operator: operator | |
82 | + } | |
77 | 83 | if field == "_all" or field.end_with?(".analyzed") |
78 | - shared_options = { | |
79 | - fields: [field], | |
80 | - query: term, | |
81 | - use_dis_max: false, | |
82 | - operator: operator | |
83 | - } | |
84 | 84 | shared_options[:cutoff_frequency] = 0.001 unless operator == "and" |
85 | 85 | queries.concat [ |
86 | 86 | {multi_match: shared_options.merge(boost: 10, analyzer: "searchkick_search")}, |
... | ... | @@ -95,13 +95,7 @@ module Searchkick |
95 | 95 | end |
96 | 96 | else |
97 | 97 | analyzer = field.match(/\.word_(start|middle|end)\z/) ? "searchkick_word_search" : "searchkick_autocomplete_search" |
98 | - queries << { | |
99 | - multi_match: { | |
100 | - fields: [field], | |
101 | - query: term, | |
102 | - analyzer: analyzer | |
103 | - } | |
104 | - } | |
98 | + queries << {multi_match: shared_options.merge(analyzer: analyzer)} | |
105 | 99 | end |
106 | 100 | end |
107 | 101 | ... | ... |
test/autocomplete_test.rb
... | ... | @@ -52,4 +52,9 @@ class TestAutocomplete < Minitest::Unit::TestCase |
52 | 52 | assert_search "rld men ego", ["Where in the World is Carmen San Diego"], fields: [{name: :word_end}] |
53 | 53 | end |
54 | 54 | |
55 | + def test_word_start_multiple_words | |
56 | + store_names ["Dark Grey", "Dark Blue"] | |
57 | + assert_search "dark grey", ["Dark Grey"], fields: [{name: :word_start}] | |
58 | + end | |
59 | + | |
55 | 60 | end | ... | ... |