March 26, 2008

Installing Sphinx & Ultrasphinx on Windows

Tags: , ,

So you have decided to add full-text searching to your Ruby on Rails application. After some investigation (see here and here) Sphinx with the Ultrasphinx plugin looks like the best solution for your needs. Just one problem, despite your deployment environment being Linux, for various reasons your current development environment is Windows. While Sphinx runs on Windows, it explicitly states it prefers to run on other systems and there are a few little gotchas. Here is the step by step guide to getting it working:

  1. Download the Windows binaries rather than the source code.
  2. Extract the contents of the bin/release folder in the zip file you just downloaded into a location of your choice (eg. C:\Sphinx).
  3. Add the location of the folder in step 2 into your system path.
  4. Install chronic – gem install chronic
  5. Install Ultrasphinx – svn export svn:// vendor/plugins/ultrasphinx
  6. Copy the example default.base to the app config folder and edit it. The path variable is the path to the location of the index (created in step 10), not the Sphinx binaries. Also, find the “set_rotate” option and set it to 0. This is not supported on Windows at the time of writing. You probably want to have this set differently in production.
  7. Run rake ultrasphinx:configure You should now have a Sphinx conf file.
  8. Add indexing to your model.
  9. Edit the Ultrasphinx.rake (in plugins/ultrasphinx/tasks) and where you see ‘#{Ultrasphinx::CONF_PATH}’ remove the apostrophes, otherwise the rake task below won’t be able to find the configuration file.
  10. Run rake ultrasphinx:index You should now have an index in the location specified in the conf path.
  11. Run rake ultrasphinx:daemon:start The sphinx daemon should start up.
  12. You are done and should be able to search. Good luck.

Update: In case you are not reading the comments, Naomi Novik has pointed out that Sphinx/Ultrasphinx doesn’t seem to want to work if the Rails project is in a directory with spaces in the path.

Update: Some people have had problems beyond those I mentioned above. Take a look at this and this if you have extra problems.

comments powered by Disqus