2013-02-25 11:42:20 -05:00
|
|
|
task "search:reindex" => :environment do
|
2016-10-01 02:53:30 -04:00
|
|
|
ENV['RAILS_DB'] ? reindex_search : reindex_search_all_sites
|
|
|
|
end
|
|
|
|
|
|
|
|
def reindex_search(db=RailsMultisite::ConnectionManagement.current_db)
|
|
|
|
puts "Reindexing '#{db}'"
|
|
|
|
puts ""
|
|
|
|
puts "Posts:"
|
|
|
|
Post.exec_sql("select p.id, p.cooked, c.name category, t.title, p.post_number, t.id topic_id from
|
|
|
|
posts p
|
|
|
|
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"]
|
|
|
|
post_number = p["post_number"].to_i
|
|
|
|
topic_id = p["topic_id"].to_i
|
|
|
|
|
2016-12-21 21:13:14 -05:00
|
|
|
SearchIndexer.update_posts_index(post_id, cooked, title, category)
|
|
|
|
SearchIndexer.update_topics_index(topic_id, title , cooked) if post_number == 1
|
2016-10-01 02:53:30 -04:00
|
|
|
|
|
|
|
putc "."
|
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
|
|
|
puts "Users:"
|
|
|
|
User.exec_sql("select id, name, username from users").each do |u|
|
|
|
|
id = u["id"]
|
|
|
|
name = u["name"]
|
|
|
|
username = u["username"]
|
2016-12-21 21:13:14 -05:00
|
|
|
SearchIndexer.update_users_index(id, username, name)
|
2016-10-01 02:53:30 -04:00
|
|
|
|
|
|
|
putc "."
|
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
|
|
|
puts "Categories"
|
|
|
|
|
|
|
|
Category.exec_sql("select id, name from categories").each do |c|
|
|
|
|
id = c["id"]
|
|
|
|
name = c["name"]
|
2016-12-21 21:13:14 -05:00
|
|
|
SearchIndexer.update_categories_index(id, name)
|
2016-10-01 02:53:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
|
|
|
def reindex_search_all_sites
|
2013-02-05 14:16:51 -05:00
|
|
|
RailsMultisite::ConnectionManagement.each_connection do |db|
|
2016-10-01 02:53:30 -04:00
|
|
|
reindex_search(db)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|