Installing Thinking Sphinx
There’s a few different ways you can get Thinking Sphinx installed into your web application. I recommend installing as a gem (and indeed, if you’re using Merb, then you’ll have to use the gem). If you’re using Rails and prefer a plugin, read through the options further down the page.
Please note: If you’re using Sphinx 0.9.9 (as opposed to 0.9.8), then you’ll want to download the sphinx-0.9.9 branch from the GitHub repository, or use the 099 gem (see below).
As a Gem
There’s a few steps to using Thinking Sphinx as a gem. Firstly, let’s install it from GemCutter:
sudo gem install thinking-sphinx \
--source http://gemcutter.org
If you’re using Sphinx 0.9.9, then make sure you grab the 099 version instead:
sudo gem install thinking-sphinx-099 \
--source http://gemcutter.org
It’s recommended to not install both versions of the library – choose a version, and stick with it.
If you’re using Merb, then you just need to require the library within your init.rb:
require 'thinking_sphinx'
For Rails users, you’ll need to add the gem to your configuration setup in environment.rb:
config.gem(
'thinking-sphinx',
:lib => 'thinking_sphinx',
:version => '1.2.12'
)
Again, if you’re using Sphinx 0.9.9, set the gem name appropriately.
config.gem(
'thinking-sphinx-099',
:lib => 'thinking_sphinx',
:version => '1.2.12'
)
And one last thing: ensure the rake tasks are available by adding the following line to your Rakefile:
require 'thinking_sphinx/tasks'
As a Plugin with Rails 2.1 or newer and Git
If you’ve got git installed, and are using Rails 2.1 or newer, then it’s painless to get Thinking Sphinx installed in your Rails application:
script/plugin install \
git://github.com/freelancing-god/thinking-sphinx.git
As a Plugin with Rails 2.0 or older and Git
If you’ve got git, but using one of the older versions of Rails, then things are slightly more complicated.
git clone \
git://github.com/freelancing-god/thinking-sphinx.git \
vendor/plugins/thinking_sphinx
And if you want to make sure it all gets committed to git as part of your main repository, don’t forget to remove the plugin’s .git directory.
rm -r vendor/plugins/thinking_sphinx/.git
As a Plugin without Git
If you don’t have git installed, all is not lost. You can either manually download the tarball from GitHub, and then extract it into your vendor/plugins directory, or you can run the following shell commands from the root of your Rails application, which do exactly the same thing.
curl -L \
http://github.com/freelancing-god/thinking-sphinx/tarball/master \
-o thinking-sphinx.tar.gz
tar -xvf thinking-sphinx.tar.gz -C vendor/plugins
mv vendor/plugins/freelancing-god-thinking-sphinx* \
vendor/plugins/thinking-sphinx
rm thinking-sphinx.tar.gz