Files
fizzy/lib/tasks/search.rake
T
Donal McBreen 28efe28f24 Replace Search::Index with Search::Records
Lean on ActiveRecord models for searching and strip out the raw SQL.
Replaces the search_index_* tables with sharded search_records_* tables
as that allows us to use a Search::Record model name.

A Class is dynamically created for each record table shard so that we
and we can access it via the Search::Record.for_account(account_id)
method.
2025-11-17 09:12:40 -05:00

22 lines
574 B
Ruby

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