2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
task "search:reindex" => :environment do
|
2016-10-01 14:53:30 +08:00
|
|
|
ENV['RAILS_DB'] ? reindex_search : reindex_search_all_sites
|
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def reindex_search(db = RailsMultisite::ConnectionManagement.current_db)
|
2016-10-01 14:53:30 +08:00
|
|
|
puts "Reindexing '#{db}'"
|
|
|
|
puts ""
|
2018-02-20 11:41:00 +08:00
|
|
|
puts "Posts"
|
|
|
|
Post.includes(topic: [:category, :tags]).find_each do |p|
|
|
|
|
if p.post_number == 1
|
|
|
|
SearchIndexer.index(p.topic, force: true)
|
|
|
|
else
|
|
|
|
SearchIndexer.index(p, force: true)
|
|
|
|
end
|
2016-10-01 14:53:30 +08:00
|
|
|
putc "."
|
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
2018-02-20 11:41:00 +08:00
|
|
|
puts "Users"
|
|
|
|
User.find_each do |u|
|
|
|
|
SearchIndexer.index(u, force: true)
|
2016-10-01 14:53:30 +08:00
|
|
|
putc "."
|
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
|
|
|
puts "Categories"
|
|
|
|
|
2018-02-20 11:41:00 +08:00
|
|
|
Category.find_each do |c|
|
|
|
|
SearchIndexer.index(c, force: true)
|
|
|
|
putc "."
|
2017-10-25 05:55:05 +08:00
|
|
|
end
|
|
|
|
|
2018-02-20 11:41:00 +08:00
|
|
|
puts
|
|
|
|
puts "Tags"
|
2017-10-25 05:55:05 +08:00
|
|
|
|
2018-02-20 11:41:00 +08:00
|
|
|
Tag.find_each do |t|
|
|
|
|
SearchIndexer.index(t, force: true)
|
|
|
|
putc "."
|
2016-10-01 14:53:30 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
|
|
|
def reindex_search_all_sites
|
2013-02-06 03:16:51 +08:00
|
|
|
RailsMultisite::ConnectionManagement.each_connection do |db|
|
2016-10-01 14:53:30 +08:00
|
|
|
reindex_search(db)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|