1 |
dpavlin |
2 |
#include <estraier.h> |
2 |
|
|
#include <cabin.h> |
3 |
|
|
#include <stdlib.h> |
4 |
|
|
#include <stdio.h> |
5 |
|
|
|
6 |
|
|
int main(int argc, char **argv){ |
7 |
|
|
ESTDB *db; |
8 |
|
|
ESTCOND *cond; |
9 |
|
|
ESTDOC *doc; |
10 |
|
|
const CBLIST *texts; |
11 |
|
|
int ecode, *result, resnum, i, j; |
12 |
|
|
const char *value; |
13 |
|
|
|
14 |
|
|
/* open the database */ |
15 |
|
|
if(!(db = est_db_open("casket", ESTDBREADER, &ecode))){ |
16 |
|
|
fprintf(stderr, "error: %s\n", est_err_msg(ecode)); |
17 |
|
|
return 1; |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
/* create a search condition object */ |
21 |
|
|
cond = est_cond_new(); |
22 |
|
|
|
23 |
|
|
/* set the search phrase to the search condition object */ |
24 |
|
|
est_cond_set_phrase(cond, "rainbow AND lullaby"); |
25 |
|
|
|
26 |
|
|
/* get the result of search */ |
27 |
|
|
result = est_db_search(db, cond, &resnum, NULL); |
28 |
|
|
|
29 |
|
|
/* for each document in the result */ |
30 |
|
|
for(i = 0; i < resnum; i++){ |
31 |
|
|
|
32 |
|
|
/* retrieve the document object */ |
33 |
|
|
if(!(doc = est_db_get_doc(db, result[i], 0))) continue; |
34 |
|
|
|
35 |
|
|
/* display attributes */ |
36 |
|
|
if((value = est_doc_attr(doc, "@uri")) != NULL) |
37 |
|
|
printf("URI: %s\n", value); |
38 |
|
|
if((value = est_doc_attr(doc, "@title")) != NULL) |
39 |
|
|
printf("Title: %s\n", value); |
40 |
|
|
|
41 |
|
|
/* display the body text */ |
42 |
|
|
texts = est_doc_texts(doc); |
43 |
|
|
for(j = 0; j < cblistnum(texts); j++){ |
44 |
|
|
value = cblistval(texts, j, NULL); |
45 |
|
|
printf("%s\n", value); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
/* destloy the document object */ |
49 |
|
|
est_doc_delete(doc); |
50 |
|
|
|
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
/* free the result of search */ |
54 |
|
|
free(result); |
55 |
|
|
|
56 |
|
|
/* destroy the search condition object */ |
57 |
|
|
est_cond_delete(cond); |
58 |
|
|
|
59 |
|
|
/* close the database */ |
60 |
|
|
if(!est_db_close(db, &ecode)){ |
61 |
|
|
fprintf(stderr, "error: %s\n", est_err_msg(ecode)); |
62 |
|
|
return 1; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
return 0; |
66 |
|
|
} |