28efe28f24
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.
22 lines
574 B
Ruby
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
|