1 |
/************************************************************************************************* |
2 |
* The MT-safe API of Hyper Estraier |
3 |
* Copyright (C) 2004-2005 Mikio Hirabayashi |
4 |
* This file is part of Hyper Estraier. |
5 |
* Hyper Estraier is free software; you can redistribute it and/or modify it under the terms of |
6 |
* the GNU Lesser General Public License as published by the Free Software Foundation; either |
7 |
* version 2.1 of the License or any later version. Hyper Estraier is distributed in the hope |
8 |
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
10 |
* License for more details. |
11 |
* You should have received a copy of the GNU Lesser General Public License along with Hyper |
12 |
* Estraier; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
13 |
* Boston, MA 02111-1307 USA. |
14 |
*************************************************************************************************/ |
15 |
|
16 |
|
17 |
#ifndef _ESTMTDB_H /* duplication check */ |
18 |
#define _ESTMTDB_H |
19 |
|
20 |
#if defined(__cplusplus) /* export for C++ */ |
21 |
extern "C" { |
22 |
#endif |
23 |
|
24 |
|
25 |
#include <estraier.h> |
26 |
#include <cabin.h> |
27 |
#include <pthread.h> |
28 |
#include <stdlib.h> |
29 |
|
30 |
|
31 |
|
32 |
/************************************************************************************************* |
33 |
* API for MT-safe database |
34 |
*************************************************************************************************/ |
35 |
|
36 |
|
37 |
typedef struct { /* type of structure for a MT-safe database */ |
38 |
ESTDB *db; /* database connection */ |
39 |
char *path; /* real path of the directory */ |
40 |
pthread_mutex_t mutex; /* mutex for each connection */ |
41 |
} ESTMTDB; |
42 |
|
43 |
|
44 |
/* Open a database. */ |
45 |
ESTMTDB *est_mtdb_open(const char *name, int omode, int *ecp); |
46 |
|
47 |
|
48 |
/* Close a database. */ |
49 |
int est_mtdb_close(ESTMTDB *db, int *ecp); |
50 |
|
51 |
|
52 |
/* Get the last happended error code of a database. */ |
53 |
int est_mtdb_error(ESTMTDB *db); |
54 |
|
55 |
|
56 |
/* Check whether a database has a fatal error. */ |
57 |
int est_mtdb_fatal(ESTMTDB *db); |
58 |
|
59 |
|
60 |
/* Flush index words in the cache of a database. */ |
61 |
int est_mtdb_flush(ESTMTDB *db, int max); |
62 |
|
63 |
|
64 |
/* Synchronize updating contents of a database. */ |
65 |
int est_mtdb_sync(ESTMTDB *db); |
66 |
|
67 |
|
68 |
/* Optimize a database. */ |
69 |
int est_mtdb_optimize(ESTMTDB *db, int options); |
70 |
|
71 |
|
72 |
/* Add a document to a database. */ |
73 |
int est_mtdb_put_doc(ESTMTDB *db, ESTDOC *doc, int options); |
74 |
|
75 |
|
76 |
/* Remove a document from a database. */ |
77 |
int est_mtdb_out_doc(ESTMTDB *db, int id, int options); |
78 |
|
79 |
|
80 |
/* Retrieve a document in a database. */ |
81 |
ESTDOC *est_mtdb_get_doc(ESTMTDB *db, int id, int options); |
82 |
|
83 |
|
84 |
/* Retrieve the value of an attribute of a document in a database. */ |
85 |
char *est_mtdb_get_doc_attr(ESTMTDB *db, int id, const char *name); |
86 |
|
87 |
|
88 |
/* Get the ID of a document spacified by URI. */ |
89 |
int est_mtdb_uri_to_id(ESTMTDB *db, const char *uri); |
90 |
|
91 |
|
92 |
/* Extract keywords of a document object. */ |
93 |
CBMAP *est_mtdb_etch_doc(ESTMTDB *db, ESTDOC *doc, int max); |
94 |
|
95 |
|
96 |
/* Initialize the iterator of a database. */ |
97 |
int est_mtdb_iter_init(ESTMTDB *db); |
98 |
|
99 |
|
100 |
/* Get the next ID of the iterator of a database. */ |
101 |
int est_mtdb_iter_next(ESTMTDB *db); |
102 |
|
103 |
|
104 |
/* Get the name of a database. */ |
105 |
const char *est_mtdb_name(ESTMTDB *db); |
106 |
|
107 |
|
108 |
/* Get the number of documents in a database. */ |
109 |
int est_mtdb_doc_num(ESTMTDB *db); |
110 |
|
111 |
|
112 |
/* Get the number of unique words in a database. */ |
113 |
int est_mtdb_word_num(ESTMTDB *db); |
114 |
|
115 |
|
116 |
/* Get the size of a database. */ |
117 |
double est_mtdb_size(ESTMTDB *db); |
118 |
|
119 |
|
120 |
/* Search documents corresponding a condition for a database. */ |
121 |
int *est_mtdb_search(ESTMTDB *db, ESTCOND *cond, int *nump, CBMAP *hints); |
122 |
|
123 |
|
124 |
/* Set the maximum size of the cache memory of a database. */ |
125 |
void est_mtdb_set_cache_size(ESTMTDB *db, size_t size, int anum, int tnum); |
126 |
|
127 |
|
128 |
/* Set the special cache for narrowing and sorting with document attributes. */ |
129 |
void est_mtdb_set_special_cache(ESTMTDB *db, const char *name, int num); |
130 |
|
131 |
|
132 |
|
133 |
/************************************************************************************************* |
134 |
* features for experts |
135 |
*************************************************************************************************/ |
136 |
|
137 |
|
138 |
/* Edit attributes of a document object in a database. */ |
139 |
int est_mtdb_edit_doc(ESTMTDB *db, ESTDOC *doc); |
140 |
|
141 |
|
142 |
/* Add a piece of meta data to a database. */ |
143 |
void est_mtdb_add_meta(ESTMTDB *db, const char *name, const char *value); |
144 |
|
145 |
|
146 |
/* Get a list of names of meta data of a database. */ |
147 |
CBLIST *est_mtdb_meta_names(ESTMTDB *db); |
148 |
|
149 |
|
150 |
/* Get the value of a piece of meta data of a database. */ |
151 |
char *est_mtdb_meta(ESTMTDB *db, const char *name); |
152 |
|
153 |
|
154 |
/* Get the number of records in the cache memory of a database. */ |
155 |
int est_mtdb_cache_num(ESTMTDB *db); |
156 |
|
157 |
/* Set the callback function to inform of database events. */ |
158 |
void est_mtdb_set_informer(ESTMTDB *db, void (*func)(const char *)); |
159 |
|
160 |
|
161 |
/* Set the callback function to create a vector of keywords of a document. */ |
162 |
void est_mtdb_set_vectorizer(ESTMTDB *db, CBMAP *(*func)(void *, int, void *), void *data); |
163 |
|
164 |
|
165 |
/* Fill the cache for keys for TF-IDF. */ |
166 |
void est_mtdb_fill_key_cache(ESTMTDB *db); |
167 |
|
168 |
|
169 |
|
170 |
#if defined(__cplusplus) /* export for C++ */ |
171 |
} |
172 |
#endif |
173 |
|
174 |
#endif /* duplication check */ |
175 |
|
176 |
|
177 |
/* END OF FILE */ |