下载,安装
下载sphinx-0.9.8.1.tar.gz(在撰写本文时,0.9.8.1是最新版)
安装、启动、使用Sphinx:
./configure --prefix=/usr/local/sphinx
make;make install
cp sphinx-min.conf.dist sphinx.conf
cd /usr/local/sphinx/etc/
配置sphinx的索引任务:
配置sphinx的数据源,Mysql信息配置:
vi sphinx.conf
source src1
{
type = mysql
sql_host = localhost
sql_user = root
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
}
// ./search --config /usr/local/sphinx/etc/sphinx.conf test
index test1
{
source = src1
path = /usr/local/sphinx/var/data/test1
docinfo = extern
charset_type = sbcs
}
bogon:/usr/local/sphinx/bin # ./indexer --config /usr/local/sphinx/etc/sphinx.conf test1
./searchd --config /usr/local/sphinx/etc/sphinx.conf &
bogon:/usr/local/sphinx/bin # ./search --config /usr/local/sphinx/etc/sphinx.conf test
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff
using config file '/usr/local/sphinx/etc/sphinx.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec
displaying matches:
1. document=1, weight=2, group_id=1, date_added=Sun Dec 12 16:28:37 2010
id=1
group_id=1
group_id2=5
date_added=2010-12-12 16:28:37
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=Sun Dec 12 16:28:37 2010
id=2
group_id=1
group_id2=6
date_added=2010-12-12 16:28:37
title=test two
content=this is my test document number two
3. document=4, weight=1, group_id=2, date_added=Sun Dec 12 16:28:37 2010
id=4
group_id=2
group_id2=8
date_added=2010-12-12 16:28:37
title=doc number four
content=this is to test groups
words:
1. 'test': 3 documents, 5 hits
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/3861/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表