Commit 854138782d7f52aaa831dec848c2145e52b67c3f

Authored by Andrew Kane
1 parent bce93a14

Added misspellings? method to results - closes #807

CHANGELOG.md
1 1 ## 2.0.3 [unreleased]
2 2  
3 3 - Added `async` option to `reindex` [experimental]
  4 +- Added `misspellings?` method to results
4 5  
5 6 ## 2.0.2
6 7  
... ...
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
... ... @@ -184,6 +184,10 @@ module Searchkick
184 184 @response["hits"]["hits"]
185 185 end
186 186  
  187 + def misspellings?
  188 + @options[:misspellings]
  189 + end
  190 +
187 191 private
188 192  
189 193 def results_query(records, hits)
... ...
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
... ...