在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