Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update thinking sphinx index in ruby code

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.

like image 425
brabertaser19 Avatar asked Nov 14 '13 12:11

brabertaser19


2 Answers

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.

like image 90
Javier Ramirez Avatar answered Nov 20 '22 03:11

Javier Ramirez


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.

like image 44
Oscar Barrett Avatar answered Nov 20 '22 04:11

Oscar Barrett