A few Doxygen doc entries
[idzebra-moved-to-github.git] / include / idzebra / api.h
1 /* $Id: api.h,v 1.8 2005-01-15 22:10:16 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 /**
24  * \file api.h
25  * \brief Zebra API
26  */
27
28 /* Return codes:
29  * Most functions return an int. Unix-like, 0 means OK, 
30  * non-zero means an error. The error info should be available
31  * via zebra_errCode and friends. 
32  */
33
34 #ifndef ZEBRAAPI_H
35 #define ZEBRAAPI_H
36
37 #include <yaz/odr.h>
38 #include <yaz/oid.h>
39 #include <yaz/proto.h>
40 #include <idzebra/res.h>
41 #include <idzebra/version.h>
42
43 YAZ_BEGIN_CDECL
44
45 typedef struct {
46   int processed;
47   int inserted;
48   int updated;
49   int deleted;
50   long utime;
51   long stime;
52 } ZebraTransactionStatus;
53
54 /* Retrieval Record Descriptor */
55 typedef struct {
56     int errCode;         /* non-zero if error when fetching this */
57     char *errString;     /* error string */
58     int position;        /* position of record in result set (1,2,..) */
59     char *buf;           /* record buffer (void pointer really) */
60     int len;             /* length */
61     oid_value format;    /* record syntax */
62     char *base; 
63     SYSNO sysno;
64     int  score;
65 } ZebraRetrievalRecord;
66
67 /* Scan Term Descriptor */
68 typedef struct {
69     int occurrences;     /* scan term occurrences */
70     char *term;          /* scan term string */
71 } ZebraScanEntry;
72
73 /** \var ZebraHandle
74  * \brief a Zebra Handle - (session)
75  */
76 typedef struct zebra_session *ZebraHandle;
77
78 /** \var ZebraService
79  * \brief a Zebra Service handle
80  */
81 typedef struct zebra_service *ZebraService;
82
83
84 /******
85  * Starting and stopping 
86  */
87
88 /* Start Zebra using file 'configName' (usually zebra.cfg) */
89 /* There should be exactly one ZebraService */
90
91 /** \fn ZebraService zebra_start(const char *configName)
92  * \brief starts a Zebra service
93  * \param configName name of configuration file
94  */
95 YAZ_EXPORT ZebraService zebra_start
96 (const char *configName);
97
98 /** \fn ZebraService zebra_start_res(const char *configName, Res def_res, Res over_res)
99  * \brief starts a Zebra service with resources
100  * \param configName name of configuration file
101  * \param def_res default resources
102  * \param over_res overriding resources
103  */
104 YAZ_EXPORT
105 ZebraService zebra_start_res (const char *configName,
106                          Res def_res, Res over_res);
107
108 /** \fn int zebra_stop(ZebraService zs)
109  * \brief stops a Zebra service
110  * \param zs service handle
111  */
112 YAZ_EXPORT
113 int zebra_stop (ZebraService zs);
114
115 /** \fn void zebra_filter_info(ZebraService zs, void *cd, void (*cb)(void *cd, const char *name))
116  * \brief lists enabled Zebra filters
117  * \param zs service handle
118  * \param cd callback parameter (opaque)
119  * \param cb callback function
120  */
121 YAZ_EXPORT
122 void zebra_filter_info(ZebraService zs, void *cd,
123                   void (*cb)(void *cd, const char *name));
124
125
126 /* Open a ZebraHandle */
127 /* There should be one handle for each thred doing something */
128 /* with zebra, be that searching or indexing. In simple apps */
129 /* one handle is sufficient */
130 YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs);
131
132 /* Close handle */
133 YAZ_EXPORT int zebra_close (ZebraHandle zh);
134
135 /*********
136  * Error handling 
137  */
138
139 /* last error code */
140 YAZ_EXPORT int zebra_errCode (ZebraHandle zh);
141
142 /* string representatio of above */
143 YAZ_EXPORT const char *zebra_errString (ZebraHandle zh);
144
145 /* extra information associated with error */
146 YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
147
148 /* get the result code and addinfo from zh */
149 YAZ_EXPORT int zebra_result (ZebraHandle zh, int *code, char **addinfo);
150 /* FIXME - why is this needed?? -H */
151
152 /* clear them error things */
153 YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
154
155 /**************
156  * Searching 
157  */
158
159 /* Search using PQF Query */
160 YAZ_EXPORT int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
161                                  const char *setname, int *numhits);
162
163 /* Search using RPN Query */
164 YAZ_EXPORT int zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query,
165                                  const char *setname, int *hits);
166
167 /* Retrieve record(s) */
168 YAZ_EXPORT int zebra_records_retrieve (ZebraHandle zh, ODR stream,
169                        const char *setname, Z_RecordComposition *comp,
170                        oid_value input_format,
171                        int num_recs, ZebraRetrievalRecord *recs);
172
173 /* Delete Result Set(s) */
174 YAZ_EXPORT int zebra_deleleResultSet(ZebraHandle zh, int function,
175                                      int num_setnames, char **setnames,
176                                      int *statuses);
177
178
179 /* Browse */
180 YAZ_EXPORT int zebra_scan (ZebraHandle zh, ODR stream,
181                            Z_AttributesPlusTerm *zapt,
182                            oid_value attributeset,
183                            int *position, int *num_entries,
184                            ZebraScanEntry **list,
185                            int *is_partial);
186
187    
188           
189 /*********
190  * Other 
191  */
192                       
193 /* do authentication */
194 YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
195
196 /* Character normalisation on specific register .
197    This routine is subject to change - do not use. */
198 YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
199                                   const char *input_str, int input_len,
200                                   char *output_str, int output_len);
201
202
203 /******
204  * Admin 
205  */                   
206           
207 YAZ_EXPORT int zebra_create_database (ZebraHandle zh, const char *db);
208 YAZ_EXPORT int zebra_drop_database (ZebraHandle zh, const char *db);
209
210 YAZ_EXPORT int zebra_admin_shutdown (ZebraHandle zh);
211 YAZ_EXPORT int zebra_admin_start (ZebraHandle zh);
212
213 YAZ_EXPORT int zebra_shutdown (ZebraService zs);
214
215 YAZ_EXPORT int zebra_admin_import_begin (ZebraHandle zh, const char *database,
216                                           const char *record_type);
217
218 YAZ_EXPORT int zebra_admin_import_segment (ZebraHandle zh,
219                                             Z_Segment *segment);
220
221 YAZ_EXPORT int zebra_admin_import_end (ZebraHandle zh);
222
223 int zebra_admin_exchange_record (ZebraHandle zh,
224                                  const char *rec_buf,
225                                  size_t rec_len,
226                                  const char *recid_buf, size_t recid_len,
227                                  int action);
228
229 int zebra_begin_trans (ZebraHandle zh, int rw);
230 int zebra_end_trans (ZebraHandle zh);
231 int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *stat);
232
233 int zebra_commit (ZebraHandle zh);
234 int zebra_clean (ZebraHandle zh);
235
236 int zebra_init (ZebraHandle zh);
237 int zebra_compact (ZebraHandle zh);
238 int zebra_repository_update (ZebraHandle zh, const char *path);
239 int zebra_repository_delete (ZebraHandle zh, const char *path);
240 int zebra_repository_show (ZebraHandle zh, const char *path);
241
242 int zebra_add_record (ZebraHandle zh, const char *buf, int buf_size);
243                                
244 int zebra_insert_record (ZebraHandle zh, 
245                          const char *recordType,
246                          SYSNO *sysno, const char *match, const char *fname,
247                          const char *buf, int buf_size,
248                          int force_update);
249 int zebra_update_record (ZebraHandle zh, 
250                          const char *recordType,
251                          SYSNO *sysno, const char *match, const char *fname,
252                          const char *buf, int buf_size,
253                          int force_update);
254 int zebra_delete_record (ZebraHandle zh, 
255                          const char *recordType,
256                          SYSNO *sysno, const char *match, const char *fname,
257                          const char *buf, int buf_size,
258                          int force_update);
259
260 YAZ_EXPORT int zebra_resultSetTerms (ZebraHandle zh, const char *setname, 
261                                      int no, zint *count, 
262                                      int *type, char *out, size_t *len);
263
264 YAZ_EXPORT int zebra_sort (ZebraHandle zh, ODR stream,
265                            int num_input_setnames,
266                            const char **input_setnames,
267                            const char *output_setname,
268                            Z_SortKeySpecList *sort_sequence,
269                            int *sort_status);
270
271 YAZ_EXPORT
272 int zebra_select_databases (ZebraHandle zh, int num_bases, 
273                             const char **basenames);
274
275 YAZ_EXPORT
276 int zebra_select_database (ZebraHandle zh, const char *basename);
277
278 YAZ_EXPORT
279 int zebra_shadow_enable (ZebraHandle zh, int value);
280
281 YAZ_EXPORT
282 int zebra_register_statistics (ZebraHandle zh, int dumpdict);
283
284 YAZ_EXPORT
285 int zebra_record_encoding (ZebraHandle zh, const char *encoding);
286
287 YAZ_EXPORT
288 int zebra_record_encoding (ZebraHandle zh, const char *encoding);
289
290 YAZ_EXPORT
291 int zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
292
293 /* Resources */
294 YAZ_EXPORT
295 int zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
296 YAZ_EXPORT
297 const char *zebra_get_resource(ZebraHandle zh, 
298                 const char *name, const char *defaultvalue);
299
300
301 YAZ_EXPORT void zebra_pidfname(ZebraService zs, char *path);
302
303 typedef struct {
304     char *term;
305     char *db;
306     zint sysno;
307     int score;
308 } ZebraMetaRecord;
309
310 YAZ_EXPORT
311 ZebraMetaRecord *zebra_meta_records_create (ZebraHandle zh,
312                                             const char *name,
313                                             int num, zint *positions);
314
315
316 YAZ_EXPORT
317 ZebraMetaRecord *zebra_meta_records_create_range (ZebraHandle zh,
318                                                   const char *name, 
319                                                   zint start, int num);
320
321 YAZ_EXPORT
322 void zebra_meta_records_destroy (ZebraHandle zh, ZebraMetaRecord *records,
323                                  int num);
324 YAZ_END_CDECL                                 
325 #endif