How To Install Sphinx On Ubuntu 10.10
First of all, this is my first post and I apologize for the bad English.
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.
If you use Ubuntu 10.10, you can use
sudo apt-get install sphinxsearch
to install Sphinx.
Sphinx uses a configuration file (/etc/sphinxsearch/sphinx.conf). You should adjust this file to your configuration.
vi /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
Ok - here's a configuration file sample:
source src1 { type = mysql sql_host = localhost sql_user = test sql_pass = sql_db = test sql_port = 3306 # optional, default is 3306 sql_query = \ SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \ FROM documents sql_attr_uint = group_id sql_attr_timestamp = date_added sql_query_info = SELECT * FROM documents WHERE id=$id } index test1 { source = src1 path = /var/lib/sphinxsearch/data/test1 docinfo = extern charset_type = sbcs } indexer { mem_limit = 32M } searchd { port = 9312 log = /var/log/sphinxsearch/searchd.log query_log = /var/log/sphinxsearch/query.log read_timeout = 5 max_children = 30 pid_file = /var/run/searchd.pid max_matches = 1000 seamless_rotate = 1 preopen_indexes = 0 unlink_old = 1 }
I use MySQL this tutorial.You might have to adjust parameters and you must create data in MySQL. For example:
Mysql dump file:
DROP TABLE IF EXISTS test.documents;
CREATE TABLE test.documents
(
id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
group_id INTEGER NOT NULL,
group_id2 INTEGER NOT NULL,
date_added DATETIME NOT NULL,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL
);
REPLACE INTO test.documents ( id, group_id, group_id2, date_added, title, content ) VALUES
( 1, 1, 5, NOW(), 'test one', 'this is my test document number one. also checking search within phrases.' ),
( 2, 1, 6, NOW(), 'test two', 'this is my test document number two' ),
( 3, 2, 7, NOW(), 'another doc', 'this is another group' ),
( 4, 2, 8, NOW(), 'doc number four', 'this is to test groups' );
DROP TABLE IF EXISTS test.tags;
CREATE TABLE test.tags
(
docid INTEGER NOT NULL,
tagid INTEGER NOT NULL,
UNIQUE(docid,tagid)
);
INSERT INTO test.tags VALUES
(1,1), (1,3), (1,5), (1,7),
(2,6), (2,4), (2,2),
(3,15),
(4,7), (4,40);
Finally you must run
sudo indexer test1
OK.
Now let's test. :)
You run
search "test"
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.
You can read more details about Sphinx here: http://sphinxsearch.com/docs/1.10/