diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index beb137f..5f0a277 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -30,6 +30,8 @@ module Searchkick results[type] = results_query(klass, grouped_hits).to_a.index_by { |r| r.id.to_s } end + missing_ids = [] + # sort results = hits.map do |hit| @@ -43,10 +45,13 @@ module Searchkick end end [result, hit] - end.select { |v| v[0] } + end.select do |result, hit| + missing_ids << hit["_id"] unless result + result + end - if results.size != hits.size - warn "[searchkick] WARNING: Records in search index do not exist in database" + if missing_ids.any? + warn "[searchkick] WARNING: Records in search index do not exist in database: #{missing_ids.join(", ")}" end results diff --git a/test/index_test.rb b/test/index_test.rb index c99a55b..97041cc 100644 --- a/test/index_test.rb +++ b/test/index_test.rb @@ -85,7 +85,7 @@ class IndexTest < Minitest::Test def test_record_not_found store_names ["Product A", "Product B"] Product.where(name: "Product A").delete_all - assert_output nil, "[searchkick] WARNING: Records in search index do not exist in database\n" do + assert_output nil, /\[searchkick\] WARNING: Records in search index do not exist in database/ do assert_search "product", ["Product B"] end ensure -- libgit2 0.21.0