Sphinx 安装备忘
以前装过一次sphinx,现在有了中文站coreseek,他们整合了中文分词,相对来说还是方便了不少,coreseek的包里除了sphinx以外还有mmseg和一个用于测试的代码包,安装还算顺利。
安装文档见这里
http://www.coreseek.cn/products-install/install_on_bsd_linux/
在安装sphinx php扩展的时候略微麻烦了一下,直接用pecl install sphinx不成功,说找不到libsphinxclient库,后来发现libsphinxclient就在coreseek-4.1-beta/testpack/api/libsphinxclient路径下,安装之。
然后还是不能用pecl方式安装,在这里 http://pecl.php.net/package/sphinx 下载了安装包,用phpize方式安装ok。
如不安装php扩展,在testpack目录里也有一php版本的sphinx class可以使用。
对于mysql的应用,先按提示修改好csft_mysql.conf里的相关参数
然后建索引
/usr/local/coreseek/bin/indexer -c etc/csft_mysql.conf –all
如果服务器已经启动,建索引是不能覆盖的,需要加入–rotate参数
/usr/local/coreseek/bin/indexer -c etc/csft_mysql.conf –all –rotate
启动服务
/usr/local/coreseek/bin/searchd -c etc/csft_mysql.conf
停止服务
/usr/local/coreseek/bin/searchd -c etc/csft_mysql.conf –stop
启动服务后,可用php进行查询。。
1 2 3 4 5 6 7 8 9 10 11 |
另外还有一些高级用法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | //注意文件的编码格式需要保存为为UTF-8格式 require ( "sphinxapi.php" ); $cl = new SphinxClient (); $cl->SetServer ( '127.0.0.1', 9312); //以下设置用于返回数组形式的结果 $cl->SetArrayResult ( true ); /* //ID的过滤 $cl->SetIDRange(3,4); //sql_attr_uint等类型的属性字段,需要使用setFilter过滤,类似SQL的WHERE group_id=2 $cl->setFilter('group_id',array(2)); //sql_attr_uint等类型的属性字段,也可以设置过滤范围,类似SQL的WHERE group_id2>=6 AND group_id2<=8 $cl->SetFilterRange('group_id2',6,8); */ //取从头开始的前20条数据,0,20类似SQl语句的LIMIT 0,20 $cl->SetLimits(0,20); //在做索引时,没有进行 sql_attr_类型 设置的字段,可以作为“搜索字符串”,进行全文搜索 $res = $cl->Query ( '搜索字符串', "*" ); //"*"表示在所有索引里面同时搜索,"索引名称(例如test或者test,test2)"则表示搜索指定的 //如果需要搜索指定全文字段的内容,可以使用扩展匹配模式: //$cl->SetMatchMode(SPH_MATCH_EXTENDED); //$res=cl->Query( '@title (测试)' , "*"); //$res=cl->Query( '@title (测试) @content ('网络')' , "*"); echo '<pre>'; print_r($res['matches']); print_r($res); print_r($cl->GetLastError()); print_r($cl->GetLastWarning()); echo '</pre>'; |
给字典加入新词
/usr/local/mmseg3/etc下有个unigram.txt文件
这个是字典的文本版本
加入新词需要加入两行,如
新浪微博 1
x:1
然后执行命令mmseg -u unigram.txt
将生成一个unigram.txt.lib文件,将etc目录里的uni.lib改名,并把这个文件改名为uni.lib,重新生成索引
详细一点的可以看这里
http://hi.baidu.com/cubeking/blog/item/9aedb7a67b5b95e29152ee5c.html
一月 17th, 2012 at 11:02
[...] http://www.cruelyouth.com/2011/10/28/sphinx-%e5%ae%89%e8%a3%85%e5%a4%87%e5%bf%98/ [...]
一月 17th, 2012 at 11:13
hello
一月 17th, 2012 at 11:13
1111