Thinking About Sphinx
Friday, October 23rd, 2009 · 0 comments
I just finished installing Sphinx on my slice, and setting up Thinking Sphinx on my website. Previously I was just using a simple search method in my Post model, but it was always a little on the slow side, especially now since I've started to publish more posts. Getting Sphinx running on my development machine was simple thanks to this article. Installing it on my web server was also easy (./configure; make; make install).
The only down-side was the need to manually index and start the Sphinx server. Hello crontab, rake and capistrano.
I put these tasks under the deploy namespace:
desc "Index Sphinx"
task :sphinx_index do
run "/opt/ruby-enterprise-1.8.7-20090928/bin/rake -f /var/www/matharvard.ca/current/Rakefile thinking_sphinx:index RAILS_ENV=production"
end
desc "Start Sphinx"
task :sphinx_start do
run "/opt/ruby-enterprise-1.8.7-20090928/bin/rake -f /var/www/matharvard.ca/current/Rakefile thinking_sphinx:start RAILS_ENV=production"
end
desc "Stop Sphinx"
task :sphinx_stop do
run "/opt/ruby-enterprise-1.8.7-20090928/bin/rake -f /var/www/matharvard.ca/current/Rakefile thinking_sphinx:stop RAILS_ENV=production"
end
Here's the line in my crontab file.
* 0 * * * /opt/ruby-enterprise-1.8.7-20090928/bin/rake -f /var/www/matharvard.ca/current/Rakefile thinking_sphinx:index
RAILS_ENV=production
This runs the rake command every day at midnight. As you can see, I'm using Ruby Enterprise Edition, though it probably won't make a difference if I used regular Ruby for this.
I also had to switch from SQLite3 to MySQL, in order to use Sphinx, which was easily accomplished by YamlDb!
