2010-12-05 71 views
3

我使用acts_as_ferret(0.4.3)來做全文搜索,但是當更新索引我需要重啓如何使用acts_as_ferret重建索引?

雪貂,那麼有沒有什麼好方法可以讓它自動更新?謝謝!

+0

對不起,它是「重建」 – why 2010-12-05 09:20:38

回答

2

# 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 

這個任務是簡化了答案:我告訴它來重建整個索引的每個小時。我在猜測,當我的數據集變得足夠大時,這將非常慢。在這種情況下,我需要跟蹤所有在過去一小時內得到更新的模型實例,並將它們編入索引。

最後,我需要一個cron作業運行rake任務,確保設置環境來「生產」:

cd /rails_app && rake ferret_index RAILS_ENV=production