2013-02-26 00:42:20 +08:00
|
|
|
task "search:reindex" => :environment do
|
2013-02-06 03:16:51 +08:00
|
|
|
RailsMultisite::ConnectionManagement.each_connection do |db|
|
|
|
|
puts "Reindexing #{db}"
|
|
|
|
puts ""
|
|
|
|
puts "Posts:"
|
2013-02-26 00:42:20 +08:00
|
|
|
Post.exec_sql("select p.id, p.cooked, c.name category, t.title from
|
|
|
|
posts p
|
2013-02-06 03:16:51 +08:00
|
|
|
join topics t on t.id = p.topic_id
|
|
|
|
left join categories c on c.id = t.category_id
|
|
|
|
").each do |p|
|
|
|
|
post_id = p["id"]
|
|
|
|
cooked = p["cooked"]
|
|
|
|
title = p["title"]
|
|
|
|
category = p["cat"]
|
2013-02-26 00:42:20 +08:00
|
|
|
SearchObserver.update_posts_index(post_id, cooked, title, category)
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
putc "."
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
puts
|
2013-02-06 03:16:51 +08:00
|
|
|
puts "Users:"
|
|
|
|
User.exec_sql("select id, name, username from users").each do |u|
|
|
|
|
id = u["id"]
|
|
|
|
name = u["name"]
|
|
|
|
username = u["username"]
|
2013-02-26 00:42:20 +08:00
|
|
|
SearchObserver.update_users_index(id, username, name)
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
putc "."
|
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
|
|
|
puts "Categories"
|
|
|
|
|
|
|
|
Category.exec_sql("select id, name from categories").each do |c|
|
|
|
|
id = c["id"]
|
|
|
|
name = c["name"]
|
2013-02-26 00:42:20 +08:00
|
|
|
SearchObserver.update_categories_index(id, name)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
puts
|
|
|
|
end
|
|
|
|
end
|