|
nohhoso です。
> 何か適当なサンプルプログラムでもあれば、それを元に何とかできるかもしれ
>ませんけど。例えばgoogleデスクトップ検索の時もそういうサンプルを元にして
>作りましたが。
先に挙げたページからですが、メールデータをインデックスに登録する処理と
検索する処理のサンプルコードは以下のようになります。
●メールデータをインデックスするサンプル
-----------------------------------------------------------------
#include <estraier.h>
#include <cabin.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv){
ESTDB *db;
ESTDOC *doc;
int ecode;
/* データベースを開く */
if(!(db = est_db_open("casket", ESTDBWRITER | ESTDBCREAT, &ecode))){
fprintf(stderr, "error: %s\n", est_err_msg(ecode));
return 1;
}
/* 文書オブジェクトを生成する */
doc = est_doc_new();
/* 文書オブジェクトに属性を追加する */
est_doc_add_attr(doc, "@uri", "http://estraier.gov/example.txt");
est_doc_add_attr(doc, "@title", "Over the Rainbow");
est_doc_add_attr(doc, "from", "xxx@bbb.com");
est_doc_add_attr(doc, "to", "xxx@dddd.com");
/* その他、ヘッダを属性として追加することになると思います */
/* 文書オブジェクトに本文を追加する */
est_doc_add_text(doc, "Somewhere over the rainbow. Way up high.");
est_doc_add_text(doc, "There's a land that I heard of once in a lullaby.");
/* 文書オブジェクトをデータベースに登録する */
if(!est_db_put_doc(db, doc, ESTPDCLEAN))
fprintf(stderr, "error: %s\n", est_err_msg(est_db_error(db)));
/* 文書オブジェクトを破棄する */
est_doc_delete(doc);
/* データベースを閉じる */
if(!est_db_close(db, &ecode)){
fprintf(stderr, "error: %s\n", est_err_msg(ecode));
return 1;
}
return 0;
}
-----------------------------------------------------------------
@uri 属性は必須で、かつドキュメント毎にユニークである必要があります。
秀丸メールですと、データのファイルとオフセット値を組み合わせたものがいいので
はないでしょうか。
●メールデータを検索するサンプル
-----------------------------------------------------------------
#include <estraier.h>
#include <cabin.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv){
ESTDB *db;
ESTCOND *cond;
ESTDOC *doc;
const CBLIST *texts;
int ecode, *result, resnum, i, j;
const char *value;
/* データベースを開く */
if(!(db = est_db_open("casket", ESTDBREADER, &ecode))){
fprintf(stderr, "error: %s\n", est_err_msg(ecode));
return 1;
}
/* 検索条件オブジェクトを生成する */
cond = est_cond_new();
/* 検索条件オブジェクトに検索式を設定する */
est_cond_set_phrase(cond, "rainbow AND lullaby");
/* データベースから検索結果を得る */
result = est_db_search(db, cond, &resnum, NULL);
/* 各該当文書を取得して表示する */
for(i = 0; i < resnum; i++){
/* 文書オブジェクトを取得する */
if(!(doc = est_db_get_doc(db, result[i], 0))) continue;
/* 属性を表示する */
if((value = est_doc_attr(doc, "@uri")) != NULL)
printf("URI: %s\n", value);
if((value = est_doc_attr(doc, "@title")) != NULL)
printf("Title: %s\n", value);
/* 本文を表示する */
texts = est_doc_texts(doc);
for(j = 0; j < cblistnum(texts); j++){
value = cblistval(texts, j, NULL);
printf("%s\n", value);
}
/* 文書オブジェクトを破棄する */
est_doc_delete(doc);
}
/* 検索結果を破棄する */
free(result);
/* 検索条件オブジェクトを破棄する */
est_cond_delete(cond);
/* データベースを閉じる */
if(!est_db_close(db, &ecode)){
fprintf(stderr, "error: %s\n", est_err_msg(ecode));
return 1;
}
return 0;
}
-----------------------------------------------------------------
上記のサンプルですと、「rainbow」と「lullaby」の両方の語を
含むメールを検索する、という処理になります。
あと、Hyper EstraierのJavaバインディングを使って作った、
秀丸メールのデータをインポートして検索するツールがあるんですけども、
そんなものでよろしければソースをお送りしますが、いかがいたしましょうか。
# GUIを手早く作りたかったので、Javaを選択してしまいました。(^_^;
|
|