Commit 211624e343777f40f22ac778b7f5fba2dc7a20f5
1 parent
899ce33a
Exists in
master
and in
18 other branches
Show exact record ids that are missing [skip ci]
Showing
2 changed files
with
9 additions
and
4 deletions
Show diff stats
lib/searchkick/results.rb
@@ -30,6 +30,8 @@ module Searchkick | @@ -30,6 +30,8 @@ module Searchkick | ||
30 | results[type] = results_query(klass, grouped_hits).to_a.index_by { |r| r.id.to_s } | 30 | results[type] = results_query(klass, grouped_hits).to_a.index_by { |r| r.id.to_s } |
31 | end | 31 | end |
32 | 32 | ||
33 | + missing_ids = [] | ||
34 | + | ||
33 | # sort | 35 | # sort |
34 | results = | 36 | results = |
35 | hits.map do |hit| | 37 | hits.map do |hit| |
@@ -43,10 +45,13 @@ module Searchkick | @@ -43,10 +45,13 @@ module Searchkick | ||
43 | end | 45 | end |
44 | end | 46 | end |
45 | [result, hit] | 47 | [result, hit] |
46 | - end.select { |v| v[0] } | 48 | + end.select do |result, hit| |
49 | + missing_ids << hit["_id"] unless result | ||
50 | + result | ||
51 | + end | ||
47 | 52 | ||
48 | - if results.size != hits.size | ||
49 | - warn "[searchkick] WARNING: Records in search index do not exist in database" | 53 | + if missing_ids.any? |
54 | + warn "[searchkick] WARNING: Records in search index do not exist in database: #{missing_ids.join(", ")}" | ||
50 | end | 55 | end |
51 | 56 | ||
52 | results | 57 | results |
test/index_test.rb
@@ -85,7 +85,7 @@ class IndexTest < Minitest::Test | @@ -85,7 +85,7 @@ class IndexTest < Minitest::Test | ||
85 | def test_record_not_found | 85 | def test_record_not_found |
86 | store_names ["Product A", "Product B"] | 86 | store_names ["Product A", "Product B"] |
87 | Product.where(name: "Product A").delete_all | 87 | Product.where(name: "Product A").delete_all |
88 | - assert_output nil, "[searchkick] WARNING: Records in search index do not exist in database\n" do | 88 | + assert_output nil, /\[searchkick\] WARNING: Records in search index do not exist in database/ do |
89 | assert_search "product", ["Product B"] | 89 | assert_search "product", ["Product B"] |
90 | end | 90 | end |
91 | ensure | 91 | ensure |