Ryan Bates has a helpful screencast about the using the excellent Thinking Sphinx Rails plugin for the Sphinx search engine.

There seems to be a bit of confusion over how to enable wildcard (star) searches with Thinking Sphinx. Wildcard searches would let you search for partial words, so “thin*” would match “Thinking Sphinx” and “Thinner”. This is pretty useful, and for Donor Tools it is essential.

Turns out it’s really easy to turn on wildcard search. There is no need to make any changes to your Sphinx setup or add a config/sphinx.yml file. In your define_index block, simply add enable_star and min_prefix_len like so:

1
2
3
4
5
define_index do
  ...
  set_property :enable_star => true
  set_property :min_prefix_len => 3
end

enable_star simply turns on wildcard searching. However, this won’t do much good unless you also enable prefix indexing using min_prefix_len.

min_prefix_len sets the minimum number of letters that Sphinx will index. From the Sphinx docs:

...indexing a keyword “example” with min_prefix_len=3 will result in indexing “exa”, “exam”, “examp”, “exampl” prefixes along with the word itself.

You can also set min_infix_len, which does the same thing as min_prefix_len, except it does it on the middle of the word.

Infix indexing allows to implement wildcard searching by ‘start*’, ’*end’, and ’*middle*’ wildcards.

Caution: Infix indexing can cause your index to grow, and may slow down searching.

Now, re-run rake thinking_sphinx:configure, re-index (rake ts:in), and restart the Sphinx daemon (rake ts:run), and it should work.