3336ca202d3e8e10e73ee213719999d09097b35e
[idzebra-moved-to-github.git] / include / idzebra / api.h
1 /* $Id: api.h,v 1.7 2005-01-15 21:45:43 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 typedef struct zebra_session *ZebraHandle;
74 typedef struct zebra_service *ZebraService;
75
76
77 /******
78  * Starting and stopping 
79  */
80
81 /* Start Zebra using file 'configName' (usually zebra.cfg) */
82 /* There should be exactly one ZebraService */
83 YAZ_EXPORT ZebraService zebra_start (const char *configName);
84 YAZ_EXPORT ZebraService zebra_start_res (const char *configName,
85                                          Res def_res, Res over_res);
86
87 /* Close the whole Zebra */
88 YAZ_EXPORT int zebra_stop (ZebraService zs);
89
90 /* Report name of each record class (filter) */
91 YAZ_EXPORT void zebra_filter_info(ZebraService zs, void *cd,
92                                   void (*cb)(void *cd, const char *name));
93
94
95 /* Open a ZebraHandle */
96 /* There should be one handle for each thred doing something */
97 /* with zebra, be that searching or indexing. In simple apps */
98 /* one handle is sufficient */
99 YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs);
100
101 /* Close handle */
102 YAZ_EXPORT int zebra_close (ZebraHandle zh);
103
104 /*********
105  * Error handling 
106  */
107
108 /* last error code */
109 YAZ_EXPORT int zebra_errCode (ZebraHandle zh);
110
111 /* string representatio of above */
112 YAZ_EXPORT const char *zebra_errString (ZebraHandle zh);
113
114 /* extra information associated with error */
115 YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
116
117 /* get the result code and addinfo from zh */
118 YAZ_EXPORT int zebra_result (ZebraHandle zh, int *code, char **addinfo);
119 /* FIXME - why is this needed?? -H */
120
121 /* clear them error things */
122 YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
123
124 /**************
125  * Searching 
126  */
127
128 /* Search using PQF Query */
129 YAZ_EXPORT int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
130                                  const char *setname, int *numhits);
131
132 /* Search using RPN Query */
133 YAZ_EXPORT int zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query,
134                                  const char *setname, int *hits);
135
136 /* Retrieve record(s) */
137 YAZ_EXPORT int zebra_records_retrieve (ZebraHandle zh, ODR stream,
138                        const char *setname, Z_RecordComposition *comp,
139                        oid_value input_format,
140                        int num_recs, ZebraRetrievalRecord *recs);
141
142 /* Delete Result Set(s) */
143 YAZ_EXPORT int zebra_deleleResultSet(ZebraHandle zh, int function,
144                                      int num_setnames, char **setnames,
145                                      int *statuses);
146
147
148 /* Browse */
149 YAZ_EXPORT int zebra_scan (ZebraHandle zh, ODR stream,
150                            Z_AttributesPlusTerm *zapt,
151                            oid_value attributeset,
152                            int *position, int *num_entries,
153                            ZebraScanEntry **list,
154                            int *is_partial);
155
156    
157           
158 /*********
159  * Other 
160  */
161                       
162 /* do authentication */
163 YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
164
165 /* Character normalisation on specific register .
166    This routine is subject to change - do not use. */
167 YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
168                                   const char *input_str, int input_len,
169                                   char *output_str, int output_len);
170
171
172 /******
173  * Admin 
174  */                   
175           
176 YAZ_EXPORT int zebra_create_database (ZebraHandle zh, const char *db);
177 YAZ_EXPORT int zebra_drop_database (ZebraHandle zh, const char *db);
178
179 YAZ_EXPORT int zebra_admin_shutdown (ZebraHandle zh);
180 YAZ_EXPORT int zebra_admin_start (ZebraHandle zh);
181
182 YAZ_EXPORT int zebra_shutdown (ZebraService zs);
183
184 YAZ_EXPORT int zebra_admin_import_begin (ZebraHandle zh, const char *database,
185                                           const char *record_type);
186
187 YAZ_EXPORT int zebra_admin_import_segment (ZebraHandle zh,
188                                             Z_Segment *segment);
189
190 YAZ_EXPORT int zebra_admin_import_end (ZebraHandle zh);
191
192 int zebra_admin_exchange_record (ZebraHandle zh,
193                                  const char *rec_buf,
194                                  size_t rec_len,
195                                  const char *recid_buf, size_t recid_len,
196                                  int action);
197
198 int zebra_begin_trans (ZebraHandle zh, int rw);
199 int zebra_end_trans (ZebraHandle zh);
200 int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *stat);
201
202 int zebra_commit (ZebraHandle zh);
203 int zebra_clean (ZebraHandle zh);
204
205 int zebra_init (ZebraHandle zh);
206 int zebra_compact (ZebraHandle zh);
207 int zebra_repository_update (ZebraHandle zh, const char *path);
208 int zebra_repository_delete (ZebraHandle zh, const char *path);
209 int zebra_repository_show (ZebraHandle zh, const char *path);
210
211 int zebra_add_record (ZebraHandle zh, const char *buf, int buf_size);
212                                
213 int zebra_insert_record (ZebraHandle zh, 
214                          const char *recordType,
215                          SYSNO *sysno, const char *match, const char *fname,
216                          const char *buf, int buf_size,
217                          int force_update);
218 int zebra_update_record (ZebraHandle zh, 
219                          const char *recordType,
220                          SYSNO *sysno, const char *match, const char *fname,
221                          const char *buf, int buf_size,
222                          int force_update);
223 int zebra_delete_record (ZebraHandle zh, 
224                          const char *recordType,
225                          SYSNO *sysno, const char *match, const char *fname,
226                          const char *buf, int buf_size,
227                          int force_update);
228
229 YAZ_EXPORT int zebra_resultSetTerms (ZebraHandle zh, const char *setname, 
230                                      int no, zint *count, 
231                                      int *type, char *out, size_t *len);
232
233 YAZ_EXPORT int zebra_sort (ZebraHandle zh, ODR stream,
234                            int num_input_setnames,
235                            const char **input_setnames,
236                            const char *output_setname,
237                            Z_SortKeySpecList *sort_sequence,
238                            int *sort_status);
239
240 YAZ_EXPORT
241 int zebra_select_databases (ZebraHandle zh, int num_bases, 
242                             const char **basenames);
243
244 YAZ_EXPORT
245 int zebra_select_database (ZebraHandle zh, const char *basename);
246
247 YAZ_EXPORT
248 int zebra_shadow_enable (ZebraHandle zh, int value);
249
250 YAZ_EXPORT
251 int zebra_register_statistics (ZebraHandle zh, int dumpdict);
252
253 YAZ_EXPORT
254 int zebra_record_encoding (ZebraHandle zh, const char *encoding);
255
256 YAZ_EXPORT
257 int zebra_record_encoding (ZebraHandle zh, const char *encoding);
258
259 YAZ_EXPORT
260 int zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
261
262 /* Resources */
263 YAZ_EXPORT
264 int zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
265 YAZ_EXPORT
266 const char *zebra_get_resource(ZebraHandle zh, 
267                 const char *name, const char *defaultvalue);
268
269
270 YAZ_EXPORT void zebra_pidfname(ZebraService zs, char *path);
271
272 typedef struct {
273     char *term;
274     char *db;
275     zint sysno;
276     int score;
277 } ZebraMetaRecord;
278
279 YAZ_EXPORT
280 ZebraMetaRecord *zebra_meta_records_create (ZebraHandle zh,
281                                             const char *name,
282                                             int num, zint *positions);
283
284
285 YAZ_EXPORT
286 ZebraMetaRecord *zebra_meta_records_create_range (ZebraHandle zh,
287                                                   const char *name, 
288                                                   zint start, int num);
289
290 YAZ_EXPORT
291 void zebra_meta_records_destroy (ZebraHandle zh, ZebraMetaRecord *records,
292                                  int num);
293 YAZ_END_CDECL                                 
294 #endif