Files
fizzy/lib/tasks/search.rake
T
Donal McBreen 01d16f96d4 Remove Search::Record.for_account
Instead we'll compute the table name dynamically based on
Current.account where needed. Also we'll prevent searchable records
from being saved if Current.account is not set, otherwise the after
commit callbacks will fail.
2025-11-21 12:09:21 +00:00

29 lines
897 B
Ruby

namespace :search do
desc "Reindex all cards and comments in the search index"
task reindex: :environment do
puts "Clearing search records..."
if ActiveRecord::Base.connection.adapter_name == "SQLite"
ActiveRecord::Base.connection.execute("DELETE FROM search_records")
ActiveRecord::Base.connection.execute("DELETE FROM search_records_fts")
else
Search::Record::Trilogy::SHARD_COUNT.times do |shard_id|
ActiveRecord::Base.connection.execute("DELETE FROM search_records_#{shard_id}")
end
end
puts "Reindexing cards..."
Card.find_each do |card|
Current.account = card.account
card.reindex
end
puts "Reindexing comments..."
Comment.find_each do |comment|
Current.account = comment.account
comment.reindex
end
puts "Done! Reindexed #{Card.count} cards and #{Comment.count} comments."
end
end