diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 8cc33ab..7d43b82 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -100,22 +100,19 @@ module Searchkick options[:misspellings] elsif options.key?(:mispellings) options[:mispellings] # why not? - elsif field == "_all" || field.end_with?(".analyzed") - true else - # TODO default to true and remove this - false + true end if misspellings != false edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1 transpositions = - if misspellings.is_a?(Hash) && misspellings[:transpositions] == true - {fuzzy_transpositions: true} + if misspellings.is_a?(Hash) && misspellings.key?(:transpositions) + {fuzzy_transpositions: misspellings[:transpositions]} elsif below20? {} else - {fuzzy_transpositions: false} + {fuzzy_transpositions: true} end prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0 max_expansions = (misspellings.is_a?(Hash) && misspellings[:max_expansions]) || 3 diff --git a/test/match_test.rb b/test/match_test.rb index 95b163b..d17e157 100644 --- a/test/match_test.rb +++ b/test/match_test.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require_relative "test_helper" class MatchTest < Minitest::Test @@ -113,8 +111,8 @@ class MatchTest < Minitest::Test def test_misspelling_zucchini_transposition store_names ["zucchini"] - assert_search "zuccihni", [] # doesn't work without transpositions:true option - assert_search "zuccihni", ["zucchini"], misspellings: {transpositions: true} + assert_search "zuccihni", ["zucchini"] + assert_search "zuccihni", [], misspellings: {transpositions: false} end def test_misspelling_lasagna @@ -132,6 +130,11 @@ class MatchTest < Minitest::Test assert_search "lasanga pasat", ["lasagna pasta"], misspellings: {transpositions: true} # both words misspelled with a transposition should still work end + def test_misspellings_word_start + store_names ["Sriracha"] + assert_search "siracha", ["Sriracha"], fields: [{name: :word_start}] + end + # spaces def test_spaces_in_field -- libgit2 0.21.0