hyper estraierとrailsを組み合わせてrailsから全文検索

hyper estraierとrailsを組み合わせてrailsから全文検索を利用する。

参考にした記事は

Railsの全文
検索は、Hyper Estraierとsearch_doプラグインで超簡単 – 医者を志す妻を応援
する夫の日記

ks:
search_doというのを入れようと

hyper estraierのダウンロードはこちらから
全文検索シ
ステム Hyper Estraier

hyper estraierをインストール

ソースを取得してmakeします。’

いくつか入っていないライブラリがあったのでそちらも個別にインストールしま
した。

hyper estraierの起動

hyper estraierの起動方法は適当なディレクトリに移動して以下のコマンドで起

mkdir estdata
cd estdata
estmaster init test
estmaster start test

バックグラウンドで実行する場合は -bg オプションをつける
estmaster start -bg test

railsにプラグインのインストール

script/plugin install git://github.com/moro/search_do.git

この時gitがマシンにインストールされていないとエラーも何も表示されずコマ
ンドが終了するの注意すること!
というか正常終了しなかったらエラーメッセージとかだせよって感じ・・・

database.ymlに以下の設定を追加

development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: cms_test_development
  pool: 5
  username: root
  password:
  socket: /var/run/mysqld/mysqld.sock
  estraier:
    host: localhost
    user: test
    password: test
    port: 1978
    node: sample

モデルの設定

検索対象のモデルに検索フィールドを設定

class Articl < ActiveRecord::Base
  acts_as_searchable :searchable_fields => [:title, :message]

end

プラグインの修正

vendor/plugins/search_do/lib/search_do/backends/hyper_estraier.rbを修正


      def calculate_node_name(config)
#        node_prefix = config['node_prefix'] || config['node'] || RAILS_ENV
#        "#{node_prefix}_#{@ar_class.table_name}"
        config['node_prefix'] || config['node'] || RAILS_ENV

      end

インデクスの作成と検索

mtakagi@ireul:~/rails_work/cms_test$ ./script/console
Loading development environment (Rails 2.3.3)
>> Articl.reindex!
=> [#, #, #]
>> Articl.fulltext_search("ブラジル")
=> [#]
>>

できますた!

Tags: , , , , , , ,

This entry was posted on 土曜日, 8月 1st, 2009 at 7:08 PM and is filed under ruby, 備忘録. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply