Sphinx Cheatsheet

Creating index

$ sudo indexer -c sphinx.conf --all

Rebuild index

$ sudo indexer -c sphinx.conf --all --rotate

Enable wildcard index

Add the following lines to your index section

enable_star             = 1
min_infix_len           = 1

Enable stemming

Add the following lines to your index section

morphology = stem_en

Start / Stop

$ service searchd restart

Querying

$ mysql -h0 -P9306

mysql> SELECT * FROM idx WHERE MATCH('my document');
mysql> SELECT * FROM idx WHERE MATCH('@host wikipedia');
    mysql> SELECT * FROM idx WHERE MATCH('@Name("^Fred Bloggs$")');

Operators

  • AND: lettuce bacon tomato
  • OR: one | two
  • NOT: shaken !stirred or shaken -stirred
  • NEAR:
  • SENTENCE:
  • PARAGRAPH:
  • ZONE:
  • Phrase: "Harry Potter"
  • Field: @author rowling

Gotchas

  • editing sphinx.conf requires a restart
  • you cannot use a primary key for sql_attr_uint
  • every item in sql_attr_XXX needs to have the name specified in sql_query

mysqli::real_connect(): Server sent charset (0) unknown to the client. Please, report to the developers

Upgrade sphinx to > 2.0.6 here

  • FATAL: binlog meta file /var/lib/sphinxsearch/binlog.meta is v.4, binary is v.5; recovery requires previous binary version
  • Recipes

Installing on ubuntu

  • Find correct .deb package here
  • Install dpkg -i ./sphinxsearch_2.2.10-release-0ubuntu12~trusty_amd64.deb followed by sudo apt-get install -f source