I've found a bunch of posts on this site and others which have given me tidbits of what I need but I've not been able to piece them together.
For search I'm running sphinx on my site using the thinking sphinx gem. I need to re-index each time a user adds a new post to the site. I'm already running delayed_job on my site so what I want to do is each time a new post is added, I want to re-index asynchronously using delayed_job. I think I need to be using the handle_asynchronously command and call a method in my model which will run the rake task to re-index..but somewhere I read says rake should not be run from code.
Bottom line, totally confused. Can someone advise how to go about this?
I could be totally off but this is what I'm thinking..
# in post.rb def reindex_database # run rake task end # in posts_controller.rb def add_post # add_post logic handle_asynchronously Post.reindex_database end
In case someone was following this, I ended up resolving this by adding a system call in my post.rb method:
# in post.rb def reindexDB `rake thinking_sphinx:rebuild` end
..and then whenever i need to call this, i use this:
Would still be nice knowing how to properly go about this.
You doing it wrong. Use deltas for this - http://freelancing-god.github.com/ts/en/deltas.html