随笔-167  评论-65  文章-0  trackbacks-0
上一遍介绍了 thinking_sphix 的使用,这次来介绍 ultrasphinx 的使用,二者都是 对sphinx的封装,都是rails的plugin,为了更好的利用rails调用sphinx方法。。。

前面的配置一样

Demo:
1,安装 chronic
gem install chronic

2,安装插件
ruby script/plugin install  svn://rubyforge.org/var/svn/fauna/ultrasphinx/trunk
这个是网上提供的方法,目前似乎找不到这个源了。。建议直接从github download 下载
http://github.com/fauna/ultrasphinx

3,安装完Ultrasphinx之后,将:
vendor/plugins/ultrasphinx/examples/default.base
复制到:
config/ultrasphinx/default.base
将其中的:
charset_type = utf-8
改为:
charset_type = zh_cn.utf-8

并且在charset_type设置的下面加入一行:
charset_dictpath =  /home/feng/RailsProject/Search/lib  # 你uni.lib 字典所在的路径
然后删除所有charset_table的设置。

4,Model
  is_indexed :fields => ['created_at', 'name']
  is_indexed :fields => ['created_at', 'content']

5,action
  def index
# thinking_sphinx
#    @articles = Article.search params[:search], :include => :author, :match_mode => :boolean
#ultrasphinx
    @search = Ultrasphinx::Search.new(:query => params[:search])
    @search.run
    @articles = @search.results
  end

6,生成配置文件:
rake ultrasphinx:configure
在config/ultrasphinx下创建了一个development.conf,这个文件就是Sphinx的配置文件。

7,创建索引:
rake ultrasphinx:index
索引创建在了 default.base 中你定义的path 路径下

8, 启动Sphinx的searchd服务:
rake ultrasphinx:daemon:start

对应的停止是  rake ultrasphinx:daemon:stop

9,启动webrick

ok了。。。
项目下载:
http://www.uushare.com/user/fl1429/file/2043752

ref:
http://www.javaeye.com/topic/200065?page=1
http://github.com/fauna/ultrasphinx






write by feng
posted on 2009-09-22 17:46 fl1429 阅读(694) 评论(0)  编辑  收藏 所属分类: Rails

只有注册用户登录后才能发表评论。


网站导航:
 
已访问数:
free counters