1 /* $Id: api.h,v 1.34 2006-05-10 08:13:19 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 has return type 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 /** \brief Creates a Zebra Service.
94 \param configName name of configuration file
96 This function is a simplified version of zebra_start_res.
99 ZebraService zebra_start(const char *configName
100 ) GCC_ATTRIBUTE((warn_unused_result));
102 /** \brief Creates a Zebra service with resources.
103 \param configName name of configuration file
104 \param def_res default resources
105 \param over_res overriding resources
107 This function typically called once in a program. A Zebra Service
108 acts as a factory for Zebra session handles.
111 ZebraService zebra_start_res(const char *configName,
112 Res def_res, Res over_res
113 ) GCC_ATTRIBUTE((warn_unused_result));
115 /** \brief stops a Zebra service.
116 \param zs service handle
118 Frees resources used by the service.
121 ZEBRA_RES zebra_stop(ZebraService zs);
123 /** \brief Lists enabled Zebra filters
124 \param zs service handle
125 \param cd callback parameter (opaque)
126 \param cb callback function
129 void zebra_filter_info(ZebraService zs, void *cd,
130 void (*cb)(void *cd, const char *name));
133 /** \brief Creates a Zebra session handle within service.
134 \param zs service handle.
135 \param res resources to be used for the service (NULL for none)
137 There should be one handle for each thread doing something
138 with zebra, be that searching or indexing. In simple apps
139 one handle is sufficient
142 ZebraHandle zebra_open(ZebraService zs, Res res
143 ) GCC_ATTRIBUTE((warn_unused_result));
145 /** \brief Destroys Zebra session handle.
146 \param zh zebra session handle.
149 ZEBRA_RES zebra_close(ZebraHandle zh);
151 /** \brief Returns error code for last error
152 \param zh zebra session handle.
155 int zebra_errCode(ZebraHandle zh);
157 /** \brief Returns error string for last error
158 \param zh zebra session handle.
161 const char *zebra_errString(ZebraHandle zh);
163 /** \brief Returns additional info for last error
164 \param zh zebra session handle.
167 char *zebra_errAdd(ZebraHandle zh);
169 /** \brief Returns error code and additional info for last error
170 \param zh zebra session handle.
171 \param code pointer to returned error code
172 \param addinfo pointer to returned additional info
175 void zebra_result(ZebraHandle zh, int *code, char **addinfo);
177 /** \brief Set limit before Zebra does approx hit count
178 \param zh session handle
179 \param approx_limit the limit
181 Results will be approximiate if hit count is greater than the
182 limit specified. By default there is a high-limit (no limit).
184 ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit);
186 /** \brief Search using PQF Query String
187 \param zh session handle
188 \param pqf_query query
189 \param setname name of resultset
190 \param hits of hits is returned
193 ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
194 const char *setname, zint *hits);
196 /** \brief Search using RPN Query structure (from ASN.1)
197 \param zh session handle
199 \param query RPN query using YAZ structure
200 \param setname name of resultset
201 \param hits number of hits is returned
204 ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
205 const char *setname, zint *hits);
207 /** \brief Retrieve records from result set (after search)
208 \param zh session handle
209 \param stream allocate records returned using this ODR
210 \param setname name of result set to retrieve records from
211 \param comp Z39.50 record composition
212 \param input_format transfer syntax (OID)
213 \param num_recs number of records to retrieve
214 \param recs store records in this structure (size is num_recs)
217 ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
219 Z_RecordComposition *comp,
220 oid_value input_format,
222 ZebraRetrievalRecord *recs);
223 /** \brief Deletes one or more resultsets
224 \param zh session handle
225 \param function Z_DeleteResultSetRequest_{list,all}
226 \param num_setnames number of result sets
227 \param setnames result set names
228 \param statuses status result
231 int zebra_deleteResultSet(ZebraHandle zh, int function,
232 int num_setnames, char **setnames,
236 /** \brief returns number of term info terms assocaited with result set
237 \param zh session handle
238 \param setname result set name
239 \param num_terms number of terms returned in this integer
241 This function is used in conjunction with zebra_result_set_term_info.
242 If operation was successful, ZEBRA_OK is returned; otherwise
243 ZEBRA_FAIL is returned (typically non-existing setname)
246 ZEBRA_RES zebra_result_set_term_no(ZebraHandle zh, const char *setname,
249 /** \brief returns information about a term assocated with a result set
250 \param zh session handle
251 \param setname result set name
252 \param no the term we want to know about (0=first, 1=second,..)
253 \param count the number of occurrences of this term, aka hits (output)
254 \param approx about hits: 0=exact,1=approx (output)
255 \param termbuf buffer for term string (intput, output)
256 \param termlen size of termbuf (input=max, output=actual length)
257 \param term_ref_id if non-NULL *term_ref_id holds term reference
259 Returns information about one search term associated with result set.
260 Use zebra_result_set_term_no to read total number of terms associated
261 with result set. If this function can not return information,
262 due to no out of range or bad result set name, ZEBRA_FAIL is
264 The passed termbuf must be able to hold at least *termlen characters.
265 Upon completion, *termlen holds actual length of search term.
268 ZEBRA_RES zebra_result_set_term_info(ZebraHandle zh, const char *setname,
269 int no, zint *count, int *approx,
270 char *termbuf, size_t *termlen,
271 const char **term_ref_id);
274 /** \brief performs Scan (Z39.50 style)
275 \param zh session handle
276 \param stream ODR handle for result
277 \param zapt Attribute plus Term (start term)
278 \param attributeset Attributeset for Attribute plus Term
279 \param position input/output position
280 \param num_entries number of terms requested / returned
281 \param entries list of resulting terms (ODR allocated)
282 \param is_partial upon return 1=partial, 0=complete
283 \param setname limit scan by this set (NULL means no limit)
285 YAZ_EXPORT ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
286 Z_AttributesPlusTerm *zapt,
287 oid_value attributeset,
288 int *position, int *num_entries,
289 ZebraScanEntry **entries,
291 const char *setname);
293 /** \brief performs Scan (taking PQF string)
294 \param zh session handle
295 \param stream ODR handle for result
296 \param query PQF scan query
297 \param position input/output position
298 \param num_entries number of terms requested / returned
299 \param entries list of resulting terms (ODR allocated)
300 \param is_partial upon return 1=partial, 0=complete
301 \param setname limit scan by this set (NULL means no limit)
304 ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
305 int *position, int *num_entries,
306 ZebraScanEntry **entries,
307 int *is_partial, const char *setname);
309 /** \brief authenticate user. Returns 0 if OK, != 0 on failure
310 \param zh session handle
311 \param user user name
315 ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass);
317 /** \brief Normalize zebra term for register (subject to change!)
318 \param zh session handle
319 \param reg_id register ID, 'w', 'p',..
320 \param input_str input string buffer
321 \param input_len input string length
322 \param output_str output string buffer
323 \param output_len output string length
326 int zebra_string_norm(ZebraHandle zh, unsigned reg_id, const char *input_str,
327 int input_len, char *output_str, int output_len);
329 /** \brief Creates a database
330 \param zh session handle
331 \param db database to be created
334 ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db);
336 /** \brief Deletes a database (drop)
337 \param zh session handle
338 \param db database to be deleted
341 ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db);
344 ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh);
347 ZEBRA_RES zebra_admin_start(ZebraHandle zh);
350 ZEBRA_RES zebra_shutdown(ZebraService zs);
353 ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
354 const char *record_type);
357 ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
361 ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
364 ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
367 const char *recid_buf, size_t recid_len,
371 ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw
372 ) GCC_ATTRIBUTE((warn_unused_result));
375 ZEBRA_RES zebra_end_trans(ZebraHandle zh
376 ) GCC_ATTRIBUTE((warn_unused_result));
379 ZEBRA_RES zebra_end_transaction(ZebraHandle zh,
380 ZebraTransactionStatus *stat);
383 ZEBRA_RES zebra_commit(ZebraHandle zh);
386 ZEBRA_RES zebra_clean(ZebraHandle zh);
389 ZEBRA_RES zebra_init(ZebraHandle zh);
392 ZEBRA_RES zebra_compact(ZebraHandle zh);
394 YAZ_EXPORT int zebra_repository_update(ZebraHandle zh, const char *path);
395 YAZ_EXPORT int zebra_repository_delete(ZebraHandle zh, const char *path);
396 YAZ_EXPORT int zebra_repository_show(ZebraHandle zh, const char *path);
398 YAZ_EXPORT int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
401 ZEBRA_RES zebra_insert_record(ZebraHandle zh,
402 const char *recordType,
403 SYSNO *sysno, const char *match,
405 const char *buf, int buf_size,
408 ZEBRA_RES zebra_update_record(ZebraHandle zh,
409 const char *recordType,
410 SYSNO *sysno, const char *match,
412 const char *buf, int buf_size,
415 ZEBRA_RES zebra_delete_record(ZebraHandle zh,
416 const char *recordType,
417 SYSNO *sysno, const char *match, const char *fname,
418 const char *buf, int buf_size,
422 ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
423 int num_input_setnames,
424 const char **input_setnames,
425 const char *output_setname,
426 Z_SortKeySpecList *sort_sequence,
428 ) GCC_ATTRIBUTE((warn_unused_result));
431 ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
432 const char **basenames
433 ) GCC_ATTRIBUTE((warn_unused_result));
436 ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename
437 ) GCC_ATTRIBUTE((warn_unused_result));
440 void zebra_shadow_enable(ZebraHandle zh, int value);
443 int zebra_register_statistics(ZebraHandle zh, int dumpdict);
446 ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding);
449 ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
453 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
455 const char *zebra_get_resource(ZebraHandle zh,
456 const char *name, const char *defaultvalue);
460 void zebra_pidfname(ZebraService zs, char *path);
470 ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh,
472 int num, zint *positions);
476 ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
478 zint start, int num);
481 void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records,
485 struct BFiles_struct *zebra_get_bfs(ZebraHandle zh);
488 ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids);
494 * \section intro_sec Introduction
496 * Zebra is a search engine for structure data, such as XML, MARC
499 * API users should read the api.h for all the public definitions.
501 * The remaining sections briefly describe each of
502 * Zebra major modules/components.
504 * \section util Base Utilities
506 * The Zebra utilities (util.h) defines fundamental types and a few
507 * utilites for Zebra.
509 * \section res Resources
511 * The resources system (res.h) is a manager of configuration
512 * resources. The resources can be viewed as a simple database.
513 * Resources can be read from a configurtion file, they can be
514 * read or written by an application. Resources can also be written,
515 * but that facility is not currently in use.
517 * \section bfile Bfiles
519 * The Bfiles (bfile.h) provides a portable interface to the
520 * local file system. It also provides a facility for safe updates
521 * (shadow updates). All file system access is handle by this module
522 * (except for trival reads of configuration files).
524 * \section dict Dictionary
526 * The Zebra dictionary (dict.h) maps a search term (key) to a value. The
527 * value is a reference to the list of records identifers in which
528 * the term occurs. Zebra uses an ISAM data structure for the list
529 * of term occurrences. The Dictionary uses \ref bfile.
533 * Zebra maintains an ISAM for each term where each ISAM is a list
534 * of record identifiers corresponding to the records in which the
535 * term occur. Unlike traditional ISAM systems, the Zebra ISAM
536 * is compressed. The ISAM system uses \ref bfile.
538 * Zebra has more than one ISAM system. The old and stable ISAM system
539 * is named isamc (see isamc.h). Another version isams is a write-once
540 * isam system that is quite compact - suitable for CD-ROMs (isams.h).
541 * The newest ISAM system, isamb, is implemented as a B-Tree (see isamb.h).
543 * \section data1 Data-1
545 * The data1 (data1.h) module deals with structured documents. The module can
546 * can read, modify and write documents. The document structure was
547 * originally based on GRS-1 - a Z39.50 v3 structure that predates
548 * DOM. These days the data1 structure may describe XML/SGML as well.
549 * The data1, like DOM, is a tree structure. Each node in the tree
550 * can be of type element, text (cdata), preprocessing instruction,
551 * comment. Element nodes can point to attribute nodes.
553 * \section recctrl Record Control
555 * The record control module (recctrl.h) is responsible for
556 * managing the various record types ("classes" or filters).
558 * \section rset Result-Set
560 * The Result-Set module (rset.h) defines an interface that all
561 * Zebra Search Results must implement. Each operation (AND, OR, ..)
562 * correspond to an implementation of that interface.
566 * DFA (dfa.h) Deterministic Finite Automa is a regular expression engine.
567 * The module compiles a regular expression to a DFA. The DFA can then
568 * be used in various application to perform fast match against the
569 * origianl expression. The \ref Dict uses DFA to perform lookup
570 * using regular expressions.
577 * indent-tabs-mode: nil
579 * vim: shiftwidth=4 tabstop=8 expandtab