1 |
#include <estraier.h> |
2 |
#include <estnode.h> |
3 |
#include <cabin.h> |
4 |
#include <stdlib.h> |
5 |
#include <stdio.h> |
6 |
|
7 |
int main(int argc, char **argv){ |
8 |
ESTNODE *node; |
9 |
ESTCOND *cond; |
10 |
ESTNODERES *nres; |
11 |
ESTRESDOC *rdoc; |
12 |
int i; |
13 |
const char *value; |
14 |
/* initialize the network environment */ |
15 |
if(!est_init_net_env()){ |
16 |
fprintf(stderr, "error: network is unavailable\n"); |
17 |
return 1; |
18 |
} |
19 |
/* create the node connection object */ |
20 |
node = est_node_new("http://localhost:1978/node/test1"); |
21 |
/* create a search condition object */ |
22 |
cond = est_cond_new(); |
23 |
/* set the search phrase to the search condition object */ |
24 |
est_cond_set_phrase(cond, "rainbow AND lullaby"); |
25 |
/* get the result of search */ |
26 |
nres = est_node_search(node, cond, 0); |
27 |
if(nres){ |
28 |
/* for each document in the result */ |
29 |
for(i = 0; i < est_noderes_doc_num(nres); i++){ |
30 |
/* get a result document object */ |
31 |
rdoc = est_noderes_get_doc(nres, i); |
32 |
/* display attributes */ |
33 |
if((value = est_resdoc_attr(rdoc, "@uri")) != NULL) |
34 |
printf("URI: %s\n", value); |
35 |
if((value = est_resdoc_attr(rdoc, "@title")) != NULL) |
36 |
printf("Title: %s\n", value); |
37 |
/* display the snippet text */ |
38 |
printf("%s", est_resdoc_snippet(rdoc)); |
39 |
} |
40 |
/* delete the node result object */ |
41 |
est_noderes_delete(nres); |
42 |
} else { |
43 |
fprintf(stderr, "error: %d\n", est_node_status(node)); |
44 |
} |
45 |
/* destroy the search condition object */ |
46 |
est_cond_delete(cond); |
47 |
/* destroy the node object */ |
48 |
est_node_delete(node); |
49 |
/* free the networking environment */ |
50 |
est_free_net_env(); |
51 |
return 0; |
52 |
} |