Commit 854138782d7f52aaa831dec848c2145e52b67c3f
1 parent
bce93a14
Exists in
master
and in
19 other branches
Added misspellings? method to results - closes #807
Showing
4 changed files
with
21 additions
and
1 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/query.rb
... | ... | @@ -34,6 +34,7 @@ module Searchkick |
34 | 34 | # prevent Ruby warnings |
35 | 35 | @type = nil |
36 | 36 | @routing = nil |
37 | + @misspellings = false | |
37 | 38 | @misspellings_below = nil |
38 | 39 | @highlighted_fields = nil |
39 | 40 | |
... | ... | @@ -107,7 +108,8 @@ module Searchkick |
107 | 108 | includes: options[:includes], |
108 | 109 | json: !@json.nil?, |
109 | 110 | match_suffix: @match_suffix, |
110 | - highlighted_fields: @highlighted_fields || [] | |
111 | + highlighted_fields: @highlighted_fields || [], | |
112 | + misspellings: @misspellings | |
111 | 113 | } |
112 | 114 | |
113 | 115 | if options[:debug] |
... | ... | @@ -256,6 +258,9 @@ module Searchkick |
256 | 258 | prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0 |
257 | 259 | default_max_expansions = @misspellings_below ? 20 : 3 |
258 | 260 | max_expansions = (misspellings.is_a?(Hash) && misspellings[:max_expansions]) || default_max_expansions |
261 | + @misspellings = true | |
262 | + else | |
263 | + @misspellings = false | |
259 | 264 | end |
260 | 265 | |
261 | 266 | fields.each do |field| | ... | ... |
lib/searchkick/results.rb
test/misspellings_test.rb
... | ... | @@ -39,8 +39,18 @@ class MisspellingsTest < Minitest::Test |
39 | 39 | assert_search "abc", ["abc", "abd"], misspellings: {below: 2} |
40 | 40 | end |
41 | 41 | |
42 | + def test_misspellings_below_unmet_result | |
43 | + store_names ["abc", "abd", "aee"] | |
44 | + assert Product.search("abc", misspellings: {below: 2}).misspellings? | |
45 | + end | |
46 | + | |
42 | 47 | def test_misspellings_below_met |
43 | 48 | store_names ["abc", "abd", "aee"] |
44 | 49 | assert_search "abc", ["abc"], misspellings: {below: 1} |
45 | 50 | end |
51 | + | |
52 | + def test_misspellings_below_met_result | |
53 | + store_names ["abc", "abd", "aee"] | |
54 | + assert !Product.search("abc", misspellings: {below: 1}).misspellings? | |
55 | + end | |
46 | 56 | end | ... | ... |