1 /* $Id: api.h,v 1.19 2005-04-26 08:11:22 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
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
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
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
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.
37 #include <yaz/proto.h>
38 #include <idzebra/res.h>
39 #include <idzebra/version.h>
50 } ZebraTransactionStatus;
52 /* Retrieval Record Descriptor */
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) */
59 oid_value format; /* record syntax */
63 } ZebraRetrievalRecord;
65 /* Scan Term Descriptor */
67 int occurrences; /* scan term occurrences */
68 char *term; /* scan term string */
72 \brief a Zebra Handle - (session)
74 typedef struct zebra_session *ZebraHandle;
77 \brief a Zebra Service handle
79 typedef struct zebra_service *ZebraService;
81 /** \fn ZebraService zebra_start(const char *configName)
82 \brief starts a Zebra service.
83 \param configName name of configuration file
85 This function is a simplified version of zebra_start_res.
87 YAZ_EXPORT ZebraService zebra_start(const char *configName);
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
96 This function typically called once in a program. A Zebra Service
97 acts as a factory for Zebra session handles.
100 ZebraService zebra_start_res(const char *configName,
101 Res def_res, Res over_res);
103 /** \fn ZEBRA_RES zebra_stop(ZebraService zs)
104 \brief stops a Zebra service.
105 \param zs service handle
107 Frees resources used by the service.
110 ZEBRA_RES zebra_stop(ZebraService zs);
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
120 void zebra_filter_info(ZebraService zs, void *cd,
121 void (*cb)(void *cd, const char *name));
124 /** \fn ZebraHandle zebra_open(ZebraService zs)
125 \brief creates a Zebra session handle within service.
126 \param zs service handle.
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
132 YAZ_EXPORT ZebraHandle zebra_open(ZebraService zs);
134 /** \fn int zebra_close(ZebraHandle zh)
135 \brief destroys Zebra session handle.
136 \param zh zebra session handle.
138 YAZ_EXPORT ZEBRA_RES zebra_close(ZebraHandle zh);
140 /** \fn int zebra_errCode(ZebraHandle zh)
141 \brief returns error code for last error
142 \param zh zebra session handle.
144 YAZ_EXPORT int zebra_errCode(ZebraHandle zh);
146 /** \fn const char *zebra_errString(ZebraHandle zh)
147 \brief returns error string for last error
148 \param zh zebra session handle.
150 YAZ_EXPORT const char *zebra_errString(ZebraHandle zh);
152 /** \fn char *zebra_errAdd(ZebraHandle zh)
153 \brief returns additional info for last error
154 \param zh zebra session handle.
156 YAZ_EXPORT char *zebra_errAdd(ZebraHandle zh);
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
164 YAZ_EXPORT void zebra_result(ZebraHandle zh, int *code, char **addinfo);
166 /** \fn void zebra_clearError(ZebraHandle zh)
167 \brief clears last error.
168 \param zh zebra session handle.
170 YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
172 /** \fn ZEBRA_RES 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
180 YAZ_EXPORT ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
181 const char *setname, zint *hits);
183 /** \fn ZEBRA_RES 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
188 \param query RPN query using YAZ structure
189 \param setname name of resultset
190 \param hits number of hits is returned
192 YAZ_EXPORT ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
193 const char *setname, zint *hits);
196 \fn ZEBRA_RES 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)
209 ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
211 Z_RecordComposition *comp,
212 oid_value input_format,
214 ZebraRetrievalRecord *recs);
216 \fn int zebra_deleteResultSet(ZebraHandle zh, int function,
217 int num_setnames, char **setnames, int *statuses)
218 \brief delete one or more resultsets
219 \param zh session handle
220 \param function Z_DeleteResultSetRequest_{list,all}
221 \param num_setnames number of result sets
222 \param setnames result set names
223 \param statuses status result
226 int zebra_deleteResultSet(ZebraHandle zh, int function,
227 int num_setnames, char **setnames,
231 \fn ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
232 Z_AttributesPlusTerm *zapt, oid_value attributeset,
233 int *position, int *num_entries, ZebraScanEntry **list, int *is_partial)
234 \brief performs Scan (Z39.50 style)
235 \param zh session handle
236 \param stream ODR handle for result
237 \param zapt Attribute plus Term (start term)
238 \param attributeset Attributeset for Attribute plus Term
239 \param position input/output position
240 \param num_entries number of terms requested / returned
241 \param list list of resulting terms (ODR allocated)
242 \param is_partial upon return 1=partial, 0=complete
244 YAZ_EXPORT ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
245 Z_AttributesPlusTerm *zapt,
246 oid_value attributeset,
247 int *position, int *num_entries,
248 ZebraScanEntry **list,
252 \fn ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream,
253 const char *query, int *position, int *num_entries, ZebraScanEntry **list, int *is_partial)
254 \brief performs Scan (taking PQF string)
255 \param zh session handle
256 \param stream ODR handle for result
257 \param query PQF scan query
258 \param position input/output position
259 \param num_entries number of terms requested / returned
260 \param list list of resulting terms (ODR allocated)
261 \param is_partial upon return 1=partial, 0=complete
263 YAZ_EXPORT ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream,
265 int *position, int *num_entries,
266 ZebraScanEntry **entries,
269 \fn ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass)
270 \brief authenticate user. Returns 0 if OK, != 0 on failure
271 \param zh session handle
272 \param user user name
275 YAZ_EXPORT ZEBRA_RES zebra_auth(ZebraHandle zh,
276 const char *user, const char *pass);
279 \fn int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
280 const char *input_str, int input_len,
281 char *output_str, int output_len)
282 \brief normalize zebra term for register (subject to change!)
283 \param zh session handle
284 \param reg_id register ID, 'w', 'p',..
285 \param input_str input string buffer
286 \param input_len input string length
287 \param output_str output string buffer
288 \param output_len output string length
290 YAZ_EXPORT int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
291 const char *input_str, int input_len,
292 char *output_str, int output_len);
295 \fn ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db)
296 \brief creates a database
297 \param zh session handle
298 \param db database to be created
300 YAZ_EXPORT ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db);
303 \fn int zebra_drop_database(ZebraHandle zh, const char *db)
304 \brief deletes a database (drop)
305 \param zh session handle
306 \param db database to be deleted
309 ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db);
312 ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh);
315 ZEBRA_RES zebra_admin_start(ZebraHandle zh);
318 ZEBRA_RES zebra_shutdown(ZebraService zs);
321 ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
322 const char *record_type);
325 ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
329 ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
332 ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
335 const char *recid_buf, size_t recid_len,
339 ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw);
342 ZEBRA_RES zebra_end_trans(ZebraHandle zh);
345 ZEBRA_RES zebra_end_transaction(ZebraHandle zh,
346 ZebraTransactionStatus *stat);
349 ZEBRA_RES zebra_commit(ZebraHandle zh);
352 ZEBRA_RES zebra_clean(ZebraHandle zh);
355 ZEBRA_RES zebra_init(ZebraHandle zh);
358 ZEBRA_RES zebra_compact(ZebraHandle zh);
360 YAZ_EXPORT int zebra_repository_update(ZebraHandle zh, const char *path);
361 YAZ_EXPORT int zebra_repository_delete(ZebraHandle zh, const char *path);
362 YAZ_EXPORT int zebra_repository_show(ZebraHandle zh, const char *path);
364 YAZ_EXPORT int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
367 ZEBRA_RES zebra_insert_record(ZebraHandle zh,
368 const char *recordType,
369 SYSNO *sysno, const char *match,
371 const char *buf, int buf_size,
374 ZEBRA_RES zebra_update_record(ZebraHandle zh,
375 const char *recordType,
376 SYSNO *sysno, const char *match,
378 const char *buf, int buf_size,
381 ZEBRA_RES zebra_delete_record(ZebraHandle zh,
382 const char *recordType,
383 SYSNO *sysno, const char *match, const char *fname,
384 const char *buf, int buf_size,
388 int zebra_resultSetTerms(ZebraHandle zh, const char *setname,
390 int *type, char *out, size_t *len);
393 ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
394 int num_input_setnames,
395 const char **input_setnames,
396 const char *output_setname,
397 Z_SortKeySpecList *sort_sequence,
401 ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
402 const char **basenames);
405 ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename);
408 void zebra_shadow_enable(ZebraHandle zh, int value);
411 int zebra_register_statistics(ZebraHandle zh, int dumpdict);
414 ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding);
417 ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
421 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
423 const char *zebra_get_resource(ZebraHandle zh,
424 const char *name, const char *defaultvalue);
428 void zebra_pidfname(ZebraService zs, char *path);
438 ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh,
440 int num, zint *positions);
444 ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
446 zint start, int num);
449 void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records,
453 struct BFiles_struct *zebra_get_bfs(ZebraHandle zh);