How To Install Sphinx On Ubuntu

Sphinx is a full-text search engine, publicly distributed under GPL version 2. Commercial licensing (eg. for embedded use) is available upon request. You can use Sphinx for creating big data indexes. It supports MySQL, PostgreSQL, ODBC.

In Ubuntu to install Sphinx:

sudo apt-get install sphinxsearch

or download and install the latest .deb Sphinx package

Install official Launchpad’s repository to get the latest release every week (temporarily only 12.04 LTS packages are available) :

sudo add-apt-repository ppa:builds/sphinxsearch-stable

To enable sphinxsearch, edit /etc/default/sphinxsearch and set START=yes

Sphinx uses a configuration file (/etc/sphinxsearch/sphinx.conf). You should adjust this file to your configuration.

sudo nano  /etc/sphinxsearch/sphinx.conf

The conf file consists out of four parts:

source: data source definition

index: index settings for your data source

indexer: consists out of indexer settings (cause path, charset and so on)

searchd: searchd settings

 #
# Sphinx configuration file sample
#
#############################################################################
## data source definition
#############################################################################

source src1
{

type            = mysql

#####################################################################
## SQL settings (for ‘mysql’ and ‘pgsql’ types)
#####################################################################
sql_host        = localhost
sql_user        = user
sql_pass        = pass
sql_db            = test
sql_port        = 3306    # optional, default is 3306

sql_query_pre        = SET NAMES utf8

sql_query_pre        = SET CHARACTER_SET_RESULTS=utf8
sql_query        = \
SELECT data.id, data.title, data.content \
FROM data
sql_attr_uint        = id
sql_ranged_throttle    = 0
}
#############################################################################
## index definition
#############################################################################
index data1
{

source            = src1

docinfo            = extern
mlock            = 0
morphology        = none
min_word_len        = 2
charset_type        = utf-8

charset_table        = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F

min_prefix_len        = 1
enable_star        = 1

html_strip        = 0
}

#############################################################################
## indexer settings
#############################################################################

indexer
{

mem_limit        = 1024M
}

#############################################################################
## searchd settings
#############################################################################

searchd
{

listen            = 9312
listen            = 9306:mysql41
log            = /var/log/sphinxsearch/searchd.log
query_log        = /var/log/sphinxsearch/query.log
read_timeout        = 5
client_timeout        = 300
max_children        = 30
pid_file        = /var/run/searchd.pid
max_matches        = 1000
seamless_rotate        = 1
preopen_indexes        = 1
unlink_old        = 1
mva_updates_pool    = 1M
max_packet_size        = 8M
max_filters        = 256
max_filter_values    = 4096

max_batch_queries    = 32

workers            = threads # for RT to work

}

Finally you must run

sudo indexer –all

sudo searchd

For testing run

search “test” (a word included in fields title or content)

If there are no problems, you should see a result.

You can use Sphinx for more functionalities.You can define your indexes and attributes on source.

Read more details about Sphinx here: http://sphinxsearch.com