Commit f2f62887527d8c00cb502af549acd6c3f9e5972c
1 parent
07cb870c
Exists in
master
and in
21 other branches
Fixed multiword queries and word_* option - closes #114
Showing
3 changed files
with
24 additions
and
13 deletions
Show diff stats
lib/searchkick/reindex.rb
... | ... | @@ -125,6 +125,11 @@ module Searchkick |
125 | 125 | tokenizer: "keyword", |
126 | 126 | filter: ["lowercase", "asciifolding"] |
127 | 127 | }, |
128 | + searchkick_word_search: { | |
129 | + type: "custom", | |
130 | + tokenizer: "standard", | |
131 | + filter: ["lowercase", "asciifolding"] | |
132 | + }, | |
128 | 133 | searchkick_suggest_index: { |
129 | 134 | type: "custom", |
130 | 135 | tokenizer: "standard", | ... | ... |
lib/searchkick/search.rb
... | ... | @@ -92,11 +92,12 @@ module Searchkick |
92 | 92 | ] |
93 | 93 | end |
94 | 94 | else |
95 | + analyzer = field.match(/\.word_(start|middle|end)\z/) ? "searchkick_word_search" : "searchkick_autocomplete_search" | |
95 | 96 | queries << { |
96 | 97 | multi_match: { |
97 | 98 | fields: [field], |
98 | 99 | query: term, |
99 | - analyzer: "searchkick_autocomplete_search" | |
100 | + analyzer: analyzer | |
100 | 101 | } |
101 | 102 | } |
102 | 103 | end | ... | ... |
test/autocomplete_test.rb
... | ... | @@ -18,33 +18,38 @@ class TestAutocomplete < Minitest::Unit::TestCase |
18 | 18 | end |
19 | 19 | |
20 | 20 | def test_text_start |
21 | - store_names ["Where in the World is Carmen San Diego?"] | |
22 | - assert_search "whe", ["Where in the World is Carmen San Diego?"], fields: [{name: :text_start}] | |
21 | + store_names ["Where in the World is Carmen San Diego"] | |
22 | + assert_search "where in the world is", ["Where in the World is Carmen San Diego"], fields: [{name: :text_start}] | |
23 | + assert_search "in the world", [], fields: [{name: :text_start}] | |
23 | 24 | end |
24 | 25 | |
25 | 26 | def test_text_middle |
26 | - store_names ["Where in the World is Carmen San Diego?"] | |
27 | - assert_search "n the wor", ["Where in the World is Carmen San Diego?"], fields: [{name: :text_middle}] | |
27 | + store_names ["Where in the World is Carmen San Diego"] | |
28 | + assert_search "where in the world is", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}] | |
29 | + assert_search "n the wor", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}] | |
30 | + assert_search "men san diego", ["Where in the World is Carmen San Diego"], fields: [{name: :text_middle}] | |
31 | + assert_search "world carmen", [], fields: [{name: :text_middle}] | |
28 | 32 | end |
29 | 33 | |
30 | 34 | def test_text_end |
31 | - store_names ["Where in the World is Carmen San Diego?"] | |
32 | - assert_search "ego?", ["Where in the World is Carmen San Diego?"], fields: [{name: :text_end}] | |
35 | + store_names ["Where in the World is Carmen San Diego"] | |
36 | + assert_search "men san diego", ["Where in the World is Carmen San Diego"], fields: [{name: :text_end}] | |
37 | + assert_search "carmen san", [], fields: [{name: :text_end}] | |
33 | 38 | end |
34 | 39 | |
35 | 40 | def test_word_start |
36 | - store_names ["Where in the World is Carmen San Diego?"] | |
37 | - assert_search "car", ["Where in the World is Carmen San Diego?"], fields: [{name: :word_start}] | |
41 | + store_names ["Where in the World is Carmen San Diego"] | |
42 | + assert_search "car san wor", ["Where in the World is Carmen San Diego"], fields: [{name: :word_start}] | |
38 | 43 | end |
39 | 44 | |
40 | 45 | def test_word_middle |
41 | - store_names ["Where in the World is Carmen San Diego?"] | |
42 | - assert_search "orl", ["Where in the World is Carmen San Diego?"], fields: [{name: :word_middle}] | |
46 | + store_names ["Where in the World is Carmen San Diego"] | |
47 | + assert_search "orl", ["Where in the World is Carmen San Diego"], fields: [{name: :word_middle}] | |
43 | 48 | end |
44 | 49 | |
45 | 50 | def test_word_end |
46 | - store_names ["Where in the World is Carmen San Diego?"] | |
47 | - assert_search "men", ["Where in the World is Carmen San Diego?"], fields: [{name: :word_end}] | |
51 | + store_names ["Where in the World is Carmen San Diego"] | |
52 | + assert_search "rld men ego", ["Where in the World is Carmen San Diego"], fields: [{name: :word_end}] | |
48 | 53 | end |
49 | 54 | |
50 | 55 | end | ... | ... |