Added zebra_meta_records_create_range
[idzebra-moved-to-github.git] / include / idzebra / api.h
1 /* $Id: api.h,v 1.4 2004-12-02 17:27:03 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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 /* Return codes:
24  * Most functions return an int. Unix-like, 0 means OK, 
25  * non-zero means an error. The error info should be available
26  * via zebra_errCode and friends. 
27  */
28
29 #ifndef ZEBRAAPI_H
30 #define ZEBRAAPI_H
31
32 #include <yaz/odr.h>
33 #include <yaz/oid.h>
34 #include <yaz/proto.h>
35 #include <idzebra/res.h>
36 #include <idzebra/version.h>
37
38 /* Fixme! Compare string (ignore case) */
39 #ifdef WIN32
40 #define STRCASECMP      stricmp
41 #else
42 #define STRCASECMP      strcasecmp
43 #endif
44
45 YAZ_BEGIN_CDECL
46
47 typedef struct {
48   int processed;
49   int inserted;
50   int updated;
51   int deleted;
52   long utime;
53   long stime;
54 } ZebraTransactionStatus;
55
56 /* Retrieval Record Descriptor */
57 typedef struct {
58     int errCode;         /* non-zero if error when fetching this */
59     char *errString;     /* error string */
60     int position;        /* position of record in result set (1,2,..) */
61     char *buf;           /* record buffer (void pointer really) */
62     int len;             /* length */
63     oid_value format;    /* record syntax */
64     char *base; 
65     SYSNO sysno;
66     int  score;
67 } ZebraRetrievalRecord;
68
69 /* Scan Term Descriptor */
70 typedef struct {
71     int occurrences;     /* scan term occurrences */
72     char *term;          /* scan term string */
73 } ZebraScanEntry;
74
75 typedef struct zebra_session *ZebraHandle;
76 typedef struct zebra_service *ZebraService;
77
78
79 /******
80  * Starting and stopping 
81  */
82
83 /* Start Zebra using file 'configName' (usually zebra.cfg) */
84 /* There should be exactly one ZebraService */
85 YAZ_EXPORT ZebraService zebra_start (const char *configName);
86 YAZ_EXPORT ZebraService zebra_start_res (const char *configName,
87                                          Res def_res, Res over_res);
88
89 /* Close the whole Zebra */
90 YAZ_EXPORT int zebra_stop (ZebraService zs);
91
92 /* Report name of each record class (filter) */
93 YAZ_EXPORT void zebra_filter_info(ZebraService zs, void *cd,
94                                   void (*cb)(void *cd, const char *name));
95
96
97 /* Open a ZebraHandle */
98 /* There should be one handle for each thred doing something */
99 /* with zebra, be that searching or indexing. In simple apps */
100 /* one handle is sufficient */
101 YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs);
102
103 /* Close handle */
104 YAZ_EXPORT int zebra_close (ZebraHandle zh);
105
106 /*********
107  * Error handling 
108  */
109
110 /* last error code */
111 YAZ_EXPORT int zebra_errCode (ZebraHandle zh);
112
113 /* string representatio of above */
114 YAZ_EXPORT const char *zebra_errString (ZebraHandle zh);
115
116 /* extra information associated with error */
117 YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
118
119 /* get the result code and addinfo from zh */
120 YAZ_EXPORT int zebra_result (ZebraHandle zh, int *code, char **addinfo);
121 /* FIXME - why is this needed?? -H */
122
123 /* clear them error things */
124 YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
125
126 /**************
127  * Searching 
128  */
129
130 /* Search using PQF Query */
131 YAZ_EXPORT int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
132                                  const char *setname, int *numhits);
133
134 /* Search using RPN Query */
135 YAZ_EXPORT int zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query,
136                                  const char *setname, int *hits);
137
138 /* Retrieve record(s) */
139 YAZ_EXPORT int zebra_records_retrieve (ZebraHandle zh, ODR stream,
140                        const char *setname, Z_RecordComposition *comp,
141                        oid_value input_format,
142                        int num_recs, ZebraRetrievalRecord *recs);
143
144 /* Delete Result Set(s) */
145 YAZ_EXPORT int zebra_deleleResultSet(ZebraHandle zh, int function,
146                                      int num_setnames, char **setnames,
147                                      int *statuses);
148
149
150 /* Browse */
151 YAZ_EXPORT int zebra_scan (ZebraHandle zh, ODR stream,
152                            Z_AttributesPlusTerm *zapt,
153                            oid_value attributeset,
154                            int *position, int *num_entries,
155                            ZebraScanEntry **list,
156                            int *is_partial);
157
158    
159           
160 /*********
161  * Other 
162  */
163                       
164 /* do authentication */
165 YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
166
167 /* Character normalisation on specific register .
168    This routine is subject to change - do not use. */
169 YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
170                                   const char *input_str, int input_len,
171                                   char *output_str, int output_len);
172
173
174 /******
175  * Admin 
176  */                   
177           
178 YAZ_EXPORT int zebra_create_database (ZebraHandle zh, const char *db);
179 YAZ_EXPORT int zebra_drop_database (ZebraHandle zh, const char *db);
180
181 YAZ_EXPORT int zebra_admin_shutdown (ZebraHandle zh);
182 YAZ_EXPORT int zebra_admin_start (ZebraHandle zh);
183
184 YAZ_EXPORT int zebra_shutdown (ZebraService zs);
185
186 YAZ_EXPORT int zebra_admin_import_begin (ZebraHandle zh, const char *database,
187                                           const char *record_type);
188
189 YAZ_EXPORT int zebra_admin_import_segment (ZebraHandle zh,
190                                             Z_Segment *segment);
191
192 YAZ_EXPORT int zebra_admin_import_end (ZebraHandle zh);
193
194 int zebra_admin_exchange_record (ZebraHandle zh,
195                                  const char *rec_buf,
196                                  size_t rec_len,
197                                  const char *recid_buf, size_t recid_len,
198                                  int action);
199
200 int zebra_begin_trans (ZebraHandle zh, int rw);
201 int zebra_end_trans (ZebraHandle zh);
202 int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *stat);
203
204 int zebra_commit (ZebraHandle zh);
205 int zebra_clean (ZebraHandle zh);
206
207 int zebra_init (ZebraHandle zh);
208 int zebra_compact (ZebraHandle zh);
209 int zebra_repository_update (ZebraHandle zh, const char *path);
210 int zebra_repository_delete (ZebraHandle zh, const char *path);
211 int zebra_repository_show (ZebraHandle zh, const char *path);
212
213 int zebra_add_record (ZebraHandle zh, const char *buf, int buf_size);
214                                
215 int zebra_insert_record (ZebraHandle zh, 
216                          const char *recordType,
217                          SYSNO *sysno, const char *match, const char *fname,
218                          const char *buf, int buf_size,
219                          int force_update);
220 int zebra_update_record (ZebraHandle zh, 
221                          const char *recordType,
222                          SYSNO *sysno, const char *match, const char *fname,
223                          const char *buf, int buf_size,
224                          int force_update);
225 int zebra_delete_record (ZebraHandle zh, 
226                          const char *recordType,
227                          SYSNO *sysno, const char *match, const char *fname,
228                          const char *buf, int buf_size,
229                          int force_update);
230
231 YAZ_EXPORT int zebra_resultSetTerms (ZebraHandle zh, const char *setname, 
232                                      int no, zint *count, 
233                                      int *type, char *out, size_t *len);
234
235 YAZ_EXPORT int zebra_sort (ZebraHandle zh, ODR stream,
236                            int num_input_setnames,
237                            const char **input_setnames,
238                            const char *output_setname,
239                            Z_SortKeySpecList *sort_sequence,
240                            int *sort_status);
241
242 YAZ_EXPORT
243 int zebra_select_databases (ZebraHandle zh, int num_bases, 
244                             const char **basenames);
245
246 YAZ_EXPORT
247 int zebra_select_database (ZebraHandle zh, const char *basename);
248
249 YAZ_EXPORT
250 int zebra_shadow_enable (ZebraHandle zh, int value);
251
252 YAZ_EXPORT
253 int zebra_register_statistics (ZebraHandle zh, int dumpdict);
254
255 YAZ_EXPORT
256 int zebra_record_encoding (ZebraHandle zh, const char *encoding);
257
258 /* Resources */
259 YAZ_EXPORT
260 int zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
261 YAZ_EXPORT
262 const char *zebra_get_resource(ZebraHandle zh, 
263                 const char *name, const char *defaultvalue);
264
265
266 YAZ_EXPORT void zebra_pidfname(ZebraService zs, char *path);
267
268 typedef struct {
269     char *term;
270     char *db;
271     zint sysno;
272     int score;
273 } ZebraMetaRecord;
274
275 YAZ_EXPORT
276 ZebraMetaRecord *zebra_meta_records_create (ZebraHandle zh,
277                                             const char *name,
278                                             int num, zint *positions);
279
280
281 YAZ_EXPORT
282 ZebraMetaRecord *zebra_meta_records_create_range (ZebraHandle zh,
283                                                   const char *name, 
284                                                   zint start, int num);
285
286 YAZ_EXPORT
287 void zebra_meta_records_destroy (ZebraHandle zh, ZebraMetaRecord *records,
288                                  int num);
289 YAZ_END_CDECL                                 
290 #endif