From c30567959cff1971f79ecc9886dafa290e64a452 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 20 Sep 2018 08:50:49 -0700 Subject: [PATCH] Fixed field misspellings for older partial match format - #1194 --- CHANGELOG.md | 1 + lib/searchkick/query.rb | 2 +- test/misspellings_test.rb | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45a2f26..06aedf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed deletes with routing and `async` callbacks - Fixed deletes with routing and `queue` callbacks - Fixed deprecation warnings +- Fixed field misspellings for older partial match format ## 3.1.1 diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index fab09d2..8bb9022 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -281,7 +281,7 @@ module Searchkick prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0 default_max_expansions = @misspellings_below ? 20 : 3 max_expansions = (misspellings.is_a?(Hash) && misspellings[:max_expansions]) || default_max_expansions - misspellings_fields = misspellings.is_a?(Hash) && misspellings.key?(:fields) && misspellings[:fields].map { |f| "#{f}.#{@match_suffix}" } + misspellings_fields = misspellings.is_a?(Hash) && misspellings.key?(:fields) && misspellings[:fields].map { |f| f.is_a?(Hash) ? f.to_a.join(".") : "#{f}.#{@match_suffix}" } if misspellings_fields missing_fields = misspellings_fields - fields diff --git a/test/misspellings_test.rb b/test/misspellings_test.rb index 80971ae..18ab357 100644 --- a/test/misspellings_test.rb +++ b/test/misspellings_test.rb @@ -97,4 +97,9 @@ class MisspellingsTest < Minitest::Test assert_search "siracha", ["Sriracha"], {misspellings: {fields: [:name]}} end end + + def test_misspellings_field_word_start + store_names ["Sriracha"] + assert_search "siracha", ["Sriracha"], fields: [{name: :word_middle}], misspellings: {fields: [{name: :word_middle}]} + end end -- libgit2 0.21.0