I have app, which run's on ubuntu 12.04, with nginx+passenger And in my method i try to rebuild sphinx index so:
def update_sphinx_index
Rails.application.load_tasks
Rake::Task['ts:rebuild'].invoke
redirect_to admin_mainpage_path
end
also i try:
`rake ts:index`
but nothing happend, sphinx index doesn't rebuild. What i do wrong? Maybe i need to do this with some privilegies, or something else, becouse when i do rake ts:rebuild in command terminal all is fine, and index rebuild.
First of all, I don't really like the idea of calling sphinx reindex from a controller. The best practice here would be to use deltas for partial indexing (deltas with resque are a great solution for almost real time indexing) and then an occasional reindex once in a while to compact the files.
But if for any reason you really need to run this from the controller, I would say there are two things to consider. One is you are probably not on the right directory, so you can try to issue the system call changing to the directory then executing rake, as in
`cd /path/to/your/app rake ts:index`
Apart from this, if you are following best practices, the user executing your web server will be an underprivileged user, something like a user belonging to the www-data group. It's very likely this user won't have permissions to execute rake or to write the index files, so make sure the user starting your web server has the right permissions.
ts:rebuild
stops sphinx, rebuilds the index and then restarts, and should only be run if you've changed the structure of your index.
Instead, you should be running ts:index
if you're only adding new data.
As for why the rake task is not executing, it may be that your search daemon is still running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With