ubuntuに全文検索中国語分詞Coreseek/sphinxおよびRails統合をインストール


Sphinx(スフィンクスの顔像)はご存知のようですが、紹介はしません.知らない子供靴は自分でGoogleすることができます.
原生Sphinxは中国語をサポートしていません.
そこでここでは、中国語の分詞をサポートするCoreseekについて重点的に紹介します.
[color=red]注意:Coreseek 3.2以降、Coreseekをインストールするだけでよい.LibMMSegとsphinxを統合し、オリジナルSphinxをインストールする必要はない.(3.2まではオリジナルSphinxをインストールし、パッチをインストールするのが面倒でした)[/color]
[b]coreseekのインストール[/b]
以下coreseek-3.2.14を例にとると、Sphinx 0.99(Sphinx 0.99をインストールしない)に基づいています.
詳細公式マニュアル:[url]http://www.coreseek.cn/products-install/install_on_bsd_linux/[/url]
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


[b]railsプロジェクトへの統合[/b]
ここではgem thinking-sphinxを使っています
新しいプロジェクトが自分でRailsプロジェクトを作成していない場合は、ここでは説明しません.
Railscasts:[url]を参照してください.http://railscasts.com/episodes/120-thinking-sphinx?autoplay=true[/url]
インストールthinking-sphinx
公式マニュアル:[url]http://freelancing-god.github.com/ts/en/installing_thinking_sphinx.html[/url]
ここではrails 3.0のみを説明します
Gemfileに追加
gem 'thinking-sphinx'

そして
bundle install

クイックインプリメンテーションを参照できます:[url]http://freelancing-god.github.com/ts/en/quickstart.html[/url]
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

コントローラにsearchコードを追加し、コントローラは自分で建てました.
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:
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:
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:
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


最後に注意事項をいくつか追加します.
[color=red]1.インデックスを定義するときに「set_property:delta=>true」という新しいレコードがないとインデックスされません.
2.coreseekインストールパッケージの辞書ファイルはRailsプロジェクトのデータディレクトリにコピーしなければなりません.そうしないと、中国語ではサポートされません.[/color]
[b]参考資料:[/b]
詳細:[url]https://github.com/freelancing-god/thinking-sphinx[/url]
公式マニュアル:[url]http://freelancing-god.github.com/ts/en/installing_thinking_sphinx.html[/url]
クイックインプリメンテーション:[url]http://freelancing-god.github.com/ts/en/quickstart.html[/url]