1 /* $Id: api.h,v 1.30 2005-09-13 11:51:05 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);
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);
113 \brief Lists enabled Zebra filters
114 \param zs service handle
115 \param cd callback parameter (opaque)
116 \param cb callback function
119 void zebra_filter_info(ZebraService zs, void *cd,
120 void (*cb)(void *cd, const char *name));
124 \brief Creates a Zebra session handle within service.
125 \param zs service handle.
127 There should be one handle for each thread doing something
128 with zebra, be that searching or indexing. In simple apps
129 one handle is sufficient
132 ZebraHandle zebra_open(ZebraService zs, Res res);
135 \brief Destroys Zebra session handle.
136 \param zh zebra session handle.
139 ZEBRA_RES zebra_close(ZebraHandle zh);
142 \brief Returns error code for last error
143 \param zh zebra session handle.
146 int zebra_errCode(ZebraHandle zh);
149 \brief Returns error string for last error
150 \param zh zebra session handle.
153 const char *zebra_errString(ZebraHandle zh);
156 \brief Returns additional info for last error
157 \param zh zebra session handle.
160 char *zebra_errAdd(ZebraHandle zh);
163 \brief Returns error code and additional info for last error
164 \param zh zebra session handle.
165 \param code pointer to returned error code
166 \param addinfo pointer to returned additional info
169 void zebra_result(ZebraHandle zh, int *code, char **addinfo);
172 \brief Clears last error.
173 \param zh zebra session handle.
176 void zebra_clearError(ZebraHandle zh);
180 \brief Set limit before Zebra does approx hit count
181 \param zh session handle
182 \param approx_limit the limit
184 Results will be approximiate if hit count is greater than the
185 limit specified. By default there is a high-limit (no limit).
187 ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit);
190 \brief Search using PQF Query
191 \param zh session handle
192 \param pqf_query query
193 \param setname name of resultset
194 \param hits of hits is returned
197 ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
198 const char *setname, zint *hits);
200 /** \fn ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query, \
201 const char *setname, zint *hits)
202 \brief Search using RPN Query
203 \param zh session handle
205 \param query RPN query using YAZ structure
206 \param setname name of resultset
207 \param hits number of hits is returned
210 ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
211 const char *setname, zint *hits);
214 \fn ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream, \
215 const char *setname, Z_RecordComposition *comp, \
216 oid_value input_format, int num_recs, \
217 ZebraRetrievalRecord *recs)
218 \brief Retrieve records from result set (after search)
219 \param zh session handle
220 \param stream allocate records returned using this ODR
221 \param setname name of result set to retrieve records from
222 \param comp Z39.50 record composition
223 \param input_format transfer syntax (OID)
224 \param num_recs number of records to retrieve
225 \param recs store records in this structure (size is num_recs)
228 ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
230 Z_RecordComposition *comp,
231 oid_value input_format,
233 ZebraRetrievalRecord *recs);
235 \brief Deletes one or more resultsets
236 \param zh session handle
237 \param function Z_DeleteResultSetRequest_{list,all}
238 \param num_setnames number of result sets
239 \param setnames result set names
240 \param statuses status result
243 int zebra_deleteResultSet(ZebraHandle zh, int function,
244 int num_setnames, char **setnames,
249 \brief returns number of term info terms assocaited with result set
250 \param zh session handle
251 \param setname result set name
252 \param num_terms number of terms returned in this integer
254 This function is used in conjunction with zebra_result_set_term_info.
255 If operation was successful, ZEBRA_OK is returned; otherwise
256 ZEBRA_FAIL is returned (typically non-existing setname)
259 ZEBRA_RES zebra_result_set_term_no(ZebraHandle zh, const char *setname,
263 \brief returns information about a term assocated with a result set
264 \param zh session handle
265 \param setname result set name
266 \param no the term we want to know about (0=first, 1=second,..)
267 \param count the number of occurrences of this term, aka hits (output)
268 \param approx about hits: 0=exact,1=approx (output)
269 \param termbuf buffer for term string (intput, output)
270 \param termlen size of termbuf (input=max, output=actual length)
271 \param term_ref_id if non-NULL *term_ref_id holds term reference
273 Returns information about one search term associated with result set.
274 Use zebra_result_set_term_no to read total number of terms associated
275 with result set. If this function can not return information,
276 due to no out of range or bad result set name, ZEBRA_FAIL is
278 The passed termbuf must be able to hold at least *termlen characters.
279 Upon completion, *termlen holds actual length of search term.
282 ZEBRA_RES zebra_result_set_term_info(ZebraHandle zh, const char *setname,
283 int no, zint *count, int *approx,
284 char *termbuf, size_t *termlen,
285 const char **term_ref_id);
289 \brief performs Scan (Z39.50 style)
290 \param zh session handle
291 \param stream ODR handle for result
292 \param zapt Attribute plus Term (start term)
293 \param attributeset Attributeset for Attribute plus Term
294 \param position input/output position
295 \param num_entries number of terms requested / returned
296 \param entries list of resulting terms (ODR allocated)
297 \param is_partial upon return 1=partial, 0=complete
298 \param setname limit scan by this set (NULL means no limit)
300 YAZ_EXPORT ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
301 Z_AttributesPlusTerm *zapt,
302 oid_value attributeset,
303 int *position, int *num_entries,
304 ZebraScanEntry **entries,
306 const char *setname);
309 \brief performs Scan (taking PQF string)
310 \param zh session handle
311 \param stream ODR handle for result
312 \param query PQF scan query
313 \param position input/output position
314 \param num_entries number of terms requested / returned
315 \param entries list of resulting terms (ODR allocated)
316 \param is_partial upon return 1=partial, 0=complete
317 \param setname limit scan by this set (NULL means no limit)
320 ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
321 int *position, int *num_entries, ZebraScanEntry **entries,
322 int *is_partial, const char *setname);
325 \brief authenticate user. Returns 0 if OK, != 0 on failure
326 \param zh session handle
327 \param user user name
331 ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass);
334 \brief Normalize zebra term for register (subject to change!)
335 \param zh session handle
336 \param reg_id register ID, 'w', 'p',..
337 \param input_str input string buffer
338 \param input_len input string length
339 \param output_str output string buffer
340 \param output_len output string length
343 int zebra_string_norm(ZebraHandle zh, unsigned reg_id, const char *input_str,
344 int input_len, char *output_str, int output_len);
347 \brief Creates a database
348 \param zh session handle
349 \param db database to be created
352 ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db);
355 \brief Deletes a database (drop)
356 \param zh session handle
357 \param db database to be deleted
360 ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db);
363 ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh);
366 ZEBRA_RES zebra_admin_start(ZebraHandle zh);
369 ZEBRA_RES zebra_shutdown(ZebraService zs);
372 ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
373 const char *record_type);
376 ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
380 ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
383 ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
386 const char *recid_buf, size_t recid_len,
390 ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw);
393 ZEBRA_RES zebra_end_trans(ZebraHandle zh);
396 ZEBRA_RES zebra_end_transaction(ZebraHandle zh,
397 ZebraTransactionStatus *stat);
400 ZEBRA_RES zebra_commit(ZebraHandle zh);
403 ZEBRA_RES zebra_clean(ZebraHandle zh);
406 ZEBRA_RES zebra_init(ZebraHandle zh);
409 ZEBRA_RES zebra_compact(ZebraHandle zh);
411 YAZ_EXPORT int zebra_repository_update(ZebraHandle zh, const char *path);
412 YAZ_EXPORT int zebra_repository_delete(ZebraHandle zh, const char *path);
413 YAZ_EXPORT int zebra_repository_show(ZebraHandle zh, const char *path);
415 YAZ_EXPORT int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
418 ZEBRA_RES zebra_insert_record(ZebraHandle zh,
419 const char *recordType,
420 SYSNO *sysno, const char *match,
422 const char *buf, int buf_size,
425 ZEBRA_RES zebra_update_record(ZebraHandle zh,
426 const char *recordType,
427 SYSNO *sysno, const char *match,
429 const char *buf, int buf_size,
432 ZEBRA_RES zebra_delete_record(ZebraHandle zh,
433 const char *recordType,
434 SYSNO *sysno, const char *match, const char *fname,
435 const char *buf, int buf_size,
439 ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
440 int num_input_setnames,
441 const char **input_setnames,
442 const char *output_setname,
443 Z_SortKeySpecList *sort_sequence,
447 ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
448 const char **basenames);
451 ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename);
454 void zebra_shadow_enable(ZebraHandle zh, int value);
457 int zebra_register_statistics(ZebraHandle zh, int dumpdict);
460 ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding);
463 ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
467 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
469 const char *zebra_get_resource(ZebraHandle zh,
470 const char *name, const char *defaultvalue);
474 void zebra_pidfname(ZebraService zs, char *path);
484 ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh,
486 int num, zint *positions);
490 ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
492 zint start, int num);
495 void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records,
499 struct BFiles_struct *zebra_get_bfs(ZebraHandle zh);
502 ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids);
508 * \section intro_sec Introduction
510 * Zebra is a search engine for structure data, such as XML, MARC
513 * API users should read the api.h for all the public definitions.
515 * The remaining sections briefly describe each of
516 * Zebra major modules/components.
518 * \section util Base Utilities
520 * The Zebra utilities (util.h) defines fundamental types and a few
521 * utilites for Zebra.
523 * \section res Resources
525 * The resources system (res.h) is a manager of configuration
526 * resources. The resources can be viewed as a simple database.
527 * Resources can be read from a configurtion file, they can be
528 * read or written by an application. Resources can also be written,
529 * but that facility is not currently in use.
531 * \section bfile Bfiles
533 * The Bfiles (bfile.h) provides a portable interface to the
534 * local file system. It also provides a facility for safe updates
535 * (shadow updates). All file system access is handle by this module
536 * (except for trival reads of configuration files).
538 * \section dict Dictionary
540 * The Zebra dictionary (dict.h) maps a search term (key) to a value. The
541 * value is a reference to the list of records identifers in which
542 * the term occurs. Zebra uses an ISAM data structure for the list
543 * of term occurrences. The Dictionary uses \ref bfile.
547 * Zebra maintains an ISAM for each term where each ISAM is a list
548 * of record identifiers corresponding to the records in which the
549 * term occur. Unlike traditional ISAM systems, the Zebra ISAM
550 * is compressed. The ISAM system uses \ref bfile.
552 * Zebra has more than one ISAM system. The old and stable ISAM system
553 * is named isamc (see isamc.h). Another version isams is a write-once
554 * isam system that is quite compact - suitable for CD-ROMs (isams.h).
555 * The newest ISAM system, isamb, is implemented as a B-Tree (see isamb.h).
557 * \section data1 Data-1
559 * The data1 (data1.h) module deals with structured documents. The module can
560 * can read, modify and write documents. The document structure was
561 * originally based on GRS-1 - a Z39.50 v3 structure that predates
562 * DOM. These days the data1 structure may describe XML/SGML as well.
563 * The data1, like DOM, is a tree structure. Each node in the tree
564 * can be of type element, text (cdata), preprocessing instruction,
565 * comment. Element nodes can point to attribute nodes.
567 * \section recctrl Record Control
569 * The record control module (recctrl.h) is responsible for
570 * managing the various record types ("classes" or filters).
572 * \section rset Result-Set
574 * The Result-Set module (rset.h) defines an interface that all
575 * Zebra Search Results must implement. Each operation (AND, OR, ..)
576 * correspond to an implementation of that interface.
580 * DFA (dfa.h) Deterministic Finite Automa is a regular expression engine.
581 * The module compiles a regular expression to a DFA. The DFA can then
582 * be used in various application to perform fast match against the
583 * origianl expression. The \ref Dict uses DFA to perform lookup
584 * using regular expressions.