本文共 2756 字,大约阅读时间需要 9 分钟。
http://sphinxsearch.com/
sudo apt-get install sphinxsearch
/etc/sphinxsearch/sphinx.conf
sudo cp /etc/sphinxsearch/sphinx-min.conf.dist /etc/sphinxsearch/sphinx.conf
创建测试数据库并导入测试数据
$ wget http://sphinxsearch.googlecode.com/svn/trunk/example.sql$ mysql -h localhost -uroot -p < example.sql$ mysql -h localhost -uroot -pCREATE USER 'test'@'localhost' IDENTIFIED BY '';GRANT SELECT ON test.* TO 'test'@'localhost';FLUSH PRIVILEGES;mysql> quit$ echo "select * from documents" | mysql -utest -p testEnter password:id group_id group_id2 date_added title content1 1 5 2011-02-12 15:29:34 test one this is my test document number one. also checking search within phrases.2 1 6 2011-02-12 15:29:34 test two this is my test document number two3 2 7 2011-02-12 15:29:34 another doc this is another group4 2 8 2011-02-12 15:29:34 doc number four this is to test groups
创建索引
sudo indexer <index>
$ sudo indexer test1Sphinx 0.9.8.1-release (r1533)Copyright (c) 2001-2008, Andrew Aksyonoffusing config file '/etc/sphinxsearch/sphinx.conf'...indexing index 'test1'...collected 4 docs, 0.0 MBsorted 0.0 Mhits, 100.0% donetotal 4 docs, 193 bytestotal 0.012 sec, 16531.05 bytes/sec, 342.61 docs/sec
$ sudo /etc/init.d/sphinxsearch startStarting sphinx: Sphinx 0.9.8.1-release (r1533)Copyright (c) 2001-2008, Andrew Aksyonoffusing config file '/etc/sphinxsearch/sphinx.conf'...creating server socket on 0.0.0.0:3312sphinx.
测试
search "keyword"
$ search testSphinx 0.9.8.1-release (r1533)Copyright (c) 2001-2008, Andrew Aksyonoffusing config file '/etc/sphinxsearch/sphinx.conf'...index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 secdisplaying matches:1. document=1, weight=2, group_id=1, date_added=Sat Feb 12 15:29:34 2011 id=1 group_id=1 group_id2=5 date_added=2011-02-12 15:29:34 title=test one content=this is my test document number one. also checking search within phrases.2. document=2, weight=2, group_id=1, date_added=Sat Feb 12 15:29:34 2011 id=2 group_id=1 group_id2=6 date_added=2011-02-12 15:29:34 title=test two content=this is my test document number two3. document=4, weight=1, group_id=2, date_added=Sat Feb 12 15:29:34 2011 id=4 group_id=2 group_id2=8 date_added=2011-02-12 15:29:34 title=doc number four content=this is to test groupswords:1. 'test': 3 documents, 5 hits
wget http://sphinxsearch.googlecode.com/svn/trunk/api/sphinxapi.phpwget http://sphinxsearch.googlecode.com/svn/trunk/api/test.phpphp test.php test原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。