1 /* $Id: api.h,v 1.41 2006-11-21 22:17:49 adam Exp $
2 Copyright (C) 1995-2006
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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>
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 zint 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 /** \brief Creates a Zebra Service.
81 \param configName name of configuration file
83 This function is a simplified version of zebra_start_res.
86 ZebraService zebra_start(const char *configName
87 ) ZEBRA_GCC_ATTR((warn_unused_result));
89 /** \brief Creates a Zebra service with resources.
90 \param configName name of configuration file
91 \param def_res default resources
92 \param over_res overriding resources
94 This function typically called once in a program. A Zebra Service
95 acts as a factory for Zebra session handles.
98 ZebraService zebra_start_res(const char *configName,
99 Res def_res, Res over_res
100 ) ZEBRA_GCC_ATTR((warn_unused_result));
102 /** \brief stops a Zebra service.
103 \param zs service handle
105 Frees resources used by the service.
108 ZEBRA_RES zebra_stop(ZebraService zs);
110 /** \brief Lists enabled Zebra filters
111 \param zs service handle
112 \param cd callback parameter (opaque)
113 \param cb callback function
116 void zebra_filter_info(ZebraService zs, void *cd,
117 void (*cb)(void *cd, const char *name));
120 /** \brief Creates a Zebra session handle within service.
121 \param zs service handle.
122 \param res resources to be used for the service (NULL for none)
124 There should be one handle for each thread doing something
125 with zebra, be that searching or indexing. In simple apps
126 one handle is sufficient
129 ZebraHandle zebra_open(ZebraService zs, Res res
130 ) ZEBRA_GCC_ATTR((warn_unused_result));
132 /** \brief Destroys Zebra session handle.
133 \param zh zebra session handle.
136 ZEBRA_RES zebra_close(ZebraHandle zh);
138 /** \brief Returns error code for last error
139 \param zh zebra session handle.
142 int zebra_errCode(ZebraHandle zh);
144 /** \brief Returns error string for last error
145 \param zh zebra session handle.
148 const char *zebra_errString(ZebraHandle zh);
150 /** \brief Returns additional info for last error
151 \param zh zebra session handle.
154 char *zebra_errAdd(ZebraHandle zh);
156 /** \brief Returns error code and additional info for last error
157 \param zh zebra session handle.
158 \param code pointer to returned error code
159 \param addinfo pointer to returned additional info
162 void zebra_result(ZebraHandle zh, int *code, char **addinfo);
164 /** \brief Set limit before Zebra does approx hit count
165 \param zh session handle
166 \param approx_limit the limit
168 Results will be approximiate if hit count is greater than the
169 limit specified. By default there is a high-limit (no limit).
171 ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit);
173 /** \brief Search using PQF Query String
174 \param zh session handle
175 \param pqf_query query
176 \param setname name of resultset
177 \param hits of hits is returned
180 ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
181 const char *setname, zint *hits);
183 /** \brief Search using RPN Query structure (from ASN.1)
184 \param zh session handle
186 \param query RPN query using YAZ structure
187 \param setname name of resultset
188 \param hits number of hits is returned
191 ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
192 const char *setname, zint *hits);
194 /** \brief Retrieve records from result set (after search)
195 \param zh session handle
196 \param stream allocate records returned using this ODR
197 \param setname name of result set to retrieve records from
198 \param comp Z39.50 record composition
199 \param input_format transfer syntax (OID)
200 \param num_recs number of records to retrieve
201 \param recs store records in this structure (size is num_recs)
204 ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
206 Z_RecordComposition *comp,
207 oid_value input_format,
209 ZebraRetrievalRecord *recs);
210 /** \brief Deletes one or more resultsets
211 \param zh session handle
212 \param function Z_DeleteResultSetRequest_{list,all}
213 \param num_setnames number of result sets
214 \param setnames result set names
215 \param statuses status result
218 int zebra_deleteResultSet(ZebraHandle zh, int function,
219 int num_setnames, char **setnames,
223 /** \brief returns number of term info terms assocaited with result set
224 \param zh session handle
225 \param setname result set name
226 \param num_terms number of terms returned in this integer
228 This function is used in conjunction with zebra_result_set_term_info.
229 If operation was successful, ZEBRA_OK is returned; otherwise
230 ZEBRA_FAIL is returned (typically non-existing setname)
233 ZEBRA_RES zebra_result_set_term_no(ZebraHandle zh, const char *setname,
236 /** \brief returns information about a term assocated with a result set
237 \param zh session handle
238 \param setname result set name
239 \param no the term we want to know about (0=first, 1=second,..)
240 \param count the number of occurrences of this term, aka hits (output)
241 \param approx about hits: 0=exact,1=approx (output)
242 \param termbuf buffer for term string (intput, output)
243 \param termlen size of termbuf (input=max, output=actual length)
244 \param term_ref_id if non-NULL *term_ref_id holds term reference
246 Returns information about one search term associated with result set.
247 Use zebra_result_set_term_no to read total number of terms associated
248 with result set. If this function can not return information,
249 due to no out of range or bad result set name, ZEBRA_FAIL is
251 The passed termbuf must be able to hold at least *termlen characters.
252 Upon completion, *termlen holds actual length of search term.
255 ZEBRA_RES zebra_result_set_term_info(ZebraHandle zh, const char *setname,
256 int no, zint *count, int *approx,
257 char *termbuf, size_t *termlen,
258 const char **term_ref_id);
261 /** \brief performs Scan (Z39.50 style)
262 \param zh session handle
263 \param stream ODR handle for result
264 \param zapt Attribute plus Term (start term)
265 \param attributeset Attributeset for Attribute plus Term
266 \param position input/output position
267 \param num_entries number of terms requested / returned
268 \param entries list of resulting terms (ODR allocated)
269 \param is_partial upon return 1=partial, 0=complete
270 \param setname limit scan by this set (NULL means no limit)
272 YAZ_EXPORT ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
273 Z_AttributesPlusTerm *zapt,
274 oid_value attributeset,
275 int *position, int *num_entries,
276 ZebraScanEntry **entries,
278 const char *setname);
280 /** \brief performs Scan (taking PQF string)
281 \param zh session handle
282 \param stream ODR handle for result
283 \param query PQF scan query
284 \param position input/output position
285 \param num_entries number of terms requested / returned
286 \param entries list of resulting terms (ODR allocated)
287 \param is_partial upon return 1=partial, 0=complete
288 \param setname limit scan by this set (NULL means no limit)
291 ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
292 int *position, int *num_entries,
293 ZebraScanEntry **entries,
294 int *is_partial, const char *setname);
296 /** \brief authenticate user. Returns 0 if OK, != 0 on failure
297 \param zh session handle
298 \param user user name
302 ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass);
304 /** \brief Normalize zebra term for register (subject to change!)
305 \param zh session handle
306 \param reg_id register ID, 'w', 'p',..
307 \param input_str input string buffer
308 \param input_len input string length
309 \param output_str output string buffer
310 \param output_len output string length
313 int zebra_string_norm(ZebraHandle zh, unsigned reg_id, const char *input_str,
314 int input_len, char *output_str, int output_len);
316 /** \brief Creates a database
317 \param zh session handle
318 \param db database to be created
321 ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db);
323 /** \brief Deletes a database (drop)
324 \param zh session handle
325 \param db database to be deleted
328 ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db);
331 ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh);
334 ZEBRA_RES zebra_admin_start(ZebraHandle zh);
337 ZEBRA_RES zebra_shutdown(ZebraService zs);
340 ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
341 const char *record_type);
344 ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
348 ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
351 ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
354 const char *recid_buf, size_t recid_len,
358 ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw
359 ) ZEBRA_GCC_ATTR((warn_unused_result));
362 ZEBRA_RES zebra_end_trans(ZebraHandle zh
363 ) ZEBRA_GCC_ATTR((warn_unused_result));
366 ZEBRA_RES zebra_end_transaction(ZebraHandle zh,
367 ZebraTransactionStatus *stat);
370 ZEBRA_RES zebra_commit(ZebraHandle zh);
373 ZEBRA_RES zebra_clean(ZebraHandle zh);
376 ZEBRA_RES zebra_init(ZebraHandle zh);
379 ZEBRA_RES zebra_compact(ZebraHandle zh);
382 ZEBRA_RES zebra_repository_update(ZebraHandle zh, const char *path);
385 ZEBRA_RES zebra_repository_delete(ZebraHandle zh, const char *path);
388 ZEBRA_RES zebra_repository_show(ZebraHandle zh, const char *path);
391 ZEBRA_RES zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
394 ZEBRA_RES zebra_insert_record(ZebraHandle zh,
395 const char *recordType,
396 zint *sysno, const char *match,
398 const char *buf, int buf_size,
401 ZEBRA_RES zebra_update_record(ZebraHandle zh,
402 const char *recordType,
403 zint *sysno, const char *match,
405 const char *buf, int buf_size,
408 ZEBRA_RES zebra_delete_record(ZebraHandle zh,
409 const char *recordType,
410 zint *sysno, const char *match,
412 const char *buf, int buf_size,
416 ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
417 int num_input_setnames,
418 const char **input_setnames,
419 const char *output_setname,
420 Z_SortKeySpecList *sort_sequence,
422 ) ZEBRA_GCC_ATTR((warn_unused_result));
425 ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases,
426 const char **basenames
427 ) ZEBRA_GCC_ATTR((warn_unused_result));
430 ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename
431 ) ZEBRA_GCC_ATTR((warn_unused_result));
434 void zebra_shadow_enable(ZebraHandle zh, int value);
437 int zebra_register_statistics(ZebraHandle zh, int dumpdict);
440 ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding);
443 ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
447 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
449 const char *zebra_get_resource(ZebraHandle zh,
450 const char *name, const char *defaultvalue);
454 void zebra_pidfname(ZebraService zs, char *path);
464 ZebraMetaRecord *zebra_meta_records_create(ZebraHandle zh,
466 int num, zint *positions);
470 ZebraMetaRecord *zebra_meta_records_create_range(ZebraHandle zh,
472 zint start, int num);
475 void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records,
479 struct BFiles_struct *zebra_get_bfs(ZebraHandle zh);
482 ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids);
488 * \section intro_sec Introduction
490 * Zebra is a search engine for structure data, such as XML, MARC
493 * API users should read the api.h for all the public definitions.
495 * The remaining sections briefly describe each of
496 * Zebra major modules/components.
498 * \section util Base Utilities
500 * The Zebra utilities (util.h) defines fundamental types and a few
501 * utilites for Zebra.
503 * \section res Resources
505 * The resources system (res.h) is a manager of configuration
506 * resources. The resources can be viewed as a simple database.
507 * Resources can be read from a configurtion file, they can be
508 * read or written by an application. Resources can also be written,
509 * but that facility is not currently in use.
511 * \section bfile Bfiles
513 * The Bfiles (bfile.h) provides a portable interface to the
514 * local file system. It also provides a facility for safe updates
515 * (shadow updates). All file system access is handle by this module
516 * (except for trival reads of configuration files).
518 * \section dict Dictionary
520 * The Zebra dictionary (dict.h) maps a search term (key) to a value. The
521 * value is a reference to the list of records identifers in which
522 * the term occurs. Zebra uses an ISAM data structure for the list
523 * of term occurrences. The Dictionary uses \ref bfile.
527 * Zebra maintains an ISAM for each term where each ISAM is a list
528 * of record identifiers corresponding to the records in which the
529 * term occur. Unlike traditional ISAM systems, the Zebra ISAM
530 * is compressed. The ISAM system uses \ref bfile.
532 * Zebra has more than one ISAM system. The old and stable ISAM system
533 * is named isamc (see isamc.h). Another version isams is a write-once
534 * isam system that is quite compact - suitable for CD-ROMs (isams.h).
535 * The newest ISAM system, isamb, is implemented as a B-Tree (see isamb.h).
537 * \section data1 Data-1
539 * The data1 (data1.h) module deals with structured documents. The module can
540 * can read, modify and write documents. The document structure was
541 * originally based on GRS-1 - a Z39.50 v3 structure that predates
542 * DOM. These days the data1 structure may describe XML/SGML as well.
543 * The data1, like DOM, is a tree structure. Each node in the tree
544 * can be of type element, text (cdata), preprocessing instruction,
545 * comment. Element nodes can point to attribute nodes.
547 * \section recctrl Record Control
549 * The record control module (recctrl.h) is responsible for
550 * managing the various record types ("classes" or filters).
552 * \section rset Result-Set
554 * The Result-Set module (rset.h) defines an interface that all
555 * Zebra Search Results must implement. Each operation (AND, OR, ..)
556 * correspond to an implementation of that interface.
560 * DFA (dfa.h) Deterministic Finite Automa is a regular expression engine.
561 * The module compiles a regular expression to a DFA. The DFA can then
562 * be used in various application to perform fast match against the
563 * origianl expression. The \ref Dict uses DFA to perform lookup
564 * using regular expressions.
571 * indent-tabs-mode: nil
573 * vim: shiftwidth=4 tabstop=8 expandtab