Commit 0bf9b28cdb01ab9a80fa0abf7f787f1614fa592c
1 parent
744360b7
Exists in
master
and in
21 other branches
Use dis_max
Showing
2 changed files
with
22 additions
and
6 deletions
Show diff stats
lib/searchkick.rb
... | ... | @@ -50,11 +50,21 @@ module Searchkick |
50 | 50 | def searchkick_query(fields, term, conversions = false) |
51 | 51 | query do |
52 | 52 | boolean do |
53 | - should do | |
54 | - match fields, term, boost: 10, operator: "and", analyzer: "searchkick_search" | |
55 | - end | |
56 | 53 | must do |
57 | - match fields, term, use_dis_max: false, fuzziness: 0.7, max_expansions: 1, prefix_length: 1, operator: "and", analyzer: "searchkick_search" | |
54 | + dis_max do | |
55 | + query do | |
56 | + match fields, term, boost: 10, operator: "and", analyzer: "searchkick_search" | |
57 | + end | |
58 | + query do | |
59 | + match fields, term, boost: 10, operator: "and", analyzer: "searchkick_search2" | |
60 | + end | |
61 | + query do | |
62 | + match fields, term, use_dis_max: false, fuzziness: 0.7, max_expansions: 1, prefix_length: 1, operator: "and", analyzer: "searchkick_search" | |
63 | + end | |
64 | + query do | |
65 | + match fields, term, use_dis_max: false, fuzziness: 0.7, max_expansions: 1, prefix_length: 1, operator: "and", analyzer: "searchkick_search2" | |
66 | + end | |
67 | + end | |
58 | 68 | end |
59 | 69 | if conversions |
60 | 70 | should do |
... | ... | @@ -95,6 +105,11 @@ module Searchkick |
95 | 105 | type: "custom", |
96 | 106 | tokenizer: "whitespace", |
97 | 107 | filter: ["lowercase", "asciifolding", "stop", "snowball", "searchkick_search_shingle"] |
108 | + }, | |
109 | + searchkick_search2: { | |
110 | + type: "custom", | |
111 | + tokenizer: "whitespace", | |
112 | + filter: ["lowercase", "asciifolding", "stop", "snowball"] #, "searchkick_search_shingle"] | |
98 | 113 | } |
99 | 114 | }, |
100 | 115 | filter: { |
... | ... | @@ -123,6 +138,7 @@ module Searchkick |
123 | 138 | settings[:analysis][:analyzer][:searchkick][:filter] << "searchkick_synonym" |
124 | 139 | settings[:analysis][:analyzer][:searchkick_search][:filter].insert(-2, "searchkick_synonym") |
125 | 140 | settings[:analysis][:analyzer][:searchkick_search][:filter] << "searchkick_synonym" |
141 | + settings[:analysis][:analyzer][:searchkick_search2][:filter] << "searchkick_synonym" | |
126 | 142 | end |
127 | 143 | settings |
128 | 144 | end | ... | ... |
test/searchkick_test.rb
... | ... | @@ -58,8 +58,8 @@ class TestSearchkick < Minitest::Unit::TestCase |
58 | 58 | end |
59 | 59 | |
60 | 60 | def test_middle_token |
61 | - store_names ["Dish Washer Soap"] | |
62 | - assert_search "dish soap", ["Dish Washer Soap"] | |
61 | + store_names ["Dish Washer Amazing Organic Soap"] | |
62 | + assert_search "dish soap", ["Dish Washer Amazing Organic Soap"] | |
63 | 63 | end |
64 | 64 | |
65 | 65 | # ascii | ... | ... |