Reserved element set _sysno_ returns sysno for record
[idzebra-moved-to-github.git] / include / idzebra / api.h
1 /* $Id: api.h,v 1.17 2005-04-13 08:52:26 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 /** \file api.h
24     \brief Zebra API
25     
26     Return codes:
27     Most functions return an int. Unix-like, 0 means OK, 
28     non-zero means an error. The error info should be available
29     via zebra_errCode and friends. 
30 */
31
32 #ifndef IDZEBRA_API_H
33 #define IDZEBRA_API_H
34
35 #include <yaz/odr.h>
36 #include <yaz/oid.h>
37 #include <yaz/proto.h>
38 #include <idzebra/res.h>
39 #include <idzebra/version.h>
40
41 YAZ_BEGIN_CDECL
42
43 typedef struct {
44     int processed;
45     int inserted;
46     int updated;
47     int deleted;
48     long utime;
49     long stime;
50 } ZebraTransactionStatus;
51
52 /* Retrieval Record Descriptor */
53 typedef struct {
54     int errCode;         /* non-zero if error when fetching this */
55     char *errString;     /* error string */
56     int position;        /* position of record in result set (1,2,..) */
57     char *buf;           /* record buffer (void pointer really) */
58     int len;             /* length */
59     oid_value format;    /* record syntax */
60     char *base; 
61     SYSNO sysno;
62     int  score;
63 } ZebraRetrievalRecord;
64
65 /* Scan Term Descriptor */
66 typedef struct {
67     int occurrences;     /* scan term occurrences */
68     char *term;          /* scan term string */
69 } ZebraScanEntry;
70
71 /** \var ZebraHandle
72     \brief a Zebra Handle - (session)
73 */
74 typedef struct zebra_session *ZebraHandle;
75
76 /** \var ZebraService
77     \brief a Zebra Service handle
78 */
79 typedef struct zebra_service *ZebraService;
80
81 /** \fn ZebraService zebra_start(const char *configName)
82     \brief starts a Zebra service. 
83     \param configName name of configuration file
84     
85     This function is a simplified version of zebra_start_res.
86 */
87 YAZ_EXPORT ZebraService zebra_start(const char *configName);
88
89 /** \fn ZebraService zebra_start_res(const char *configName,
90     Res def_res, Res over_res)
91     \brief starts a Zebra service with resources.
92     \param configName name of configuration file
93     \param def_res default resources
94     \param over_res overriding resources
95     
96     This function typically called once in a program. A Zebra Service
97     acts as a factory for Zebra session handles.
98 */
99 YAZ_EXPORT
100 ZebraService zebra_start_res(const char *configName,
101                              Res def_res, Res over_res);
102
103 /** \fn int zebra_stop(ZebraService zs)
104     \brief stops a Zebra service.
105     \param zs service handle
106     
107     Frees resources used by the service.
108 */
109 YAZ_EXPORT
110 int zebra_stop(ZebraService zs);
111
112 /** \fn void zebra_filter_info(ZebraService zs, void *cd,
113     void(*cb)(void *cd, const char *name))
114     \brief lists enabled Zebra filters
115     \param zs service handle
116     \param cd callback parameter (opaque)
117     \param cb callback function
118  */
119 YAZ_EXPORT
120 void zebra_filter_info(ZebraService zs, void *cd,
121                        void (*cb)(void *cd, const char *name));
122
123
124 /** \fn ZebraHandle zebra_open(ZebraService zs)
125     \brief creates a Zebra session handle within service.
126     \param zs service handle.
127     
128     There should be one handle for each thread doing something
129     with zebra, be that searching or indexing. In simple apps 
130     one handle is sufficient 
131 */
132 YAZ_EXPORT ZebraHandle zebra_open(ZebraService zs);
133
134 /** \fn int zebra_close(ZebraHandle zh)
135     \brief destroys Zebra session handle.
136     \param zh zebra session handle.
137  */
138 YAZ_EXPORT int zebra_close(ZebraHandle zh);
139
140 /** \fn int zebra_errCode(ZebraHandle zh)
141     \brief returns error code for last error
142     \param zh zebra session handle.
143 */
144 YAZ_EXPORT int zebra_errCode(ZebraHandle zh);
145
146 /** \fn const char *zebra_errString(ZebraHandle zh)
147     \brief returns error string for last error
148     \param zh zebra session handle.
149 */
150 YAZ_EXPORT const char *zebra_errString(ZebraHandle zh);
151
152 /** \fn char *zebra_errAdd(ZebraHandle zh)
153     \brief returns additional info for last error
154     \param zh zebra session handle.
155 */
156 YAZ_EXPORT char *zebra_errAdd(ZebraHandle zh);
157
158 /** \fn int zebra_result(ZebraHandle zh, int *code, char **addinfo)
159     \brief returns error code and additional info for last error
160     \param zh zebra session handle.
161     \param code pointer to returned error code
162     \param addinfo pointer to returned additional info
163 */
164 YAZ_EXPORT int zebra_result(ZebraHandle zh, int *code, char **addinfo);
165
166 /** \fn void zebra_clearError(ZebraHandle zh)
167     \brief clears last error.
168     \param zh zebra session handle.
169  */
170 YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
171
172 /** \fn int zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
173     const char *setname, int *hits)
174     \brief Search using PQF Query 
175     \param zh session handle
176     \param pqf_query query
177     \param setname name of resultset
178     \param hits of hits is returned
179  */
180 YAZ_EXPORT int zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
181                                 const char *setname, zint *hits);
182
183 /** \fn int zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
184     const char *setname, zint *hits)
185     \brief Search using RPN Query 
186     \param zh session handle
187     \param o ODR handle
188     \param query RPN query using YAZ structure
189     \param setname name of resultset
190     \param hits number of hits is returned
191  */
192 YAZ_EXPORT int zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
193                                 const char *setname, zint *hits);
194
195 /** 
196     \fn int zebra_records_retrieve(ZebraHandle zh, ODR stream,
197     const char *setname, Z_RecordComposition *comp, oid_value input_format,
198     int num_recs, ZebraRetrievalRecord *recs)
199     \brief retrieve records from result set (after search)
200     \param zh session handle
201     \param stream allocate records returned using this ODR
202     \param setname name of result set to retrieve records from
203     \param comp Z39.50 record composition
204     \param input_format transfer syntax (OID)
205     \param num_recs number of records to retrieve
206     \param recs store records in this structure (size is num_recs)
207 */
208 YAZ_EXPORT int zebra_records_retrieve(ZebraHandle zh, ODR stream,
209                        const char *setname, Z_RecordComposition *comp,
210                        oid_value input_format,
211                        int num_recs, ZebraRetrievalRecord *recs);
212
213 /**
214    \fn int zebra_deleteResultSet(ZebraHandle zh, int function,
215    int num_setnames, char **setnames, int *statuses)
216    \brief delete one or more resultsets 
217    \param zh session handle
218    \param function Z_DeleteResultSetRequest_{list,all}
219    \param num_setnames number of result sets
220    \param setnames result set names
221    \param statuses status result
222 */
223 YAZ_EXPORT int zebra_deleteResultSet(ZebraHandle zh, int function,
224                                      int num_setnames, char **setnames,
225                                      int *statuses);
226
227 /**
228    \fn int zebra_scan(ZebraHandle zh, ODR stream,
229    Z_AttributesPlusTerm *zapt, oid_value attributeset,
230    int *position, int *num_entries, ZebraScanEntry **list, int *is_partial)
231    \brief performs Scan (Z39.50 style)
232    \param zh session handle
233    \param stream ODR handle for result
234    \param zapt Attribute plus Term (start term)
235    \param attributeset Attributeset for Attribute plus Term
236    \param position input/output position
237    \param num_entries number of terms requested / returned 
238    \param list list of resulting terms (ODR allocated)
239    \param is_partial upon return 1=partial, 0=complete
240 */
241 YAZ_EXPORT int zebra_scan(ZebraHandle zh, ODR stream,
242                           Z_AttributesPlusTerm *zapt,
243                           oid_value attributeset,
244                           int *position, int *num_entries,
245                           ZebraScanEntry **list,
246                           int *is_partial);
247
248 /**
249    \fn int zebra_scan_PQF(ZebraHandle zh, ODR stream,
250    const char *query, int *position, int *num_entries, ZebraScanEntry **list, int *is_partial)
251    \brief performs Scan (taking PQF string)
252    \param zh session handle
253    \param stream ODR handle for result
254    \param query PQF scan query
255    \param position input/output position
256    \param num_entries number of terms requested / returned 
257    \param list list of resulting terms (ODR allocated)
258    \param is_partial upon return 1=partial, 0=complete
259 */
260 YAZ_EXPORT int zebra_scan_PQF(ZebraHandle zh, ODR stream,
261                               const char *query,
262                               int *position, int *num_entries,
263                               ZebraScanEntry **entries,
264                               int *is_partial);
265 /**
266    \fn int zebra_auth(ZebraHandle zh, const char *user, const char *pass)
267    \brief authenticate user. Returns 0 if OK, != 0 on failure
268    \param zh session handle
269    \param user user name
270    \param pass password
271  */
272 YAZ_EXPORT int zebra_auth(ZebraHandle zh, const char *user, const char *pass);
273
274
275 /**
276    \fn int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
277    const char *input_str, int input_len,
278    char *output_str, int output_len)
279    \brief normalize zebra term for register (subject to change!)
280    \param zh session handle
281    \param reg_id register ID, 'w', 'p',..
282    \param input_str input string buffer
283    \param input_len input string length
284    \param output_str output string buffer
285    \param output_len output string length
286  */
287 YAZ_EXPORT int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
288                                   const char *input_str, int input_len,
289                                   char *output_str, int output_len);
290
291 /**
292    \fn int zebra_create_database(ZebraHandle zh, const char *db)
293    \brief creates a database
294    \param zh session handle
295    \param db database to be created
296 */
297 YAZ_EXPORT int zebra_create_database(ZebraHandle zh, const char *db);
298
299 /**
300    \fn int zebra_drop_database(ZebraHandle zh, const char *db)
301    \brief deletes a database (drop)
302    \param zh session handle
303    \param db database to be deleted
304 */
305 YAZ_EXPORT int zebra_drop_database(ZebraHandle zh, const char *db);
306
307 YAZ_EXPORT int zebra_admin_shutdown(ZebraHandle zh);
308 YAZ_EXPORT int zebra_admin_start(ZebraHandle zh);
309
310 YAZ_EXPORT int zebra_shutdown(ZebraService zs);
311
312 YAZ_EXPORT int zebra_admin_import_begin(ZebraHandle zh, const char *database,
313                                           const char *record_type);
314
315 YAZ_EXPORT int zebra_admin_import_segment(ZebraHandle zh,
316                                             Z_Segment *segment);
317
318 YAZ_EXPORT int zebra_admin_import_end(ZebraHandle zh);
319
320 YAZ_EXPORT int zebra_admin_exchange_record(ZebraHandle zh,
321                                  const char *rec_buf,
322                                  size_t rec_len,
323                                  const char *recid_buf, size_t recid_len,
324                                  int action);
325
326 YAZ_EXPORT int zebra_begin_trans(ZebraHandle zh, int rw);
327 YAZ_EXPORT int zebra_end_trans(ZebraHandle zh);
328 YAZ_EXPORT int zebra_end_transaction(ZebraHandle zh, ZebraTransactionStatus *stat);
329
330 YAZ_EXPORT int zebra_commit(ZebraHandle zh);
331 YAZ_EXPORT int zebra_clean(ZebraHandle zh);
332
333 YAZ_EXPORT int zebra_init(ZebraHandle zh);
334 YAZ_EXPORT int zebra_compact(ZebraHandle zh);
335 YAZ_EXPORT int zebra_repository_update(ZebraHandle zh, const char *path);
336 YAZ_EXPORT int zebra_repository_delete(ZebraHandle zh, const char *path);
337 YAZ_EXPORT int zebra_repository_show(ZebraHandle zh, const char *path);
338
339 YAZ_EXPORT int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
340                                
341 YAZ_EXPORT int zebra_insert_record(ZebraHandle zh, 
342                          const char *recordType,
343                          SYSNO *sysno, const char *match, const char *fname,
344                          const char *buf, int buf_size,
345                          int force_update);
346 YAZ_EXPORT int zebra_update_record(ZebraHandle zh, 
347                          const char *recordType,
348                          SYSNO *sysno, const char *match, const char *fname,
349                          const char *buf, int buf_size,
350                          int force_update);
351 YAZ_EXPORT int zebra_delete_record(ZebraHandle zh, 
352                          const char *recordType,
353                          SYSNO *sysno, const char *match, const char *fname,
354                          const char *buf, int buf_size,
355                          int force_update);
356
357 YAZ_EXPORT int zebra_resultSetTerms(ZebraHandle zh, const char *setname, 
358                                      int no, zint *count, 
359                                      int *type, char *out, size_t *len);
360
361 YAZ_EXPORT int zebra_sort(ZebraHandle zh, ODR stream,
362                            int num_input_setnames,
363                            const char **input_setnames,
364                            const char *output_setname,
365                            Z_SortKeySpecList *sort_sequence,
366                            int *sort_status);
367
368 YAZ_EXPORT
369 int zebra_select_databases(ZebraHandle zh, int num_bases, 
370                            const char **basenames);
371
372 YAZ_EXPORT
373 int zebra_select_database(ZebraHandle zh, const char *basename);
374
375 YAZ_EXPORT
376 int zebra_shadow_enable(ZebraHandle zh, int value);
377
378 YAZ_EXPORT
379 int zebra_register_statistics(ZebraHandle zh, int dumpdict);
380
381 YAZ_EXPORT
382 int zebra_record_encoding(ZebraHandle zh, const char *encoding);
383
384 YAZ_EXPORT
385 int zebra_record_encoding(ZebraHandle zh, const char *encoding);
386
387 YAZ_EXPORT
388 int zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
389
390 /* Resources */
391 YAZ_EXPORT
392 int zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
393 YAZ_EXPORT
394 const char *zebra_get_resource(ZebraHandle zh, 
395                 const char *name, const char *defaultvalue);
396
397
398 YAZ_EXPORT void zebra_pidfname(ZebraService zs, char *path);
399
400 typedef struct {
401     char *term;
402     char *db;
403     zint sysno;
404     int score;
405 } ZebraMetaRecord;
406
407 YAZ_EXPORT
408 ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh,
409                                            const char *name,
410                                            int num, zint *positions);
411
412
413 YAZ_EXPORT
414 ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
415                                                  const char *name, 
416                                                  zint start, int num);
417
418 YAZ_EXPORT
419 void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records,
420                                 int num);
421
422 YAZ_EXPORT 
423 struct BFiles_struct *zebra_get_bfs(ZebraHandle zh);
424 YAZ_END_CDECL                                 
425 #endif