diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a6906d..4983ebe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 2.0.3 [unreleased] - Added `async` option to `reindex` [experimental] +- Added `misspellings?` method to results ## 2.0.2 diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 669d0f3..8530202 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -34,6 +34,7 @@ module Searchkick # prevent Ruby warnings @type = nil @routing = nil + @misspellings = false @misspellings_below = nil @highlighted_fields = nil @@ -107,7 +108,8 @@ module Searchkick includes: options[:includes], json: !@json.nil?, match_suffix: @match_suffix, - highlighted_fields: @highlighted_fields || [] + highlighted_fields: @highlighted_fields || [], + misspellings: @misspellings } if options[:debug] @@ -256,6 +258,9 @@ 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 = true + else + @misspellings = false end fields.each do |field| diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index 8a80992..fa74f53 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -184,6 +184,10 @@ module Searchkick @response["hits"]["hits"] end + def misspellings? + @options[:misspellings] + end + private def results_query(records, hits) diff --git a/test/misspellings_test.rb b/test/misspellings_test.rb index 277b7f1..ae01f64 100644 --- a/test/misspellings_test.rb +++ b/test/misspellings_test.rb @@ -39,8 +39,18 @@ class MisspellingsTest < Minitest::Test assert_search "abc", ["abc", "abd"], misspellings: {below: 2} end + def test_misspellings_below_unmet_result + store_names ["abc", "abd", "aee"] + assert Product.search("abc", misspellings: {below: 2}).misspellings? + end + def test_misspellings_below_met store_names ["abc", "abd", "aee"] assert_search "abc", ["abc"], misspellings: {below: 1} end + + def test_misspellings_below_met_result + store_names ["abc", "abd", "aee"] + assert !Product.search("abc", misspellings: {below: 1}).misspellings? + end end -- libgit2 0.21.0