Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How rebuild index with acts_as_ferret?

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 update automatic? thanks!

like image 231
why Avatar asked Oct 28 '25 16:10

why


1 Answers

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 
like image 95
why Avatar answered Oct 31 '25 11:10

why



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!