From fe1cf63b9a27482be2214d5e1d8b0b38adea54ae Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 20 Nov 2020 15:00:06 -0800 Subject: [PATCH] Use missing_hits instead of missing_ids --- CHANGELOG.md | 2 +- lib/searchkick/results.rb | 20 ++++++++++---------- test/search_test.rb | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8c4157..a9d3bb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 4.4.2 (unreleased) -- Added `missing_ids` method to results +- Added `missing_hits` method to results - Fixed issue with `like` and special characters ## 4.4.1 (2020-06-24) diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index 4b75d85..9cdd5db 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -22,15 +22,15 @@ module Searchkick # TODO return enumerator like with_score def with_hit @with_hit ||= begin - if missing_ids.any? - Searchkick.warn("Records in search index do not exist in database: #{missing_ids.join(", ")}") + if missing_hits.any? + Searchkick.warn("Records in search index do not exist in database: #{missing_hits.map { |v| v["_id"] }.join(", ")}") end - with_hit_and_missing_ids[0] + with_hit_and_missing_hits[0] end end - def missing_ids - @missing_ids ||= with_hit_and_missing_ids[1] + def missing_hits + @missing_hits ||= with_hit_and_missing_hits[1] end def suggestions @@ -219,9 +219,9 @@ module Searchkick private - def with_hit_and_missing_ids - @with_hit_and_missing_ids ||= begin - missing_ids = [] + def with_hit_and_missing_hits + @with_hit_and_missing_hits ||= begin + missing_hits = [] if options[:load] # results can have different types @@ -257,7 +257,7 @@ module Searchkick end [result, hit] end.select do |result, hit| - missing_ids << hit["_id"] unless result + missing_hits << hit unless result result end else @@ -284,7 +284,7 @@ module Searchkick end end - [results, missing_ids] + [results, missing_hits] end end diff --git a/test/search_test.rb b/test/search_test.rb index eada9e9..e3019de 100644 --- a/test/search_test.rb +++ b/test/search_test.rb @@ -37,16 +37,16 @@ class SearchTest < Minitest::Test assert_equal ["Dollar Tree"], products.map(&:name) end - def test_missing_ids + def test_missing_hits store_names ["Product A", "Product B"] product = Product.find_by(name: "Product A") product.delete assert_output nil, /\[searchkick\] WARNING: Records in search index do not exist in database/ do result = Product.search("product") assert_equal ["Product B"], result.map(&:name) - assert_equal [product.id.to_s], result.missing_ids + assert_equal [product.id.to_s], result.missing_hits.map { |v| v["_id"] } end - assert_equal [], Product.search("product", load: false).missing_ids + assert_empty Product.search("product", load: false).missing_hits ensure Product.reindex end -- libgit2 0.21.0