I forgot why I had to install 0.9.9-rc2 on Snow Leopard, but I used the following and it worked:
Get Sphinx 0.9.9-rc2 or newer. Install with:
# wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
# tar xzf sphinx*.tar.gz
# cd sphinx-0.9.9
# LDFLAGS="-arch x86_64" ./configure --prefix=/usr/local --with-mysql=/usr/local/mysql
# make && sudo make install
# sudo gem install thinking-sphinx
# wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
# tar xzf sphinx*.tar.gz
# cd spinx-0.9.9
# ./configure
# make && sudo make install
# sudo gem install thinking-sphinx
Once you have Sphinx and thinking-sphinx installed, the “sphinx” brick is automatically activated add all fulltext searches will go through Sphinx (you can change the setting in config/bricks.yml if you do not like this).
Since you will most likely use Sphinx in production, I will use this environment in the examples.
Just deploy your application and.. voilà: the sphinx search daemon will be started for you, a cron task will be added to reindex your data and you even have a worker up and running for the deltas.
In case you run into troubles or need to execute the commands by hand, read on…
Setup:
# rake RAILS_ENV=production sphinx:setup
Start search daemon:
# rake RAILS_ENV=production sphinx:start
Stop search daemon:
# rake RAILS_ENV=production sphinx:stop
To index your data, you have to run:
# rake RAILS_ENV=production sphinx:index
You can use the setup_indexer rake task to install/update the cron job for you.
If you have installed the “delayed_job” gem, the “worker” brick is activated and delta indexes are resolved with the “delayed_job” plugin. If you should therefore start a worker to handle the delta indexes (all changes that happen between two full indexes). Something like this starts the job:
# rake RAILS_ENV=production worker:start
To stop the worker:
# rake RAILS_ENV=production worker:stop
When the brick is activated on your development machine, the sphinx tasks will get inserted into the deployment process, starting and stopping the search deamon as needed.
If you have enabled sphinx in production mode on your development machine, this will automatically activate sphinx on the server. Make sure sphinx and thinking-sphinx are installed there !
For every rake task listed above, there is an equivalent capistrano task. These tasks are:
And if you want to see the details, have a look at the capistrano receipts in bricks/sphinx/deploy.rb and bricks/worker/deploy.rb and the rake tasks in bricks/sphinx/tasks.rb and bricks/worker/tasks.rb.
Gaspard Bucher
comments