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