1 /* $Id: api.h,v 1.23 2005-05-09 10:16:12 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 ZEBRA_RES, where ZEBRA_FAIL indicates
28 failure; ZEBRA_OK indicates success.
36 #include <yaz/proto.h>
37 #include <idzebra/res.h>
38 #include <idzebra/version.h>
49 } ZebraTransactionStatus;
51 /** Retrieval Record Descriptor */
53 int errCode; /* non-zero if error when fetching this */
54 char *errString; /* error string */
55 int position; /* position of record in result set (1,2,..) */
56 char *buf; /* record buffer (void pointer really) */
58 oid_value format; /* record syntax */
62 } ZebraRetrievalRecord;
64 /** Scan Term Descriptor */
66 int occurrences; /* scan term occurrences */
67 char *term; /* scan term string */
71 \brief a Zebra Handle - (session)
73 typedef struct zebra_session *ZebraHandle;
76 \brief a Zebra Service handle
78 typedef struct zebra_service *ZebraService;
80 /** \fn ZebraService zebra_start(const char *configName)
81 \brief starts a Zebra service.
82 \param configName name of configuration file
84 This function is a simplified version of zebra_start_res.
87 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
133 ZebraHandle zebra_open(ZebraService zs);
135 /** \fn int zebra_close(ZebraHandle zh)
136 \brief destroys Zebra session handle.
137 \param zh zebra session handle.
140 ZEBRA_RES zebra_close(ZebraHandle zh);
142 /** \fn int zebra_errCode(ZebraHandle zh)
143 \brief returns error code for last error
144 \param zh zebra session handle.
147 int zebra_errCode(ZebraHandle zh);
149 /** \fn const char *zebra_errString(ZebraHandle zh)
150 \brief returns error string for last error
151 \param zh zebra session handle.
154 const char *zebra_errString(ZebraHandle zh);
156 /** \fn char *zebra_errAdd(ZebraHandle zh)
157 \brief returns additional info for last error
158 \param zh zebra session handle.
161 char *zebra_errAdd(ZebraHandle zh);
163 /** \fn int zebra_result(ZebraHandle zh, int *code, char **addinfo)
164 \brief returns error code and additional info for last error
165 \param zh zebra session handle.
166 \param code pointer to returned error code
167 \param addinfo pointer to returned additional info
170 void zebra_result(ZebraHandle zh, int *code, char **addinfo);
172 /** \fn void zebra_clearError(ZebraHandle zh)
173 \brief clears last error.
174 \param zh zebra session handle.
177 void zebra_clearError(ZebraHandle zh);
179 /** \fn ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query, \
180 const char *setname, zint *hits)
181 \brief Search using PQF Query
182 \param zh session handle
183 \param pqf_query query
184 \param setname name of resultset
185 \param hits of hits is returned
188 ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
189 const char *setname, zint *hits);
191 /** \fn ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query, \
192 const char *setname, zint *hits)
193 \brief Search using RPN Query
194 \param zh session handle
196 \param query RPN query using YAZ structure
197 \param setname name of resultset
198 \param hits number of hits is returned
201 ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
202 const char *setname, zint *hits);
205 \fn ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream, \
206 const char *setname, Z_RecordComposition *comp, \
207 oid_value input_format, int num_recs, \
208 ZebraRetrievalRecord *recs)
209 \brief retrieve records from result set (after search)
210 \param zh session handle
211 \param stream allocate records returned using this ODR
212 \param setname name of result set to retrieve records from
213 \param comp Z39.50 record composition
214 \param input_format transfer syntax (OID)
215 \param num_recs number of records to retrieve
216 \param recs store records in this structure (size is num_recs)
219 ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
221 Z_RecordComposition *comp,
222 oid_value input_format,
224 ZebraRetrievalRecord *recs);
226 \fn int zebra_deleteResultSet(ZebraHandle zh, int function, \
227 int num_setnames, char **setnames, int *statuses)
228 \brief delete one or more resultsets
229 \param zh session handle
230 \param function Z_DeleteResultSetRequest_{list,all}
231 \param num_setnames number of result sets
232 \param setnames result set names
233 \param statuses status result
236 int zebra_deleteResultSet(ZebraHandle zh, int function,
237 int num_setnames, char **setnames,
241 \fn ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, \
242 Z_AttributesPlusTerm *zapt, oid_value attributeset, \
243 int *position, int *num_entries, ZebraScanEntry **list, \
245 \brief performs Scan (Z39.50 style)
246 \param zh session handle
247 \param stream ODR handle for result
248 \param zapt Attribute plus Term (start term)
249 \param attributeset Attributeset for Attribute plus Term
250 \param position input/output position
251 \param num_entries number of terms requested / returned
252 \param list list of resulting terms (ODR allocated)
253 \param is_partial upon return 1=partial, 0=complete
255 YAZ_EXPORT ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
256 Z_AttributesPlusTerm *zapt,
257 oid_value attributeset,
258 int *position, int *num_entries,
259 ZebraScanEntry **list,
263 \fn ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, \
264 const char *query, int *position, int *num_entries, \
265 ZebraScanEntry **list, int *is_partial)
266 \brief performs Scan (taking PQF string)
267 \param zh session handle
268 \param stream ODR handle for result
269 \param query PQF scan query
270 \param position input/output position
271 \param num_entries number of terms requested / returned
272 \param list list of resulting terms (ODR allocated)
273 \param is_partial upon return 1=partial, 0=complete
276 ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
277 int *position, int *num_entries, ZebraScanEntry **entries,
280 \fn ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass)
281 \brief authenticate user. Returns 0 if OK, != 0 on failure
282 \param zh session handle
283 \param user user name
287 ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass);
290 \fn int zebra_string_norm(ZebraHandle zh, unsigned reg_id, \
291 const char *input_str, int input_len, \
292 char *output_str, int output_len)
293 \brief normalize zebra term for register (subject to change!)
294 \param zh session handle
295 \param reg_id register ID, 'w', 'p',..
296 \param input_str input string buffer
297 \param input_len input string length
298 \param output_str output string buffer
299 \param output_len output string length
302 int zebra_string_norm(ZebraHandle zh, unsigned reg_id, const char *input_str,
303 int input_len, char *output_str, int output_len);
306 \fn ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db)
307 \brief creates a database
308 \param zh session handle
309 \param db database to be created
312 ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db);
315 \fn int zebra_drop_database(ZebraHandle zh, const char *db)
316 \brief deletes a database (drop)
317 \param zh session handle
318 \param db database to be deleted
321 ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db);
324 ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh);
327 ZEBRA_RES zebra_admin_start(ZebraHandle zh);
330 ZEBRA_RES zebra_shutdown(ZebraService zs);
333 ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
334 const char *record_type);
337 ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
341 ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
344 ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
347 const char *recid_buf, size_t recid_len,
351 ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw);
354 ZEBRA_RES zebra_end_trans(ZebraHandle zh);
357 ZEBRA_RES zebra_end_transaction(ZebraHandle zh,
358 ZebraTransactionStatus *stat);
361 ZEBRA_RES zebra_commit(ZebraHandle zh);
364 ZEBRA_RES zebra_clean(ZebraHandle zh);
367 ZEBRA_RES zebra_init(ZebraHandle zh);
370 ZEBRA_RES zebra_compact(ZebraHandle zh);
372 YAZ_EXPORT int zebra_repository_update(ZebraHandle zh, const char *path);
373 YAZ_EXPORT int zebra_repository_delete(ZebraHandle zh, const char *path);
374 YAZ_EXPORT int zebra_repository_show(ZebraHandle zh, const char *path);
376 YAZ_EXPORT int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
379 ZEBRA_RES zebra_insert_record(ZebraHandle zh,
380 const char *recordType,
381 SYSNO *sysno, const char *match,
383 const char *buf, int buf_size,
386 ZEBRA_RES zebra_update_record(ZebraHandle zh,
387 const char *recordType,
388 SYSNO *sysno, const char *match,
390 const char *buf, int buf_size,
393 ZEBRA_RES zebra_delete_record(ZebraHandle zh,
394 const char *recordType,
395 SYSNO *sysno, const char *match, const char *fname,
396 const char *buf, int buf_size,
400 int zebra_resultSetTerms(ZebraHandle zh, const char *setname,
402 int *type, char *out, size_t *len);
405 ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
406 int num_input_setnames,
407 const char **input_setnames,
408 const char *output_setname,
409 Z_SortKeySpecList *sort_sequence,
413 ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
414 const char **basenames);
417 ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename);
420 void zebra_shadow_enable(ZebraHandle zh, int value);
423 int zebra_register_statistics(ZebraHandle zh, int dumpdict);
426 ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding);
429 ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
433 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
435 const char *zebra_get_resource(ZebraHandle zh,
436 const char *name, const char *defaultvalue);
440 void zebra_pidfname(ZebraService zs, char *path);
450 ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh,
452 int num, zint *positions);
456 ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
458 zint start, int num);
461 void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records,
465 struct BFiles_struct *zebra_get_bfs(ZebraHandle zh);
468 ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids);
474 * \section intro_sec Introduction
476 * Zebra is a search engine for structure data, such as XML, MARC
477 * and others. The following chapters briefly describe each of
478 * Zebra major modules/components.
480 * \section util Base Utilities
482 * The Zebra utilities (util.h) defines fundamental types and a few
483 * utilites for Zebra.
485 * \section res Resources
487 * The resources system (res.h) is a manager of configuration
488 * resources. The resources can be viewed as a simple database.
489 * Resources can be read from a configurtion file, they can be
490 * read or written by an application. Resources can also be written,
491 * but that facility is not currently in use.
493 * \section bfile Bfiles
495 * The Bfiles (bfile.h) provides a portable interface to the
496 * local file system. It also provides a facility for safe updates
497 * (shadow updates). All file system access is handle by this module
498 * (except for trival reads of configuration files).
500 * \section dict Dictionary
502 * The Zebra dictionary (dict.h) maps a search term (key) to a value. The
503 * value is a reference to the list of records identifers in which
504 * the term occurs. Zebra uses an ISAM data structure for the list
505 * of term occurrences. The Dictionary uses \ref bfile.
509 * Zebra maintains an ISAM for each term where each ISAM is a list
510 * of record identifiers corresponding to the records in which the
511 * term occur. Unlike traditional ISAM systems, the Zebra ISAM
512 * is compressed. The ISAM system uses \ref bfile.
514 * Zebra has more than one ISAM system. The old and stable ISAM system
515 * is named isamc (see isamc.h). Another version isams is a write-once
516 * isam system that is quite compact - suitable for CD-ROMs (isams.h).
517 * The newest ISAM system, isamb, is implemented as a B-Tree (see isamb.h).
519 * \section data1 Data-1
521 * The data1 (data1.h) module deals with structured documents. The module can
522 * can read, modify and write documents. The document structure was
523 * originally based on GRS-1 - a Z39.50 v3 structure that predates
524 * DOM. These days the data1 structure may describe XML/SGML as well.
525 * The data1, like DOM, is a tree structure. Each node in the tree
526 * can be of type element, text (cdata), preprocessing instruction,
527 * comment. Element nodes can point to attribute nodes.
529 * \section recctrl Record Control
531 * The record control module (recctrl.h) is responsible for
532 * managing the various record types ("classes" or filters).
534 * \section rset Result-Set
536 * The Result-Set module (rset.h) defines an interface that all
537 * Zebra Search Results must implement. Each operation (AND, OR, ..)
538 * correspond to an implementation of that interface.
542 * DFA (dfa.h) Deterministic Finite Automa is a regular expression engine.
543 * The module compiles a regular expression to a DFA. The DFA can then
544 * be used in various application to perform fast match against the
545 * origianl expression. The \ref Dict uses DFA to perform lookup
546 * using regular expressions.