1 |
dpavlin |
9 |
#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 connecton 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 |
|
|
value = est_resdoc_snippet(rdoc); |
39 |
|
|
printf("%s", value); |
40 |
|
|
} |
41 |
|
|
/* delete the node result object */ |
42 |
|
|
est_noderes_delete(nres); |
43 |
|
|
} else { |
44 |
|
|
fprintf(stderr, "error: %d\n", est_node_status(node)); |
45 |
|
|
} |
46 |
|
|
/* destroy the search condition object */ |
47 |
|
|
est_cond_delete(cond); |
48 |
|
|
/* destroy the node object */ |
49 |
|
|
est_node_delete(node); |
50 |
|
|
/* free the networking environment */ |
51 |
|
|
est_free_net_env(); |
52 |
|
|
return 0; |
53 |
|
|
} |