Padawan coder

Getting from zero to hero...

Decrypting Thinking Sphinx

| Comments

3 things to be aware of when installing Thinking Sphinx

My key takeaway from installing the Thinking Sphinx gem for a project, is that Thinking Sphinx is extremely finickety.

The steps seem simple enough on the Thinking Sphinx documentation website, but many errors and hours later, I can attest that it is full of pitfalls for the unwary, or the plain unlucky.

Our initial steps to install Thinking Sphinx for Rails 3.1 and above - which threw a bunch of errors - were to do the following:
1) brew install sphinx
2) brew install mysql
3) added the following to the Gemfile
- gem ‘mysql2’
- gem ‘thinking-sphinx’

Things I learnt from my experience are as follows:

1) You need to have a specific (older) version of MySQL installed (5.5.28)

Initially Sphinx threw its toys out of the pram because it couldn’t find the correct version of MySQL because brew had automatically installed the latest version of MySQL (5.6.10)

We downloaded 5.5.30 from Or alternatively, you can follow the instructions on this gist to install older versions of mysql using Homebrew. This ushered in the next set of fairly obscure errors.

2) When using Thinking Sphinx with a Postgres database (which we are doing for our project), install Sphinx with both the mysql and postgres flags

The next set of errors from our attempt to debug and install TS, were mostly variants of: ‘ERROR: source ‘location_core_0’: unknown type ‘mysql’ ; skipping’, ‘Can't connect to MySQL server [or client or lib]’

Although the docs say that Sphinx will automatically detect whether you have MySQL of PostgresSQL, that wasn’t the case for us.

And the only combination that worked was brew install sphinx -–mysql -–pgsql (we had tried all the other permutations before this one finally worked, sort of).

3) Follow the gem version to the letter

After the installation of sphinx, bundling of gems, and running of rake ts:index and rake ts:start, we ran our search in rails console, which returned a Thinking Sphinx object #<ThinkingSphinx::Search:0x3fc3d2550958>, which resulted in the error undefined method `next_result' for #<Mysql2::Client:0xac86a54>

We eventually found the solution in Thinking Sphinx’s github issues. Our mistake had been to assume that Thinking Sphinx would work with the latest releases of mysql and thinking-sphinx gems, which is why we had not included the specific gem version in our Gemfile.

But Thinking Sphinx was pernickety enough to require the exact version ‘0.3.12b5’ of ‘mysql2’ (yes, down to ‘b5’!).