1 /* $Id: api.h,v 1.32 2006-03-31 15:58:03 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>
43 expand GCC_ATTRIBUTE if GCC is in use. See :
44 http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
49 #define GCC_ATTRIBUTE(x) __attribute__ (x)
51 #define GCC_ATTRIBUTE(x)
62 } ZebraTransactionStatus;
64 /** Retrieval Record Descriptor */
66 int errCode; /* non-zero if error when fetching this */
67 char *errString; /* error string */
68 int position; /* position of record in result set (1,2,..) */
69 char *buf; /* record buffer (void pointer really) */
71 oid_value format; /* record syntax */
75 } ZebraRetrievalRecord;
77 /** Scan Term Descriptor */
79 int occurrences; /* scan term occurrences */
80 char *term; /* scan term string */
84 \brief a Zebra Handle - (session)
86 typedef struct zebra_session *ZebraHandle;
89 \brief a Zebra Service handle
91 typedef struct zebra_service *ZebraService;
93 /** \fn ZebraService zebra_start(const char *configName)
94 \brief starts a Zebra service.
95 \param configName name of configuration file
97 This function is a simplified version of zebra_start_res.
100 ZebraService zebra_start(const char *configName
101 ) GCC_ATTRIBUTE((warn_unused_result));
103 /** \fn ZebraService zebra_start_res(const char *configName, \
104 Res def_res, Res over_res)
105 \brief starts a Zebra service with resources.
106 \param configName name of configuration file
107 \param def_res default resources
108 \param over_res overriding resources
110 This function typically called once in a program. A Zebra Service
111 acts as a factory for Zebra session handles.
114 ZebraService zebra_start_res(const char *configName,
115 Res def_res, Res over_res
116 ) GCC_ATTRIBUTE((warn_unused_result));
119 \brief stops a Zebra service.
120 \param zs service handle
122 Frees resources used by the service.
125 ZEBRA_RES zebra_stop(ZebraService zs);
128 \brief Lists enabled Zebra filters
129 \param zs service handle
130 \param cd callback parameter (opaque)
131 \param cb callback function
134 void zebra_filter_info(ZebraService zs, void *cd,
135 void (*cb)(void *cd, const char *name));
139 \brief Creates a Zebra session handle within service.
140 \param zs service handle.
142 There should be one handle for each thread doing something
143 with zebra, be that searching or indexing. In simple apps
144 one handle is sufficient
147 ZebraHandle zebra_open(ZebraService zs, Res res
148 ) GCC_ATTRIBUTE((warn_unused_result));
151 \brief Destroys Zebra session handle.
152 \param zh zebra session handle.
155 ZEBRA_RES zebra_close(ZebraHandle zh);
158 \brief Returns error code for last error
159 \param zh zebra session handle.
162 int zebra_errCode(ZebraHandle zh);
165 \brief Returns error string for last error
166 \param zh zebra session handle.
169 const char *zebra_errString(ZebraHandle zh);
172 \brief Returns additional info for last error
173 \param zh zebra session handle.
176 char *zebra_errAdd(ZebraHandle zh);
179 \brief Returns error code and additional info for last error
180 \param zh zebra session handle.
181 \param code pointer to returned error code
182 \param addinfo pointer to returned additional info
185 void zebra_result(ZebraHandle zh, int *code, char **addinfo);
188 \brief Set limit before Zebra does approx hit count
189 \param zh session handle
190 \param approx_limit the limit
192 Results will be approximiate if hit count is greater than the
193 limit specified. By default there is a high-limit (no limit).
195 ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit);
198 \brief Search using PQF Query
199 \param zh session handle
200 \param pqf_query query
201 \param setname name of resultset
202 \param hits of hits is returned
205 ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
206 const char *setname, zint *hits);
208 /** \fn ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query, \
209 const char *setname, zint *hits)
210 \brief Search using RPN Query
211 \param zh session handle
213 \param query RPN query using YAZ structure
214 \param setname name of resultset
215 \param hits number of hits is returned
218 ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
219 const char *setname, zint *hits);
222 \fn ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream, \
223 const char *setname, Z_RecordComposition *comp, \
224 oid_value input_format, int num_recs, \
225 ZebraRetrievalRecord *recs)
226 \brief Retrieve records from result set (after search)
227 \param zh session handle
228 \param stream allocate records returned using this ODR
229 \param setname name of result set to retrieve records from
230 \param comp Z39.50 record composition
231 \param input_format transfer syntax (OID)
232 \param num_recs number of records to retrieve
233 \param recs store records in this structure (size is num_recs)
236 ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
238 Z_RecordComposition *comp,
239 oid_value input_format,
241 ZebraRetrievalRecord *recs);
243 \brief Deletes one or more resultsets
244 \param zh session handle
245 \param function Z_DeleteResultSetRequest_{list,all}
246 \param num_setnames number of result sets
247 \param setnames result set names
248 \param statuses status result
251 int zebra_deleteResultSet(ZebraHandle zh, int function,
252 int num_setnames, char **setnames,
257 \brief returns number of term info terms assocaited with result set
258 \param zh session handle
259 \param setname result set name
260 \param num_terms number of terms returned in this integer
262 This function is used in conjunction with zebra_result_set_term_info.
263 If operation was successful, ZEBRA_OK is returned; otherwise
264 ZEBRA_FAIL is returned (typically non-existing setname)
267 ZEBRA_RES zebra_result_set_term_no(ZebraHandle zh, const char *setname,
271 \brief returns information about a term assocated with a result set
272 \param zh session handle
273 \param setname result set name
274 \param no the term we want to know about (0=first, 1=second,..)
275 \param count the number of occurrences of this term, aka hits (output)
276 \param approx about hits: 0=exact,1=approx (output)
277 \param termbuf buffer for term string (intput, output)
278 \param termlen size of termbuf (input=max, output=actual length)
279 \param term_ref_id if non-NULL *term_ref_id holds term reference
281 Returns information about one search term associated with result set.
282 Use zebra_result_set_term_no to read total number of terms associated
283 with result set. If this function can not return information,
284 due to no out of range or bad result set name, ZEBRA_FAIL is
286 The passed termbuf must be able to hold at least *termlen characters.
287 Upon completion, *termlen holds actual length of search term.
290 ZEBRA_RES zebra_result_set_term_info(ZebraHandle zh, const char *setname,
291 int no, zint *count, int *approx,
292 char *termbuf, size_t *termlen,
293 const char **term_ref_id);
297 \brief performs Scan (Z39.50 style)
298 \param zh session handle
299 \param stream ODR handle for result
300 \param zapt Attribute plus Term (start term)
301 \param attributeset Attributeset for Attribute plus Term
302 \param position input/output position
303 \param num_entries number of terms requested / returned
304 \param entries list of resulting terms (ODR allocated)
305 \param is_partial upon return 1=partial, 0=complete
306 \param setname limit scan by this set (NULL means no limit)
308 YAZ_EXPORT ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
309 Z_AttributesPlusTerm *zapt,
310 oid_value attributeset,
311 int *position, int *num_entries,
312 ZebraScanEntry **entries,
314 const char *setname);
317 \brief performs Scan (taking PQF string)
318 \param zh session handle
319 \param stream ODR handle for result
320 \param query PQF scan query
321 \param position input/output position
322 \param num_entries number of terms requested / returned
323 \param entries list of resulting terms (ODR allocated)
324 \param is_partial upon return 1=partial, 0=complete
325 \param setname limit scan by this set (NULL means no limit)
328 ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
329 int *position, int *num_entries, ZebraScanEntry **entries,
330 int *is_partial, const char *setname);
333 \brief authenticate user. Returns 0 if OK, != 0 on failure
334 \param zh session handle
335 \param user user name
339 ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass);
342 \brief Normalize zebra term for register (subject to change!)
343 \param zh session handle
344 \param reg_id register ID, 'w', 'p',..
345 \param input_str input string buffer
346 \param input_len input string length
347 \param output_str output string buffer
348 \param output_len output string length
351 int zebra_string_norm(ZebraHandle zh, unsigned reg_id, const char *input_str,
352 int input_len, char *output_str, int output_len);
355 \brief Creates a database
356 \param zh session handle
357 \param db database to be created
360 ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db);
363 \brief Deletes a database (drop)
364 \param zh session handle
365 \param db database to be deleted
368 ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db);
371 ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh);
374 ZEBRA_RES zebra_admin_start(ZebraHandle zh);
377 ZEBRA_RES zebra_shutdown(ZebraService zs);
380 ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
381 const char *record_type);
384 ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
388 ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
391 ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
394 const char *recid_buf, size_t recid_len,
398 ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw
399 ) GCC_ATTRIBUTE((warn_unused_result));
402 ZEBRA_RES zebra_end_trans(ZebraHandle zh
403 ) GCC_ATTRIBUTE((warn_unused_result));
406 ZEBRA_RES zebra_end_transaction(ZebraHandle zh,
407 ZebraTransactionStatus *stat);
410 ZEBRA_RES zebra_commit(ZebraHandle zh);
413 ZEBRA_RES zebra_clean(ZebraHandle zh);
416 ZEBRA_RES zebra_init(ZebraHandle zh);
419 ZEBRA_RES zebra_compact(ZebraHandle zh);
421 YAZ_EXPORT int zebra_repository_update(ZebraHandle zh, const char *path);
422 YAZ_EXPORT int zebra_repository_delete(ZebraHandle zh, const char *path);
423 YAZ_EXPORT int zebra_repository_show(ZebraHandle zh, const char *path);
425 YAZ_EXPORT int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
428 ZEBRA_RES zebra_insert_record(ZebraHandle zh,
429 const char *recordType,
430 SYSNO *sysno, const char *match,
432 const char *buf, int buf_size,
435 ZEBRA_RES zebra_update_record(ZebraHandle zh,
436 const char *recordType,
437 SYSNO *sysno, const char *match,
439 const char *buf, int buf_size,
442 ZEBRA_RES zebra_delete_record(ZebraHandle zh,
443 const char *recordType,
444 SYSNO *sysno, const char *match, const char *fname,
445 const char *buf, int buf_size,
449 ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
450 int num_input_setnames,
451 const char **input_setnames,
452 const char *output_setname,
453 Z_SortKeySpecList *sort_sequence,
455 ) GCC_ATTRIBUTE((warn_unused_result));
458 ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
459 const char **basenames
460 ) GCC_ATTRIBUTE((warn_unused_result));
463 ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename
464 ) GCC_ATTRIBUTE((warn_unused_result));
467 void zebra_shadow_enable(ZebraHandle zh, int value);
470 int zebra_register_statistics(ZebraHandle zh, int dumpdict);
473 ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding);
476 ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
480 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
482 const char *zebra_get_resource(ZebraHandle zh,
483 const char *name, const char *defaultvalue);
487 void zebra_pidfname(ZebraService zs, char *path);
497 ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh,
499 int num, zint *positions);
503 ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
505 zint start, int num);
508 void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records,
512 struct BFiles_struct *zebra_get_bfs(ZebraHandle zh);
515 ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids);
521 * \section intro_sec Introduction
523 * Zebra is a search engine for structure data, such as XML, MARC
526 * API users should read the api.h for all the public definitions.
528 * The remaining sections briefly describe each of
529 * Zebra major modules/components.
531 * \section util Base Utilities
533 * The Zebra utilities (util.h) defines fundamental types and a few
534 * utilites for Zebra.
536 * \section res Resources
538 * The resources system (res.h) is a manager of configuration
539 * resources. The resources can be viewed as a simple database.
540 * Resources can be read from a configurtion file, they can be
541 * read or written by an application. Resources can also be written,
542 * but that facility is not currently in use.
544 * \section bfile Bfiles
546 * The Bfiles (bfile.h) provides a portable interface to the
547 * local file system. It also provides a facility for safe updates
548 * (shadow updates). All file system access is handle by this module
549 * (except for trival reads of configuration files).
551 * \section dict Dictionary
553 * The Zebra dictionary (dict.h) maps a search term (key) to a value. The
554 * value is a reference to the list of records identifers in which
555 * the term occurs. Zebra uses an ISAM data structure for the list
556 * of term occurrences. The Dictionary uses \ref bfile.
560 * Zebra maintains an ISAM for each term where each ISAM is a list
561 * of record identifiers corresponding to the records in which the
562 * term occur. Unlike traditional ISAM systems, the Zebra ISAM
563 * is compressed. The ISAM system uses \ref bfile.
565 * Zebra has more than one ISAM system. The old and stable ISAM system
566 * is named isamc (see isamc.h). Another version isams is a write-once
567 * isam system that is quite compact - suitable for CD-ROMs (isams.h).
568 * The newest ISAM system, isamb, is implemented as a B-Tree (see isamb.h).
570 * \section data1 Data-1
572 * The data1 (data1.h) module deals with structured documents. The module can
573 * can read, modify and write documents. The document structure was
574 * originally based on GRS-1 - a Z39.50 v3 structure that predates
575 * DOM. These days the data1 structure may describe XML/SGML as well.
576 * The data1, like DOM, is a tree structure. Each node in the tree
577 * can be of type element, text (cdata), preprocessing instruction,
578 * comment. Element nodes can point to attribute nodes.
580 * \section recctrl Record Control
582 * The record control module (recctrl.h) is responsible for
583 * managing the various record types ("classes" or filters).
585 * \section rset Result-Set
587 * The Result-Set module (rset.h) defines an interface that all
588 * Zebra Search Results must implement. Each operation (AND, OR, ..)
589 * correspond to an implementation of that interface.
593 * DFA (dfa.h) Deterministic Finite Automa is a regular expression engine.
594 * The module compiles a regular expression to a DFA. The DFA can then
595 * be used in various application to perform fast match against the
596 * origianl expression. The \ref Dict uses DFA to perform lookup
597 * using regular expressions.