- 浏览: 29259 次
- 性别:
- 来自: 温州
文章分类
最新评论
-
helloqidi:
谢谢博主分享
在ubuntu上安装全文搜索中文分词Coreseek/sphinx 及和Rails集成 -
jim.jin:
谢谢提醒。
设计模式与动态语言 之 Observer -
open2ye:
有错别字 有错别字
设计模式与动态语言 之 Observer
在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项目
这里用的是gem thinking-sphinx
如果没有新项目自己创建Rails项目,这里不做说明。
可以参考Railscasts: http://railscasts.com/episodes/120-thinking-sphinx?autoplay=true
安装 thinking-sphinx
官方手册:http://freelancing-god.github.com/ts/en/installing_thinking_sphinx.html
这里只说明下 rails 3.0
在Gemfile中加入
然后
可以参考快速实现:http://freelancing-god.github.com/ts/en/quickstart.html
在model中定义索引
记得添加实时索引字段 delta
在controller中加search代码,controler大家自己建啦。
最后再补几点注意事项:
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
原生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安装需要预装的软件:
sudo apt-get install make gcc g++ automake libtool mysql-client libmysqlclient15-dev libxml2-dev libexpat1-dev
#下载 coreseek-3.2.14,里面已经包含 mmseg cd /tmp wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz tar xzvf coreseek-3.2.14.tar.gz cd coreseek-3.2.14 # 先安装mmseg cd mmseg-3.2.14 ./bootstrap #输出的warning信息可以忽略,如果出现error则需要解决 ./configure --prefix=/opt/mmseg [color=red]#下面安装coreseek 需要此路径[/color] sudo make && sudo make install #安装coreseek cd .. cd csft-3.2.14 sh buildconf.sh #输出的warning信息可以忽略,如果出现error则需要解决 ./configure --prefix=/opt/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/opt/mmseg/include/mmseg/ --with-mmseg-libs=/opt/mmseg/lib/ --with-mysql ##如果提示mysql问题,可以查看MySQL数据源安装说明 sudo make && sudo make install cd .. #然后建立命令快捷方式,方便使用 sudo ln -s /opt/coreseek/bin/indexer /usr/local/bin/indexer sudo ln -s /opt/coreseek/bin/indextool /usr/local/bin/indextool sudo ln -s /opt/coreseek/bin/search /usr/local/bin/search sudo ln -s /opt/coreseek/bin/searchd /usr/local/bin/searchd sudo ln -s /opt/coreseek/bin/spelldump /usr/local/bin/spelldump
集成到rails项目
这里用的是gem thinking-sphinx
如果没有新项目自己创建Rails项目,这里不做说明。
可以参考Railscasts: http://railscasts.com/episodes/120-thinking-sphinx?autoplay=true
安装 thinking-sphinx
官方手册:http://freelancing-god.github.com/ts/en/installing_thinking_sphinx.html
这里只说明下 rails 3.0
在Gemfile中加入
gem 'thinking-sphinx'
然后
bundle install
可以参考快速实现:http://freelancing-god.github.com/ts/en/quickstart.html
在model中定义索引
class Post < ActiveRecord::Base define_index do indexes :title, :body #声明使用实时索引 set_property :delta => true #注意这句一定要加,否则添加了记录不会自动索引 end end
记得添加实时索引字段 delta
ruby script/generate migration add_delta_to_posts delta:boolean
class AddDeltaToPosts < ActiveRecord::Migration def self.up add_column :posts, :delta,:boolean, :default => true, :null => false end def self.down remove_column :posts, :delta end end
rake db:migrate
在controller中加search代码,controler大家自己建啦。
class FullTextSearchController < ApplicationController def search per_page = params[:limit].to_i page = (params[:start].to_i / per_page) + 1 total_count = ThinkingSphinx.count(params[:query], :classes => [Post], :page => page, :per_page => per_page) @results = ThinkingSphinx.search(params[:query], :classes => [Post], :page => page, :per_page => per_page) respond_to do |format| format.json { render(:json => {:total => total_count, :success => true, :items => @results.map{ |i| {:id => i.id, :title => i.title, :body => i.body} unless i.blank ? }, }.to_json)} end end end
#创建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: 0 development: 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: 0 production: 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
发表评论
-
ubuntu rbenv、ruby、rails开发环境搭建
2014-04-23 13:13 893# ! /usr/bin/sh # Ubunt ... -
Vbox 中给 server 版 ubuntu 分别数据空间
2011-09-05 12:32 12221、首先,选择设备->安装增强功能 2、然后安装以下的 ... -
USB系统安装盘制作
2011-05-29 00:00 0用USB安装系统 安装速度比光盘还要快! U盘安装Wind ... -
virtualBox 中为 ubuntu 虚拟机分配数据空间
2011-05-21 10:54 2470tags: 磁盘映射 数据空间 分配数据空间 virtualB ... -
virtualBox 中为 ubuntu 虚拟机分配数据空间
2011-05-21 10:53 0tags: 磁盘映射 数据空间 分配数据空间 virtualB ... -
virtualBox 中为 ubuntu 虚拟机分配数据空间
2011-05-21 10:52 0tags: 磁盘映射 数据空间 分配数据空间 virtualB ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 10:56 38141.安装zhcon sudo apt-get install ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 10:42 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 10:38 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 10:37 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 10:31 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 10:29 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 10:27 01.安装zhcon sudo apt-get inst ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 10:06 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动时用zhcon自动开启中文界面
2011-05-20 09:49 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动自动开启中文界面
2011-05-20 09:48 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动自动开启中文界面
2011-05-20 09:48 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动自动开启中文界面
2011-05-20 09:39 01.安装zhcon sudo apt-get install ... -
ubuntu server 启动自动开启中文界面
2011-05-20 09:08 0安装 1.sudo apt-get install zhc ... -
ubuntu server 启动自动开启中文界面
2011-05-20 09:08 0安装 sudo apt-get install zhc ...
相关推荐
从官网上拷贝的内容,然后转的pdf;自己看的时候加了部分标签
Coreseek 是一款中文全文检索/搜索软件,以GPLv2许可协议开源发布,基于Sphinx研发并独立发布,专攻中文搜索和信息处理领域,适用于行业/垂直搜索、论坛/站内搜索、数据库搜索、文档/文献检索、信息检索、数据挖掘等...
NULL 博文链接:https://sinykk.iteye.com/blog/1154099
coreseek/sphinx分词词库txt版本(中日韩)
coreseek SPHINX 使用说明及详细介绍
coreseek是在sphinx的基础上,增加了中文分词功能,换句话说,就是支持了中文。 Coreseek发布了3.2.14版本和4.1版本,其中的3.2.14版本是2010年发布的,它是基于Sphinx0.9.9搜索引擎的。而4.1版本是2011年发布的,...
详细说明sphinx+coreseek安装、配置、php很用
coreseek是一款基于sphinx开源的搜索引擎,因为sphinx只支持英文和俄文(即只能进行英文分词和俄文分词),所以如果要使用sphinx做中文搜索的话,需要自己独立去导入中文词库。而coreseek里集成了中文词库模块mmseg,...
coreseek/sphinx分词词库txt版本(中日韩)
sphinx-coreseek中文手册 sphinx-coreseek中文手册 sphinx-coreseek中文手册 sphinx-coreseek中文手册
Sphinx 0.9.9/Coreseek 3.2 参考手册,完全离线版。
Sphinx 0.9.9/Coreseek 3.2 参考手册 离线版 Sphinx--强大的开源全文检索引擎,Coreseek--免费开源的中文全文检索引擎 在线地址: http://www.coreseek.cn/docs/coreseek_3.2-sphinx_0.9.9.html
coreseek3.2版本(目前来说最稳定的coreseek版本)的权威中文手册,内部带配置和开发示例。
window 下sphinx 2.2.11 及coreseek3.1 安装包及安装说明 ,简单php调试.供学习使用。。现在必须选择资源分。要玩的自己玩吧。谢谢
中文分词 coreseek sphinx
sphinx全文搜索引擎,支持中文分词。内置sphinx安装包及coreseek安装包
基于Sphinx 0.9.8 开发 支持Mysql全文搜索,支持PHP开发。 新增如下特性: 修正 2.5.x 系列searchd可能崩溃的Bug 改进 高亮的算法,支持词权重自定义 改进 切分算法,支持必须出现的关键词(仅在简单查询模式...
sphinx mmseg coreseek 搜狗 词库
Coreseek 是一款中文全文检索/搜索软件,以GPLv2许可协议开源发布,基于Sphinx研发并独立发布,专攻中文搜索和信息处理领域,适用于行业/垂直搜索、论坛/站内搜索、数据库搜索、文档/文献检索、信息检索、数据挖掘等...