2 * Copyright (C) 1994-2000, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.50 2000-11-29 14:24:01 adam
8 * Script configure uses yaz pthreads options. Added locking for
9 * zebra_register_{lock,unlock}.
11 * Revision 1.49 2000/05/18 12:01:36 adam
12 * System call times(2) used again. More 64-bit fixes.
14 * Revision 1.48 2000/04/05 09:49:35 adam
15 * On Unix, zebra/z'mbol uses automake.
17 * Revision 1.47 2000/03/20 19:08:36 adam
18 * Added remote record import using Z39.50 extended services and Segment
21 * Revision 1.46 2000/03/15 15:00:31 adam
22 * First work on threaded version.
24 * Revision 1.45 1999/11/30 13:48:04 adam
25 * Improved installation. Updated for inclusion of YAZ header files.
27 * Revision 1.44 1999/11/04 15:00:45 adam
28 * Implemented delete result set(s).
30 * Revision 1.43 1999/07/14 10:59:27 adam
31 * Changed functions isc_getmethod, isams_getmethod.
32 * Improved fatal error handling (such as missing EXPLAIN schema).
34 * Revision 1.42 1999/05/26 07:49:13 adam
37 * Revision 1.41 1999/05/12 13:08:06 adam
38 * First version of ISAMS.
40 * Revision 1.40 1998/11/16 16:03:45 adam
41 * Moved loggin utilities to Yaz. Was implemented in file zlogs.c.
43 * Revision 1.39 1998/10/16 08:14:35 adam
44 * Updated record control system.
46 * Revision 1.38 1998/09/22 10:03:44 adam
47 * Changed result sets to be persistent in the sense that they can
48 * be re-searched if needed.
49 * Fixed memory leak in rsm_or.
51 * Revision 1.37 1998/09/02 13:53:22 adam
52 * Extra parameter decode added to search routines to implement
55 * Revision 1.36 1998/06/24 12:16:16 adam
56 * Support for relations on text operands. Open range support in
57 * DFA module (i.e. [-j], [g-]).
59 * Revision 1.35 1998/06/23 15:33:35 adam
60 * Added feature to specify sort criteria in query (type 7 specifies
63 * Revision 1.34 1998/06/22 11:36:50 adam
64 * Added authentication check facility to zebra.
66 * Revision 1.33 1998/06/12 12:22:14 adam
69 * Revision 1.32 1998/05/27 16:57:47 adam
70 * Zebra returns surrogate diagnostic for single records when
73 * Revision 1.31 1998/05/20 10:12:23 adam
74 * Implemented automatic EXPLAIN database maintenance.
75 * Modified Zebra to work with ASN.1 compiled version of YAZ.
77 * Revision 1.30 1998/03/05 08:45:13 adam
78 * New result set model and modular ranking system. Moved towards
79 * descent server API. System information stored as "SGML" records.
81 * Revision 1.29 1998/02/10 12:03:06 adam
84 * Revision 1.28 1998/01/29 13:40:11 adam
85 * Better logging for scan service.
87 * Revision 1.27 1997/10/27 14:33:06 adam
88 * Moved towards generic character mapping depending on "structure"
89 * field in abstract syntax file. Fixed a few memory leaks. Fixed
90 * bug with negative integers when doing searches with relational
93 * Revision 1.26 1997/09/29 12:41:35 adam
94 * Fixed bug regarding USE_TIMES var.
96 * Revision 1.25 1997/09/29 09:08:36 adam
97 * Revised locking system to be thread safe for the server.
99 * Revision 1.24 1997/09/17 12:19:19 adam
100 * Zebra version corresponds to YAZ version 1.4.
101 * Changed Zebra server so that it doesn't depend on global common_resource.
103 * Revision 1.23 1996/12/23 15:30:46 adam
104 * Work on truncation.
105 * Bug fix: result sets weren't deleted after server shut down.
107 * Revision 1.22 1996/11/04 14:07:49 adam
108 * Moved truncation code to trunc.c.
110 * Revision 1.21 1996/10/29 14:09:58 adam
111 * Use of cisam system - enabled if setting isamc is 1.
113 * Revision 1.20 1996/06/04 10:19:02 adam
114 * Minor changes - removed include of ctype.h.
116 * Revision 1.19 1996/05/14 11:34:01 adam
117 * Scan support in multiple registers/databases.
119 * Revision 1.18 1996/05/14 06:16:50 adam
120 * Compact use/set bytes used in search service.
122 * Revision 1.17 1995/12/08 16:22:57 adam
123 * Work on update while servers are running. Three lock files introduced.
124 * The servers reload their registers when necessary, but they don't
125 * reestablish result sets yet.
127 * Revision 1.16 1995/12/07 17:38:48 adam
128 * Work locking mechanisms for concurrent updates/commit.
130 * Revision 1.15 1995/11/21 15:29:13 adam
131 * Config file 'base' read by default by both indexer and server.
133 * Revision 1.14 1995/11/16 17:00:57 adam
134 * Better logging of rpn query.
136 * Revision 1.13 1995/11/16 15:34:56 adam
137 * Uses new record management system in both indexer and server.
139 * Revision 1.12 1995/10/27 14:00:12 adam
140 * Implemented detection of database availability.
142 * Revision 1.11 1995/10/17 18:02:12 adam
143 * New feature: databases. Implemented as prefix to words in dictionary.
145 * Revision 1.10 1995/10/09 16:18:38 adam
146 * Function dict_lookup_grep got extra client data parameter.
148 * Revision 1.9 1995/10/06 14:38:01 adam
149 * New result set method: r_score.
150 * Local no (sysno) and score is transferred to retrieveCtrl.
152 * Revision 1.8 1995/10/06 13:52:06 adam
153 * Bug fixes. Handler may abort further scanning.
155 * Revision 1.7 1995/10/06 10:43:57 adam
156 * Scan added. 'occurrences' in scan entries not set yet.
158 * Revision 1.6 1995/09/28 09:19:48 adam
159 * xfree/xmalloc used everywhere.
160 * Extract/retrieve method seems to work for text records.
162 * Revision 1.5 1995/09/27 16:17:32 adam
163 * More work on retrieve.
165 * Revision 1.4 1995/09/14 11:53:28 adam
166 * First work on regular expressions/truncations.
168 * Revision 1.3 1995/09/08 08:53:23 adam
169 * Record buffer maintained in server_info.
171 * Revision 1.2 1995/09/06 16:11:19 adam
172 * Option: only one word key per file.
174 * Revision 1.1 1995/09/05 15:28:40 adam
175 * More work on search engine.
180 #include <sys/times.h>
184 #include <pthreads.h>
187 #include <yaz/backend.h>
191 #include <passwddb.h>
193 #include "zebraapi.h"
203 typedef struct zebra_set *ZebraSet;
205 typedef struct zebra_rank_class {
206 struct rank_control *control;
209 struct zebra_rank_class *next;
212 struct zebra_service {
214 struct zebra_session *sessions;
223 int registerState; /* 0 (no commit pages), 1 (use commit pages) */
224 time_t registerChange;
227 ZebraExplainInfo zei;
229 ZebraLockHandle server_lock_cmt;
230 ZebraLockHandle server_lock_org;
231 char *server_path_prefix;
233 ZebraMaps zebra_maps;
234 ZebraRankClass rank_classes;
237 Zebra_mutex_cond session_lock;
239 int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
256 struct sortKey *next;
259 struct zebra_session {
260 struct zebra_session *next;
261 struct zebra_service *service;
264 struct sortKey *sortKeys;
271 char *admin_databaseName;
284 struct rank_control {
286 void *(*create)(ZebraService zh);
287 void (*destroy)(ZebraService zh, void *class_handle);
288 void *(*begin)(ZebraHandle zh, void *class_handle, RSET rset);
289 void (*end)(ZebraHandle zh, void *set_handle);
290 int (*calc)(void *set_handle, int sysno);
291 void (*add)(void *set_handle, int seqno, int term_index);
294 RSET rpn_search (ZebraHandle zh, NMEM mem,
295 Z_RPNQuery *rpn, int num_bases, char **basenames,
296 const char *setname, ZebraSet sset);
299 void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
300 oid_value attributeset,
301 int num_bases, char **basenames,
302 int *position, int *num_entries, ZebraScanEntry **list,
305 RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
306 const char *term, int length_term, const char *flags);
308 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
309 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
310 ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode, Z_RPNQuery *rpn, int num_bases, char **basenames,
311 const char *setname);
312 RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
313 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
316 ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
317 int num, int *positions);
318 void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
320 void resultSetSort (ZebraHandle zh, NMEM nmem,
321 int num_input_setnames, const char **input_setnames,
322 const char *output_setname,
323 Z_SortKeySpecList *sort_sequence, int *sort_status);
324 void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
325 ZebraSet sset, RSET rset,
326 Z_SortKeySpecList *sort_sequence, int *sort_status);
327 void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
329 void zebra_sort (ZebraHandle zh, ODR stream,
330 int num_input_setnames, const char **input_setnames,
331 const char *output_setname, Z_SortKeySpecList *sort_sequence,
334 int zebra_server_lock_init (ZebraService zh);
335 int zebra_server_lock_destroy (ZebraService zh);
336 int zebra_server_lock (ZebraService zh, int lockCommit);
337 void zebra_server_unlock (ZebraService zh, int commitPhase);
338 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
340 typedef struct attent
343 data1_local_attribute *local_attributes;
346 void zebraRankInstall (ZebraService zh, struct rank_control *ctrl);
347 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
348 void zebraRankDestroy (ZebraService zh);
350 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
352 extern struct rank_control *rank1_class;
354 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
355 oid_value input_format, Z_RecordComposition *comp,
356 oid_value *output_format, char **rec_bufp,
357 int *rec_lenp, char **basenamep);
359 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
360 void zebra_index_merge (ZebraHandle zh);
363 struct zebra_fetch_control {
366 off_t record_int_pos;
367 const char *record_int_buf;
372 int zebra_record_ext_read (void *fh, char *buf, size_t count);
373 off_t zebra_record_ext_seek (void *fh, off_t offset);
374 off_t zebra_record_ext_tell (void *fh);
375 off_t zebra_record_int_seek (void *fh, off_t offset);
376 off_t zebra_record_int_tell (void *fh);
377 int zebra_record_int_read (void *fh, char *buf, size_t count);
378 void zebra_record_int_end (void *fh, off_t offset);