Commit f51492aa5f485522c36b893a4b498b778b45256e
1 parent
1ecce120
Exists in
master
and in
21 other branches
Added edit_distance option
Showing
3 changed files
with
8 additions
and
5 deletions
Show diff stats
CHANGELOG.md
README.md
... | ... | @@ -275,7 +275,7 @@ Product.search "zuchini", misspellings: false # no zucchini |
275 | 275 | You can also change the edit distance with: |
276 | 276 | |
277 | 277 | ```ruby |
278 | -Product.search "zucini", misspellings: {distance: 2} # zucchini | |
278 | +Product.search "zucini", misspellings: {edit_distance: 2} # zucchini | |
279 | 279 | ``` |
280 | 280 | |
281 | 281 | ### Indexing | ... | ... |
lib/searchkick/query.rb
... | ... | @@ -102,11 +102,12 @@ module Searchkick |
102 | 102 | shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search"), |
103 | 103 | shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search2") |
104 | 104 | ] |
105 | - if options[:misspellings] != false | |
106 | - distance = (options[:misspellings].is_a?(Hash) && options[:misspellings][:distance]) || 1 | |
105 | + misspellings = options.has_key?(:misspellings) ? options[:misspellings] : options[:mispellings] # why not? | |
106 | + if misspellings != false | |
107 | + edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1 | |
107 | 108 | qs.concat [ |
108 | - shared_options.merge(fuzziness: distance, max_expansions: 3, analyzer: "searchkick_search"), | |
109 | - shared_options.merge(fuzziness: distance, max_expansions: 3, analyzer: "searchkick_search2") | |
109 | + shared_options.merge(fuzziness: edit_distance, max_expansions: 3, analyzer: "searchkick_search"), | |
110 | + shared_options.merge(fuzziness: edit_distance, max_expansions: 3, analyzer: "searchkick_search2") | |
110 | 111 | ] |
111 | 112 | end |
112 | 113 | elsif field.end_with?(".exact") | ... | ... |