HyperEstraierのドキュメント属性をいじる 1
HyperEstraierにはドキュメント属性をいじるAPIが用意されている。これを使うと本文は変更しないでよいが属性だけをいじりたいというようなことが素早くできるのではないかと思い、ちょっとだけ試してみる。
まず、hyper_estraier_wrappers-0.0.9に少し手を入れてest_db_edit_docを使えるようにする:
diff -ruN swig_hest-0.0.9.orig/HyperEstraierWrapper.cpp swig_hest-0.0.9/HyperEstraierWrapper.cpp
--- swig_hest-0.0.9.orig/HyperEstraierWrapper.cpp 2005-06-12 19:11:18.000000000 +0900
+++ swig_hest-0.0.9/HyperEstraierWrapper.cpp 2005-08-02 14:01:00.000000000 +0900
@@ -275,6 +275,12 @@
*/
return est_mtdb_put_doc(db, doc->doc, options);
}
+ bool edit_doc(Document *doc) {
+ /**
+ * edit a document to a database
+ */
+ return est_mtdb_edit_doc(db, doc->doc);
+ }
std::vector<int> * search(Condition * cond, int options) {
/**
* search documents corresponding a condition for a database
diff -ruN swig_hest-0.0.9.orig/ruby/extconf.rb swig_hest-0.0.9/ruby/extconf.rb
--- swig_hest-0.0.9.orig/ruby/extconf.rb 2005-06-09 13:35:07.000000000 +0900
+++ swig_hest-0.0.9/ruby/extconf.rb 2005-08-02 14:31:02.000000000 +0900
@@ -5,11 +5,7 @@
$srcdir = 'src'
-$libs += [
- `estconfig --libs`.chomp,
- `estconfig --mtlibs`.chomp,
- '-lstdc++'].join(" ")
-
+pkg_config('qdbm')
if have_header('estraier.h') and have_library('estraier', 'est_db_open')
create_makefile('HyperEstraier')
end
Debian環境だと-Iを指定してやらなければならないので、ついでにextconf.rbにも手を加えておいた。この状態でrubyディレクトリに移動し、以下を実行する:
$ ruby extconf.rb --with-cflags=`estconfig --cflags` \ --with-ldflags="`estconfig --ldflags` `estconfig --libs` -lstdc++" $ make
これで準備が出来たので、あらかじめ作っておいたインデックスを指定して次のように実行する:
$ ruby -r./HyperEstraier -e '
db = HyperEstraier::Database.new()
db.open("/path/to/index", HyperEstraier::Database::DBWRITER)
doc = db.get_doc(document-id, 0)
doc.add_attr("attribute-name", "varlue")
unless db.edit_doc(doc)
HyperEstraier::Database::err_msg(db.error)
end
db.close'
検索してみると属性が変わっているのが確認できるはず。
で、まあ、こういったことがRastでもできると良いなあ、と。
トラックバック
トラックバックリンク:
http://arika.org/diary/trackbacks?article_id=1611



すみません,Rastでももちろんできるようにします.