Commit 211624e343777f40f22ac778b7f5fba2dc7a20f5

Authored by Andrew
1 parent 899ce33a

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 30 results[type] = results_query(klass, grouped_hits).to_a.index_by { |r| r.id.to_s }
31 31 end
32 32  
  33 + missing_ids = []
  34 +
33 35 # sort
34 36 results =
35 37 hits.map do |hit|
... ... @@ -43,10 +45,13 @@ module Searchkick
43 45 end
44 46 end
45 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 55 end
51 56  
52 57 results
... ...
test/index_test.rb
... ... @@ -85,7 +85,7 @@ class IndexTest &lt; Minitest::Test
85 85 def test_record_not_found
86 86 store_names ["Product A", "Product B"]
87 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 89 assert_search "product", ["Product B"]
90 90 end
91 91 ensure
... ...