Hyper Estraier Node APIデモ
私のプロジェクトでは、フルテキスト検索エンジンとしてhttp://hyperestraier.sourceforge.net/index.html[Hyper Estraier]を使用することに決めました。ここでは、CでNode APIを使用してHyper Estraierをプログラミングする方法を示す簡単なインターフェイスを作成しました。
(1)、更新(2)、削除(3)、またはリスト(4)既存の索引付き+ 2)索引付きのURL(一意のID)およびURLを入力してください
gcc -o HyperIndex HyperIndex.c -L/usr/local/lib -lestraier -lresolv -lnsl -lpthread -lqdbm -lz -liconv -lm -lc
-
Node URL ** – ここでは、自分のノードのURLをハードコードしています
http://localhost:1978/node/pattern
P.S私はCの専門家ではない、私はコードが何か間違っている場合は私を修正してください。
リンク://wp-content/uploads/2008/07/simple-hyper-estraier-node-api.jpg[
]
-
プログラム説明** ————常にhttp://hyperestraier.sourceforge.net/nguide-en.html[Hyper Estraier Node APIリファレンス]を参照してください。
-
1)est
node
put__doc()を使用してノードを挿入または更新する** URIが同じ場合、既存ノードの詳細を更新/上書きする
static void putNode(ESTDOC ** doc ,ESTNODE ** node, char ** cBufferUri ,char ** cBufferUrl) { /** add attributes to the document object ** / est__doc__add__attr(doc, "@uri", cBufferUri); est__doc__add__attr(doc, "@title", cBufferUri); est__doc__add__attr(doc, "url", cBufferUrl);//for include function /** add the body text to the document object ** / est__doc__add__text(doc, cBufferUrl); /** register the document object to the node ** / if(!est__node__put__doc(node, doc)){ fprintf(stderr, "error: %d\n", est__node__status(node)); } printf("\n URL ID : %s Added/Updated \n", cBufferUri); }
-
2)est
node
out
doc
by__uri()を使ってノードを削除**
static void outNode(ESTDOC ** doc ,ESTNODE ** node, char ** cBufferUri) { if(!est__node__out__doc__by__uri(node, cBufferUri)){ fprintf(stderr, "error: %d\n", est__node__status(node)); } printf("\n URL ID : %s Deleted\n", cBufferUri); }
-
3)est
node
get
doc
attr
by
uri()を使ってノードを表示**
static void listNode(ESTDOC ** doc ,ESTNODE ** node, char ** cBufferUri) { char ** pUrl; if(!(pUrl = est__node__get__doc__attr__by__uri(node, cBufferUri,"url"))){ fprintf(stderr, "error: %d\n", est__node__status(node)); } printf("\n URL ID : %s\n", cBufferUri); printf(" URL Value : %s\n", pUrl); pUrl=NULL; }
-
ここには完全なソースコードがあります**
…./
HyperIndex.c
Simple Interface For Hyper Estraier
gcc -o HyperIndex HyperIndex.c -L/usr/local/lib -lestraier -lresolv -lnsl -lpthread -lqdbm -lz -liconv -lm -lc
/#include
#include
#include
#include
#include
#include
#include
static void
putNode(ESTDOC
doc ,ESTNODE
node, char
cBufferUri ,char
cBufferUrl)
{
/
add attributes to the document object
/ est
doc
add
attr(doc, “@uri”, cBufferUri);
est
doc
add
attr(doc, “@title”, cBufferUri);
est
doc
add__attr(doc, “url”, cBufferUrl);//for include function
/** add the body text to the document object ** / est__doc__add__text(doc, cBufferUrl);
/** register the document object to the node ** / if(!est__node__put__doc(node, doc)){ fprintf(stderr, "error: %d\n", est__node__status(node)); }
printf("\n URL ID : %s Added/Updated \n", cBufferUri);
}
static void
listNode(ESTDOC
doc ,ESTNODE
node, char
cBufferUri)
{
char
pUrl;
if(!(pUrl = est__node__get__doc__attr__by__uri(node, cBufferUri,"url"))){ fprintf(stderr, "error: %d\n", est__node__status(node)); }
printf("\n URL ID : %s\n", cBufferUri); printf(" URL Value : %s\n", pUrl);
pUrl=NULL; }
static void
outNode(ESTDOC
doc ,ESTNODE
node, char ** cBufferUri)
{
if(!est__node__out__doc__by__uri(node, cBufferUri)){ fprintf(stderr, "error: %d\n", est__node__status(node)); }
printf("\n URL ID : %s Deleted\n", cBufferUri);
}
int
main(int argc, char
argv)
{
//calculate program time elapsed
time
t start, stop;
clock
t ticks; long count;
//Get user input char cBufferFlag[1]; char cBufferUri[256]; char cBufferUrl[256];
//start time time(&start);
//ESTDOC ** est__node__get__doc__by__uri(ESTNODE ** node, const char ** uri);
ESTNODE ** node; ESTDOC ** doc; /** initialize the network environment ** / if(!est__init__net__env()){ fprintf(stderr, "\nerror: network is unavailable\n"); return 1; }
/** create and configure the node connection object ** / node = est__node__new("http://localhost:1978/node/pattern"); est__node__set__auth(node, "admin", "admin");
/** create a document object ** / doc = est__doc__new();
printf("\n 1=Insert 2=Update 3=Delete 4=List"); printf("\n Please Enter Opereation : "); scanf("%s",cBufferFlag);
if(!strcmp(cBufferFlag, "1") || !strcmp(cBufferFlag, "2")) { printf(" Please Enter URL ID : "); scanf("%s",cBufferUri);
printf(" Please Enter URL : "); scanf("%s",cBufferUrl);
//insert/update putNode(doc,node,cBufferUri,cBufferUrl);
} else if(!strcmp(cBufferFlag, "3")) { printf(" Please Enter URL ID : "); scanf("%s",cBufferUri); //delete url info outNode(doc,node,cBufferUri);
} else if(!strcmp(cBufferFlag, "4")) { printf(" Please Enter URL ID : "); scanf("%s",cBufferUri); //list url info listNode(doc,node,cBufferUri);
} else { exit(1); }
/** destroy the document object ** / est__doc__delete(doc);
/** destroy the node object ** / est__node__delete(node); /** free the networking environment ** / est__free__net__env();
//stop time time(&stop);
printf("\nFinished in about %.0f seconds. \n\n", difftime(stop, start));
return 0; }
link://タグ/全文検索/[全文検索]リンク://tag/hyper-estraier/[hyper estraier]