2005-07-22 (Fri) [長年日記]
_ acts_as_rast_indexed
とりあえず、サクっと作ってみた。 効率もtransactionも気にしない。
まず、rast_indexed.rbをlib/active_record/acts/以下に置く。
次にconfig/environment.rbに
require "active_record/acts/rast_indexed" ActiveRecord::Base.class_eval do include ActiveRecord::Acts::RastIndexed end
と書いて、準備完了。
デフォルトではRAILS_ROOT/index/RAILS_ENV/以下にインデックスを作るが、 ActiveRecord::Acts::RastIndexed.configurations=で設定もできる。
あとは、モデルに
class Page < ActiveRecord::Base acts_as_rast_indexed end
のように書くだけで使える。
具体的にはこんな感じ。
page = Page.new(:name => "abc",
:body => "This is abc")
page.save
pages = Page.find_by_rast(["body : ?", "abc"])
fixturesを使えるようにするにはtest/test_helper.rbに以下のおまじないを。
class << Fixtures
alias create_fixtures_without_rast_index create_fixtures
def create_fixtures_with_rast_index(fixture_directory, *table_names)
result = create_fixtures_without_rast_index(fixture_directory,
*table_names)
for table_name in table_names.flatten
table_class_name = Inflector.classify(table_name)
table_class = Object.const_get(table_class_name)
begin
table_class.rebuild_rast_index
rescue NoMethodError
end
end
return result
end
alias create_fixtures create_fixtures_with_rast_index
end
http://d.hatena.ne.jp/babie/20050729#p4<br>遅レス。<br>[Ruby][Rails][Debian] 初めての Rast (1)<br> せっかく前田さんが Ruby on Rails 用の Rast extention を作ってくださったので、Rast をインストール。 Apache Portable Runtime が無かったので入れておく。 Web 上にある deb が 0.1.1 のものだったので 、後学のために作って見た。(参考: 自作パッケージを作りたい ..