sphinx在win上的安装 本例子目前还不支持中文搜索
下载MYSQL5.0.27以上版本 http://dev.mysql.com
从Sphinx官网上http://www.sphinxsearch.com/downloads.html下载sphinx-0.9.8-win32.zip 和mysql-5.0.45-sphinxse-0.9.8-
win32.zip
先将mysql服务停掉 解压mysql-5.0.45-sphinxse-0.9.8-win32.zip 将bin和share覆盖掉 mysql目录中的bin和share
解压sphinx-0.9.8-win32.zip到独立的目录,如:d:/www/sphinx/中
在test数据库中新建测试表
CREATE TABLE `documents` (
`id` int(11) NOT NULL auto_increment,
`group_id` int(11) NOT NULL,
`group_id2` int(11) NOT NULL,
`date_added` datetime NOT NULL,
`title` varchar(255) NOT NULL,
`content` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5;
INSERT INTO `documents` VALUES ('1', '1', '5', '2008-09-13 21:37:47', 'test one', 'this is my test document number
one. also checking search within phrases.');
INSERT INTO `documents` VALUES ('2', '1', '6', '2008-09-13 21:37:47', 'test two', 'this is my test document number
two');
INSERT INTO `documents` VALUES ('3', '2', '7', '2008-09-13 21:37:47', 'another doc', 'this is another group');
INSERT INTO `documents` VALUES ('4', '2', '8', '2008-09-13 21:37:47', 'doc number four', 'this is to test groups');
配置sphinx-doc.conf文件
将sphinx下的sphinx-min.conf复制一份改名为sphinx-doc.conf
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source documents
{
type = mysql
sql_host = localhost
sql_user = test
sql_pass = test
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 documents
{
source = documents
path = D:/www/sphinx/data/doc
morphology = extern
enable_star = 1
min_word_len = 3
min_prefix_len = 0
min_infix_len = 3
}
indexer
{
mem_limit = 32M
}
searchd
{
port = 3312
log = D:/www/sphinx/data/log/searchd-doc.log
query_log = D:/www/sphinx/data/log/query-doc.log
read_timeout = 5
max_children = 30
pid_file = D:/www/sphinx/data/log/searchd-doc.pid
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
}
启动mysql数据库 net start mysql
生成数据索引或重建索引
d:/www/sphinx/bin/indexer.exe --config d:/www/sphinx/bin/sphinx-doc.conf documents
运行检索守护进程 searchd.exe
d:/www/sphinx/bin/searchd.exe --config d:/www/sphinx/bin/sphinx-doc.conf
此时sphinx已经正常运行了,可以通过netstat -an 查看是否3312端口是否处如监听状态
现在来用sphinx自带的工具search.exe来测试一样
索引关键字: this is m
D:\www\sphinx\bin>search.exe -c d:/www/sphinx/bin/sphinx-doc.conf this is m
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff
using config file 'd:/www/sphinx/bin/sphinx-doc.conf'...
WARNING: index 'documents': invalid morphology option 'extern' - IGNORED
index 'documents': query 'this is m ': returned 4 matches of 4 total in 0.000 s
c
displaying matches:
1. document=1, weight=1, group_id=1, date_added=Sat Sep 13 21:37:47 2008
id=1
group_id=1
group_id2=5
date_added=2008-09-13 21:37:47
title=test one
content=this is my test document number one. also checking search withi
phrases.
2. document=2, weight=1, group_id=1, date_added=Sat Sep 13 21:37:47 2008
id=2
group_id=1
group_id2=6
date_added=2008-09-13 21:37:47
title=test two
content=this is my test document number two
3. document=3, weight=1, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=3
group_id=2
group_id2=7
date_added=2008-09-13 21:37:47
title=another doc
content=this is another group
4. document=4, weight=1, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=4
group_id=2
group_id2=8
date_added=2008-09-13 21:37:47
title=doc number four
content=this is to test groups
words:
1. 'this': 4 documents, 4 hits
索引关键字: this is another group
D:\www\sphinx\bin>search.exe -c d:/www/sphinx/bin/sphinx-doc.conf this is another group
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff
using config file 'd:/www/sphinx/bin/sphinx-doc.conf'...
WARNING: index 'documents': invalid morphology option 'extern' - IGNORED
index 'documents': query 'this is another group ': returned 1 matches of 1 total
in 0.000 sec
displaying matches:
1. document=3, weight=4, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=3
group_id=2
group_id2=7
date_added=2008-09-13 21:37:47
title=another doc
content=this is another group
words:
1. 'this': 4 documents, 4 hits
2. 'another': 1 documents, 2 hits
3. 'group': 1 documents, 1 hits
到此sphinx在win上算正常运行了,sphinx-doc.conf文件配置比较灵活,根据你需要索引的数据库进行灵活配置来达到你需要的效果
如果配置过程中出现运行参数配置问题可以查看 doc/sphinx.html文件,里面对各种参数都要详细的说明
参考资料:
http://www.sphinxsearch.com/wiki/doku.php?id=sphinx_chinese_tutorial
http://www.ibm.com/developerworks/cn/opensource/os-php-sphinxsearch/