sphinx 配置&demo

下载0.99稳定版本

http://sphinxsearch.com/downloads/release

解压

tar -zvxf sphinx-0.9.9.tar.gz

安装

cd sphinx-0.9.9
./configure
make
&& make install

 

以下是sphinx自带一个例子(使用mysql, 还支持其它数据库) 


导入测试数据

mysql-u root -p  </usr/local/sphinx/etc/example.sql

创建配置文件

cd /usr/local/sphinx/etc
cp sphinx
.conf.dist sphinx.conf
vi sphinx
.conf

设置数据库信息

   type                    =mysql

#####################################################################
## SQL settings (for 'mysql' and 'pgsql' types)
#####################################################################

# some straightforward parameters for SQL source types
sql_host = localhost
sql_user
= root
sql_pass
= admin
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

设置索引(以上是在src1{...}中的)

index test1
{
	source			= src1
	path			= /usr/local/sphinx/var/data/test1
        .....
}

生成索引

cd /usr/local/sphinx/etc
/usr/local/sphinx/bin/indexer

在命令行进行搜索

cd /usr/local/sphinx/etc
/usr/local/sphinx/bin/search test

 

php下调用shpinx进行搜索(这是源码api中php cli模式的用例,还有其它语言调用的相关用例)


cd sphinx/api
php test
.php test

posted on 2011-09-19 16:28  bluefrog  阅读(811)  评论(0编辑  收藏  举报