Minimal Sphinx configuration to play with Sphinx

If you want to start learning Sphinx or see how some its feature works the following simplest Sphinx configuration might be useful:

source min
{
    type = mysql 
    sql_host = localhost
    sql_user = root
    sql_pass =
    sql_db = test
    sql_query = select 1, 'cat' union select 2, 'dog'
}

index idx_min
{
    path = idx
    source = min
}

searchd
{
    listen = 9306:mysql41
    log = sphinx.log
    pid_file = sphinx.pid
    binlog_path =
}

It contains almost nothing, but only those things Sphinx cannot work without. Those are:

  • Section “source” to fetch data from mysql. In this case we don’t even fetch real data from mysql, but just use mysql interface having the data defined right in the config (“select 1, ‘cat’ union select 2, ‘dog'”). It will create 2 documents in Sphinx: one containing word “cat”, another one with word “dog”, the ids are 1 and 2 respectively.
  • Section “index” to create index based on the above source, it contains only reference to the source (“source = min”) and path to the index (“path = idx”). Once you build this index files idx.* will be created in the dir you start ‘indexer’ from.
  • Section “searchd” to tell Sphinx what ports it should be listening (“listen = 9307:mysql41” which means that SphinxQL should be used to talk to Sphinx on this port), what log it should use (“log = sphinx.log”) and where it should save its process id (“pid_file = sphinx.pid”)

Here’s an example of using this config:

  • Indexing:

    [snikolaev@srv ~]$ indexer -c sphinx_min.conf --all
    Sphinx 0.9.10-dev (r1996)
    Copyright (c) 2001-2009, Andrew Aksyonoff
    
    using config file 'sphinx_min.conf'...
    indexing index 'idx_min'...
    collected 2 docs, 0.0 MB
    sorted 0.0 Mhits, 100.0% done
    total 2 docs, 6 bytes
    total 0.097 sec, 61 bytes/sec, 20.51 docs/sec
    total 2 reads, 0.000 sec, 16.0 kb/call avg, 0.0 msec/call avg
    total 6 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
    
  • Using ‘search’ tool to find some results:

    
    [snikolaev@srv ~]$ search -c sphinx_min.conf dog
    Sphinx 0.9.10-dev (r1996)
    Copyright (c) 2001-2009, Andrew Aksyonoff
    
    using config file 'sphinx_min.conf'...
    index 'idx_min': query 'dog ': returned 1 matches of 1 total in 0.097 sec
    
    displaying matches:
    1. document=2, weight=1643
    
    words:
    1. 'dog': 1 documents, 1 hits
    
    
    [snikolaev@srv ~]$ search -c sphinx_min.conf "dog|cat"
    Sphinx 0.9.10-dev (r1996)
    Copyright (c) 2001-2009, Andrew Aksyonoff
    
    using config file 'sphinx_min.conf'...
    index 'idx_min': query 'dog|cat ': returned 2 matches of 2 total in 0.000 sec
    
    displaying matches:
    1. document=1, weight=1571
    2. document=2, weight=1571
    
    words:
    1. 'dog': 1 documents, 1 hits
    2. 'cat': 1 documents, 1 hits
    
    
  • Starting ‘searchd’ and fetching results using mysql client:

    [snikolaev@srv ~]$ searchd -c sphinx_min.conf 
    Sphinx 0.9.10-dev (r1996)
    Copyright (c) 2001-2009, Andrew Aksyonoff
    
    using config file 'sphinx_min.conf'...
    listening on all interfaces, port=9306
    precaching index 'idx_min'
    precached 1 indexes in 0.352 sec                            
    
    
    [snikolaev@srv ~]$ mysql -hlocalhost -P9306 --protocol=tcp
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 0.9.10-dev (r1996)
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> select * from idx_min where match('cat');
    +------+--------+
    | id   | weight |
    +------+--------+
    |    1 |   1643 | 
    +------+--------+
    1 row in set (0.23 sec)
    
    mysql> select * from idx_min where match('dog');
    +------+--------+
    | id   | weight |
    +------+--------+
    |    2 |   1643 | 
    +------+--------+
    1 row in set (0.00 sec)
    

Enjoy playing with Sphinx!

10 Comments

ssnobbenJune 6th, 2011 at 1:52 pm

Thanks for your great improvment of the search functions!

Looking forward to next version of your Sphinx integration to Joomla 1.6

rgds

KishorJanuary 24th, 2012 at 7:18 am

Does precaching index , prevent newer data from getting searched ?

Sergey NikolaevJanuary 25th, 2012 at 3:26 am

Hello Kishor. Precaching index doesn’t actually have anything with newer data. It’s just that Sphinx precaches an index on start. To make newer data searchable you need one of the following:
– rebuild the index
– use main + delta scheme (you can find some info here http://www.ivinco.com/blog/five-ways-to-configure-sphinx-search-engine/) and rebuild the delta index
– use real time indexes to put the new data to the index w/o reindexing (you can read a bit here http://www.ivinco.com/blog/should-you-switch-to-sphinx-real-time-indexes/ )

yaMarch 12th, 2012 at 7:55 am

help! windows hosting wordpress !!! not work.

Sergey NikolaevMarch 12th, 2012 at 11:03 am

Hello Ya

Can you say in more details what is not working?

yaMarch 12th, 2012 at 7:00 pm

I have started service E:\sphinx\bin\searchd.exe –install –config “E:\sphinx\bin\labok.conf” –servicename labok-index

The plug-in writes Warning: Sphinx Search Server is NOT running.

Sergey NikolaevMarch 13th, 2012 at 1:49 am

Does the search work?

yaMarch 13th, 2012 at 5:37 am

Если смотреть E:\Sphinx\log\query.txt не работает.

For words in English searches.

yaMarch 13th, 2012 at 5:38 am

If to look E:\Sphinx\log\query.txt doesn’t work.

Sergey NikolaevMarch 14th, 2012 at 4:39 am

Ya, please contact me at opensource@ivinco.com, we can discuss this in Russian

Leave a comment

Your comment