Installing Thinking Sphinx
There’s a few different ways you can get Thinking Sphinx installed into your web application. I highly 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.
As a Gem
There’s a few steps to using Thinking Sphinx as a gem. Firstly, let’s install it from Gemcutter:
gem install thinking-sphinx \
--source http://gemcutter.org
If you’re using Merb, then you just need to require the library within your init.rb:
require 'thinking_sphinx/0.9.8'
For Rails users, you’ll need to add the gem to your configuration setup in environment.rb:
config.gem(
'thinking-sphinx',
:lib => 'thinking_sphinx/0.9.8',
:version => '1.3.3'
)
If you’re using Sphinx 0.9.9, set the lib value appropriately (or change the require statement if you’re using Merb).
config.gem(
'thinking-sphinx',
:lib => 'thinking_sphinx/0.9.9',
:version => '1.3.3'
)
And one last thing: ensure the rake tasks are available by adding the following lines to your Rakefile (change the Sphinx version if necessary):
require 'thinking_sphinx/0.9.8'
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
If you’re using Sphinx 0.9.9, then you’ll need to manually add a require statement to the end of your environment.rb:
require 'thinking_sphinx/0.9.9'
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
Again, if you’re using Sphinx 0.9.9, then you’ll need to manually add a require statement to the end of your environment.rb:
require 'thinking_sphinx/0.9.9'
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
And just like in the other ways of installing Thinking Sphinx as a plugin, if you’re using Sphinx 0.9.9, make sure you add a require statement to the end of your environment.rb:
require 'thinking_sphinx/0.9.9'