Tuesday, August 14. 2007Rails acts_as_ferret without DRbTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
great post. exactly what i was attempting to do. almost.
is there a way to rebuild index using only a conditional subset of the model's records? like only records with a certain "approved" state flag get indexed? thanks for any help you can provide.
Hi Lawrence, I did some digging in the acts_as_ferret API (http://actsasferret.rubyforge.org/). I couldn't find a method that would update the index for just record X.
What you might do in your rake task is something like this: records = Record.find(:all, :conditions => 'approved = 1') records.each { | r | r.save } The save method should run the ferret indexer automatically. But it will probably also update the updated_at field if you have one. I'm not sure how to avoid that.
I need to do the same thing. From looking at the ferret docs, I can see that the ferret_enabled? method can be overridden to exclude certain records:
http://projects.jkraemer.net/rdoc/acts_as_ferret/classes/ActsAsFerret/InstanceMethods.html#M000042 so I think you could do something like this in the model (assuming your record has a .hidden field): def ferret_enabled? hidden? ? false : super; end
If collisions are so rare could you not implement your own locking and, if the lock is taken, just wait until it becomes available?
I think the problem of multiple threads trying to access the same file increases as the traffic increases. And real-time locking could work if the waits were short. Having the background process is probably the best way if your web hosting supports it. That way there's no delay for the users.
If you disable rebuild on save with self.disable_ferret(:always) you can then index one record by calling record.ferret_update
Good to know. Has that method always been available? I'm surprised I missed it when I went looking the last time.
Hi,
I am facing the same problem with index folder in rails app. is there any changes in your code? and where will i add this code 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 i mean in which file? please give reply for this
Ravi, you should put ferret_index.rake into its own file in the lib/tasks folder.
Wow...this saved my bacon today!
In the past if I had to rebuild the index I would just delete the index folder and it would work. But my site has a lot more traffic now - and it takes it a good 5-10 minutes to rebuild. Meanwhile requests would come pouring into the server getting backed up and causing the rebuild to fail part way. Talk about stressful! Anyway this worked since I was able to shut down the mongrels and let this rake task do it's magic without more requests coming in for a while. Once a clean index was rebuilt - turned the mongrels back on and all was well. Still not really sure why/how it got corrupted in the first place (seems to happen about once every 3 months or so) but really glad I have this rake task at my disposal now. This is the site you saved today!: www.universitytutor.com Thanks again! Brian Armstrong |
CategoriesQuicksearch |