上一遍介紹了 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:stop9,啟動webrick
ok了。。。
項目下載:
http://www.uushare.com/user/fl1429/file/2043752
ref:
http://www.javaeye.com/topic/200065?page=1
http://github.com/fauna/ultrasphinx
posted on 2009-09-22 17:46
fl1429 閱讀(725)
評論(0) 編輯 收藏 所屬分類:
Rails