Commit 926f9dc51549a54484b8cc2b3e15bcb7ad84e885
1 parent
ba4c4c99
Exists in
master
and in
21 other branches
Set transpositions: true by default and misspellings for partial matches
Showing
2 changed files
with
11 additions
and
11 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -100,22 +100,19 @@ module Searchkick |
100 | 100 | options[:misspellings] |
101 | 101 | elsif options.key?(:mispellings) |
102 | 102 | options[:mispellings] # why not? |
103 | - elsif field == "_all" || field.end_with?(".analyzed") | |
104 | - true | |
105 | 103 | else |
106 | - # TODO default to true and remove this | |
107 | - false | |
104 | + true | |
108 | 105 | end |
109 | 106 | |
110 | 107 | if misspellings != false |
111 | 108 | edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1 |
112 | 109 | transpositions = |
113 | - if misspellings.is_a?(Hash) && misspellings[:transpositions] == true | |
114 | - {fuzzy_transpositions: true} | |
110 | + if misspellings.is_a?(Hash) && misspellings.key?(:transpositions) | |
111 | + {fuzzy_transpositions: misspellings[:transpositions]} | |
115 | 112 | elsif below20? |
116 | 113 | {} |
117 | 114 | else |
118 | - {fuzzy_transpositions: false} | |
115 | + {fuzzy_transpositions: true} | |
119 | 116 | end |
120 | 117 | prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0 |
121 | 118 | max_expansions = (misspellings.is_a?(Hash) && misspellings[:max_expansions]) || 3 | ... | ... |
test/match_test.rb
1 | -# encoding: utf-8 | |
2 | - | |
3 | 1 | require_relative "test_helper" |
4 | 2 | |
5 | 3 | class MatchTest < Minitest::Test |
... | ... | @@ -113,8 +111,8 @@ class MatchTest < Minitest::Test |
113 | 111 | |
114 | 112 | def test_misspelling_zucchini_transposition |
115 | 113 | store_names ["zucchini"] |
116 | - assert_search "zuccihni", [] # doesn't work without transpositions:true option | |
117 | - assert_search "zuccihni", ["zucchini"], misspellings: {transpositions: true} | |
114 | + assert_search "zuccihni", ["zucchini"] | |
115 | + assert_search "zuccihni", [], misspellings: {transpositions: false} | |
118 | 116 | end |
119 | 117 | |
120 | 118 | def test_misspelling_lasagna |
... | ... | @@ -132,6 +130,11 @@ class MatchTest < Minitest::Test |
132 | 130 | assert_search "lasanga pasat", ["lasagna pasta"], misspellings: {transpositions: true} # both words misspelled with a transposition should still work |
133 | 131 | end |
134 | 132 | |
133 | + def test_misspellings_word_start | |
134 | + store_names ["Sriracha"] | |
135 | + assert_search "siracha", ["Sriracha"], fields: [{name: :word_start}] | |
136 | + end | |
137 | + | |
135 | 138 | # spaces |
136 | 139 | |
137 | 140 | def test_spaces_in_field | ... | ... |