Hyper Estraier Rubyクラスライブラリ
第二十回
全文検索エンジンHyper Estraierをインストールしたわけだが,これをRubyから操作できるようにRubyクラスライブラリもインストールする.Rubyクラスライブラリには二つあり,「RubyNativeAPI」はRubyからHyper Estraierのデータベースを読んだり書き込んだりできるものだ.主に,文書の登録や検索を行うことができる.「RubyPureAPI」も同じくRubyからHyper Estraierを操作できるが,こちらはHyper EstraierのP2P機能を操作するためのもので,主にノードサーバの管理やノードサーバへの文書の登録,各ノードからの文書の検索などが行える.
これを使えるようにするためには,Hyper Estraierを展開したディレクトリに移動して,以下の手順でインストールを行えばよい.
まずは,RubyNativeAPIから.
$ cd rubynative $ ./configure $ make $ su # make install
次はRubyPureAPI.
$ cd rubypure $ ./configure $ make $ su # make install
まぁ,二つとも手順は同じなわけであえて書くまでもなかったかもしれない.ちなみに,どちらかしか使わない場合は片方だけのインストールで構わないし,両方使う場合でもそれぞれの順番はどちらが先でもいい.
実際に使ってみるべく,http://hyperestraier.sourceforge.net/rubynativeapi/とhttp://hyperestraier.sourceforge.net/rubypureapi/に載っているSearchサンプルを動かしてみる.すると,RubyPureAPIの方は問題なく動いたのだが,RubyNativeAPIの方はエラーが出てしまった.
$ ruby -v ruby 1.8.4 (2005-12-24) [i386-linux] $ cat smple-search-estraier.rb #/usr/bin/ruby -Ku require "estraier" include Estraier # create the database object db = Database::new # open the database unless db.open("casket", Database::DBREADER) printf("error: %s\n", db.err_msg(db.error)) exit end ## `casket'のところにHyperEstraierの転置インデックス ## データベースのパスを指定する # create a search condition object cond = Condition::new # set the search phrase to the search condition object cond.set_phrase("rainbow AND lullaby") # get the result of search result = db.search(cond) # for each document in the result dnum = result.doc_num for i in 0...dnum # retrieve the document object doc = db.get_doc(result.get_doc_id(i), 0) next unless doc # display attributes uri = doc.attr("@uri") printf("URI: %s\n", uri) if uri title = doc.attr("@title") printf("Title: %s\n", title) if title # display the body text doc.texts.each do |text| printf("%s\n", text) end end # close the database unless db.close printf("error: %s\n", db.err_msg(db.error)) end $ ruby smple-search-estraier.rb /usr/lib/site_ruby/1.8/estraier.so: libestraier.so.8: cannot open shared object file: No such file or directory - /usr/lib/site_ruby/1.8/estraier.so (LoadError) from smple-search-estraier.rb:2
エラーの部分は見やすいように改行しておいたが,どうやらクラスライブラリを読み込む際のパスの検索がダメのようだ.そこで,クラスライブラリをインストールしたディレクトリを/etc/ld.so.confに追加してみた.
$ cat /etc/ld.so.conf include ld.so.conf.d/*.conf
これを見ると設定ファイルごとに読み込んできているようなので,/etc/ld.so.conf.d/にruby-estraier.confとか適当な名前でファイルを作った.内容は以下のとおり.
/usr/local/lib
これをした上で,
$ /sbin/ldconfig
を実行.そして,もう一度さっきのサンプルを動かしてみると,成功.
これを使って専用の検索UIを作ってみようかな.
おしまい