2 * Copyright (C) 1995-1998, Index Data ApS
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1998-08-24 17:29:23 adam
10 * Revision 1.7 1998/06/24 12:16:13 adam
11 * Support for relations on text operands. Open range support in
12 * DFA module (i.e. [-j], [g-]).
14 * Revision 1.6 1998/06/22 11:36:47 adam
15 * Added authentication check facility to zebra.
17 * Revision 1.5 1998/06/13 00:14:08 adam
20 * Revision 1.4 1998/06/12 12:22:12 adam
23 * Revision 1.3 1998/05/27 16:57:44 adam
24 * Zebra returns surrogate diagnostic for single records when
27 * Revision 1.2 1998/05/20 10:12:19 adam
28 * Implemented automatic EXPLAIN database maintenance.
29 * Modified Zebra to work with ASN.1 compiled version of YAZ.
31 * Revision 1.1 1998/03/05 08:45:13 adam
32 * New result set model and modular ranking system. Moved towards
33 * descent server API. System information stored as "SGML" records.
48 static int zebra_register_lock (ZebraHandle zh)
51 int state = zebra_server_lock_get_state(zh, &lastChange);
61 zebra_server_lock (zh, state);
65 if (zh->registerState == state)
67 if (zh->registerChange >= lastChange)
69 logf (LOG_LOG, "Register completely updated since last access");
71 else if (zh->registerState == -1)
72 logf (LOG_LOG, "Reading register using state %d pid=%ld", state,
75 logf (LOG_LOG, "Register has changed state from %d to %d",
76 zh->registerState, state);
77 zh->registerChange = lastChange;
80 zebraExplain_close (zh->zei, 0, 0);
81 dict_close (zh->dict);
82 sortIdx_close (zh->sortIdx);
86 isc_close (zh->isamc);
87 rec_close (&zh->records);
89 bf_cache (zh->bfs, state ? res_get (zh->res, "shadow") : NULL);
90 zh->registerState = state;
91 zh->records = rec_open (zh->bfs, 0);
92 if (!(zh->dict = dict_open (zh->bfs, FNAME_DICT, 40, 0)))
94 logf (LOG_WARN, "dict_open");
97 if (!(zh->sortIdx = sortIdx_open (zh->bfs, 0)))
99 logf (LOG_WARN, "sortIdx_open");
104 if (!res_get_match (zh->res, "isam", "i", NULL))
106 if (!(zh->isamc = isc_open (zh->bfs, FNAME_ISAMC,
107 0, key_isamc_m(zh->res))))
109 logf (LOG_WARN, "isc_open");
116 if (!(zh->isam = is_open (zh->bfs, FNAME_ISAM, key_compare, 0,
117 sizeof (struct it_key), zh->res)))
119 logf (LOG_WARN, "is_open");
123 zh->zei = zebraExplain_open (zh->records, zh->dh, zh->res, 0, 0, 0);
128 static void zebra_register_unlock (ZebraHandle zh)
130 static int waitSec = -1;
134 logf (LOG_LOG, "user/system: %ld/%ld",
135 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
136 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
140 char *s = res_get (zh->res, "debugRequestWait");
151 if (zh->registerState != -1)
152 zebra_server_unlock (zh, zh->registerState);
155 ZebraHandle zebra_open (const char *configName)
157 ZebraHandle zh = xmalloc (sizeof(*zh));
159 if (!(zh->res = res_open (configName)))
161 logf (LOG_WARN, "Failed to read resources `%s'", configName);
164 zebra_server_lock_init (zh);
165 zh->dh = data1_create ();
166 zh->bfs = bfs_create (res_get (zh->res, "register"));
167 bf_lockDir (zh->bfs, res_get (zh->res, "lockDir"));
168 data1_set_tabpath (zh->dh, res_get(zh->res, "profilePath"));
170 zh->registerState = -1; /* trigger open of registers! */
171 zh->registerChange = 0;
174 zh->zebra_maps = zebra_maps_open (zh->res);
175 zh->rank_classes = NULL;
179 zebraRankInstall (zh, rank1_class);
181 if (!res_get (zh->res, "passwd"))
182 zh->passwd_db = NULL;
185 zh->passwd_db = passwd_db_open ();
187 logf (LOG_WARN|LOG_ERRNO, "passwd_db_open failed");
189 passwd_db_file (zh->passwd_db, res_get (zh->res, "passwd"));
194 void zebra_close (ZebraHandle zh)
198 resultSetDestroy (zh);
199 zebraExplain_close (zh->zei, 0, 0);
200 dict_close (zh->dict);
201 sortIdx_close (zh->sortIdx);
205 isc_close (zh->isamc);
206 rec_close (&zh->records);
207 zebra_register_unlock (zh);
209 zebra_maps_close (zh->zebra_maps);
210 zebraRankDestroy (zh);
211 bfs_destroy (zh->bfs);
212 data1_destroy (zh->dh);
213 zebra_server_lock_destroy (zh);
216 passwd_db_close (zh->passwd_db);
221 void zebra_search_rpn (ZebraHandle zh, ODR stream,
222 Z_RPNQuery *query, int num_bases, char **basenames,
225 zebra_register_lock (zh);
227 zh->errString = NULL;
229 rpn_search (zh, stream, query, num_bases, basenames, setname);
230 zebra_register_unlock (zh);
233 void zebra_records_retrieve (ZebraHandle zh, ODR stream,
234 const char *setname, Z_RecordComposition *comp,
235 oid_value input_format, int num_recs,
236 ZebraRetrievalRecord *recs)
242 zh->errString = NULL;
243 pos_array = xmalloc (num_recs * sizeof(*pos_array));
244 for (i = 0; i<num_recs; i++)
245 pos_array[i] = recs[i].position;
247 zebra_register_lock (zh);
249 poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
252 logf (LOG_DEBUG, "zebraPosSetCreate error");
257 for (i = 0; i<num_recs; i++)
262 logf (LOG_DEBUG, "Out of range. pos=%d", pos_array[i]);
267 zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
268 stream, input_format, comp,
269 &recs[i].format, &recs[i].buf,
272 recs[i].errString = NULL;
275 zebraPosSetDestroy (zh, poset, num_recs);
277 zebra_register_unlock (zh);
281 void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
282 oid_value attributeset,
283 int num_bases, char **basenames,
284 int *position, int *num_entries, ZebraScanEntry **entries,
288 zh->errString = NULL;
289 zebra_register_lock (zh);
290 rpn_scan (zh, stream, zapt, attributeset,
291 num_bases, basenames, position,
292 num_entries, entries, is_partial);
293 zebra_register_unlock (zh);
296 void zebra_sort (ZebraHandle zh, ODR stream,
297 int num_input_setnames, const char **input_setnames,
298 const char *output_setname, Z_SortKeySpecList *sort_sequence,
302 zh->errString = NULL;
303 zebra_register_lock (zh);
304 resultSetSort (zh, stream, num_input_setnames, input_setnames,
305 output_setname, sort_sequence, sort_status);
306 zebra_register_unlock (zh);
309 int zebra_errCode (ZebraHandle zh)
314 const char *zebra_errString (ZebraHandle zh)
316 return diagbib1_str (zh->errCode);
319 char *zebra_errAdd (ZebraHandle zh)
321 return zh->errString;
324 int zebra_hits (ZebraHandle zh)
329 int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
331 if (!zh->passwd_db || !passwd_db_auth (zh->passwd_db, user, pass))
336 void zebra_setDB (ZebraHandle zh, int num_bases, char **basenames)
341 void zebra_setRecordType (ZebraHandle zh, const char *type)
346 void zebra_setGroup (ZebraHandle zh, const char *group)
351 void zebra_admin (ZebraHandle zh, const char *command)