开发者

How rebuild index with acts_as_ferret?

开发者 https://www.devze.com 2023-01-28 18:33 出处:网络
I am using acts_as_ferret(0.4.3) to do full-text searching, but when update index I need to restart ferret, so is there any good method to make it u开发者_StackOverflow中文版pdate automatic? thanks!

I am using acts_as_ferret(0.4.3) to do full-text searching, but when update index I need to restart

ferret, so is there any good method to make it u开发者_StackOverflow中文版pdate automatic? thanks!


I got the answer

# ferret_index.rake
desc "Updates the ferret index for the application."
task :ferret_index => [ :environment ] do | t |
  MyModel.rebuild_index
  # here I could add other model index rebuilds
  puts "Completed Ferret Index Rebuild"
end 

This task is simplified: I'm telling it to rebuild the entire index each hour. I'm guessing when my dataset gets big enough, this will be really slow. In that case I'll need to track all the model instances that got updated in the past hour and just index those.

Finally, I needed a cron job to run the rake task, making sure to set the environment to "production":

cd /rails_app && rake ferret_index RAILS_ENV=production 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号