Commit f51492aa5f485522c36b893a4b498b778b45256e

Authored by Andrew Kane
1 parent 1ecce120

Added edit_distance option

CHANGELOG.md
... ... @@ -2,6 +2,8 @@
2 2  
3 3 - Added `async` to `callbacks` option
4 4 - Added `wordnet` option
  5 +- Added `edit_distance` option to eventually replace `distance` option
  6 +- Catch misspelling of `misspellings` option
5 7  
6 8 ## 0.8.1
7 9  
... ...
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")
... ...