Written by Sean Behan on Sun Jun 17th 2012

If using Sphinx, you need to refresh indexes when you add new content to your database. This is fairly easy to do by hand

rake thinking_sphinx:index RAILS_ENV=production
But if you want to automate this and use a cron, remember to set the PATH, SHELL and RAILS_ENV variables for your job. The environment isn't the same when you're doing it by hand and your index will fail silently :(

You find your specific PATH and SHELL info like so

echo $PATH
echo $SHELL
To get into the cron and set your schedule
crontab -e
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
SHELL=/bin/bash
RAILS_ENV=production

re-index production sphinx every 15 minutes

/15 * root cd /var/www/rails_app && /usr/local/bin/rake thinking_sphinx:index >> /dev/null 2>&1

More information available here http://heimdull.blogspot.com/2009/05/journey-with-thinking-sphinx-and-crond.html http://groups.google.com/group/thinking-sphinx/browse_thread/thread/5451458fae7d6124


Tagged with..
#cron #rake #Ruby on Rails

Just finishing up brewing up some fresh ground comments...