在ubuntu上安装全文搜索中文分词Coreseek/sphinx 及和Rails集成
Sphinx(狮身人面像) 想必大家都比较了解,就不作介绍了,不了解的童鞋可以自己Google。
原生Sphinx不支持中文,
所以这里重点介绍支持中文分词的 Coreseek。
注意:Coreseek 3.2 后,只有安装 Coreseek 就可以了,它对LibMMSeg和sphinx做了整合,不用再安装原生Sphinx。(3.2前是要安装原生Sphinx,还要装补丁,非常繁琐)
安装coreseek
下面以coreseek-3.2.14为例,它基于Sphinx 0.99(不用安装Sphinx 0.99)
详细官方手册:http://www.coreseek.cn/products-install/install_on_bsd_linux/
ubuntu-10.04 安装 coreseek安装需要预装的软件:
#创建rails项目全文搜索数据目录cd 你的rails目录mkdir fulltext_search_data#从安装包中复制字典到Rails项目cp /tmp/coreseek-3.2.14/mmseg-3.2.14/data/*.* 你的rails目录/fulltext_search_data#新建配置文件:vi config/sphinx.yml#内容如下:test: bin_path: /opt/coreseek/bin mem_limit: 128M config_file: config/test.sphinx.conf charset_type: zh_cn.utf-8 charset_dictpath: <%=::Rails.root.to_s + "/fulltext_search_data "%> pid_file: "/tmp/searchd.test.pid" ngram_len: 0development: bin_path: /opt/coreseek/bin mem_limit: 128M config_file: config/development.sphinx.conf charset_type: zh_cn.utf-8 charset_dictpath: <%=::Rails.root.to_s + "/fulltext_search_data "%> pid_file: "/tmp/searchd.development.pid" ngram_len: 0production: bin_path: /opt/coreseek/bin mem_limit: 128M config_file: config/production.sphinx.conf charset_type: zh_cn.utf-8 charset_dictpath: <%=::Rails.root.to_s + "/fulltext_search_data "%> pid_file: "/tmp/searchd.production.pid" ngram_len: 0#建立配置文件rake thinking_sphinx:configure#建立索引rake thinking_sphinx:index#开启服务rake thinking_sphinx:start#现在可以先加些数据,在浏览器中访问你的controller测试搜索#也可以用如下命令来测试全文搜索引擎search '关键字' -c 你的Rsils项目/config/development.sphinx.conf
最后再补几点注意事项:
1.定义索引时 "set_property :delta => true", 没有这句新加的记录不会索引。
2.coreseek 安装包中的字典文件一定要复制到Rails项目数据目录,否则中文无法支持。
参考资料:
详见:https://github.com/freelancing-god/thinking-sphinx
官方手册:http://freelancing-god.github.com/ts/en/installing_thinking_sphinx.html
快速实现:http://freelancing-god.github.com/ts/en/quickstart.html
1 楼 helloqidi 2012-04-17 谢谢博主分享