2 * Copyright (C) 1995-1998, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1998-05-27 16:57:44 adam
8 * Zebra returns surrogate diagnostic for single records when
11 * Revision 1.2 1998/05/20 10:12:19 adam
12 * Implemented automatic EXPLAIN database maintenance.
13 * Modified Zebra to work with ASN.1 compiled version of YAZ.
15 * Revision 1.1 1998/03/05 08:45:13 adam
16 * New result set model and modular ranking system. Moved towards
17 * descent server API. System information stored as "SGML" records.
31 static int zebra_register_lock (ZebraHandle zh)
34 int state = zebra_server_lock_get_state(zh, &lastChange);
44 zebra_server_lock (zh, state);
48 if (zh->registerState == state)
50 if (zh->registerChange >= lastChange)
52 logf (LOG_LOG, "Register completely updated since last access");
54 else if (zh->registerState == -1)
55 logf (LOG_LOG, "Reading register using state %d pid=%ld", state,
58 logf (LOG_LOG, "Register has changed state from %d to %d",
59 zh->registerState, state);
60 zh->registerChange = lastChange;
63 zebraExplain_close (zh->zei, 0, 0);
64 dict_close (zh->dict);
65 sortIdx_close (zh->sortIdx);
69 isc_close (zh->isamc);
70 rec_close (&zh->records);
72 bf_cache (zh->bfs, state ? res_get (zh->res, "shadow") : NULL);
73 zh->registerState = state;
74 zh->records = rec_open (zh->bfs, 0);
75 if (!(zh->dict = dict_open (zh->bfs, FNAME_DICT, 40, 0)))
77 if (!(zh->sortIdx = sortIdx_open (zh->bfs, 0)))
81 if (!res_get_match (zh->res, "isam", "i", NULL))
83 if (!(zh->isamc = isc_open (zh->bfs, FNAME_ISAMC,
84 0, key_isamc_m(zh->res))))
90 if (!(zh->isam = is_open (zh->bfs, FNAME_ISAM, key_compare, 0,
91 sizeof (struct it_key), zh->res)))
94 zh->zei = zebraExplain_open (zh->records, zh->dh, zh->res, 0, 0, 0);
99 static void zebra_register_unlock (ZebraHandle zh)
101 static int waitSec = -1;
105 logf (LOG_LOG, "user/system: %ld/%ld",
106 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
107 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
111 char *s = res_get (zh->res, "debugRequestWait");
122 if (zh->registerState != -1)
123 zebra_server_unlock (zh, zh->registerState);
126 ZebraHandle zebra_open (const char *host, const char *configName)
128 ZebraHandle zh = xmalloc (sizeof(*zh));
130 if (!(zh->res = res_open (configName)))
132 logf (LOG_WARN, "Failed to read resources `%s'", configName);
135 zebra_server_lock_init (zh);
136 zh->dh = data1_create ();
137 zh->bfs = bfs_create (res_get (zh->res, "register"));
138 bf_lockDir (zh->bfs, res_get (zh->res, "lockDir"));
139 data1_set_tabpath (zh->dh, res_get(zh->res, "profilePath"));
141 zh->registerState = -1; /* trigger open of registers! */
142 zh->registerChange = 0;
145 zh->zebra_maps = zebra_maps_open (zh->res);
146 zh->rank_classes = NULL;
148 zebraRankInstall (zh, rank1_class);
152 void zebra_close (ZebraHandle zh)
156 resultSetDestroy (zh);
157 zebraExplain_close (zh->zei, 0, 0);
158 dict_close (zh->dict);
159 sortIdx_close (zh->sortIdx);
163 isc_close (zh->isamc);
164 rec_close (&zh->records);
165 zebra_register_unlock (zh);
167 zebra_maps_close (zh->zebra_maps);
168 zebraRankDestroy (zh);
169 bfs_destroy (zh->bfs);
170 data1_destroy (zh->dh);
171 zebra_server_lock_destroy (zh);
177 void zebra_search_rpn (ZebraHandle zh, ODR stream,
178 Z_RPNQuery *query, int num_bases, char **basenames,
181 zebra_register_lock (zh);
183 zh->errString = NULL;
185 rpn_search (zh, stream, query, num_bases, basenames, setname);
186 zebra_register_unlock (zh);
189 void zebra_records_retrieve (ZebraHandle zh, ODR stream,
190 const char *setname, Z_RecordComposition *comp,
191 oid_value input_format, int num_recs,
192 ZebraRetrievalRecord *recs)
198 pos_array = xmalloc (sizeof(*pos_array));
199 for (i = 0; i<num_recs; i++)
200 pos_array[i] = recs[i].position;
202 zebra_register_lock (zh);
204 poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
207 logf (LOG_DEBUG, "zebraPosSetCreate error");
212 for (i = 0; i<num_recs; i++)
217 logf (LOG_DEBUG, "Out of range. pos=%d", pos_array[i]);
222 zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
223 stream, input_format, comp,
224 &recs[i].format, &recs[i].buf,
227 recs[i].errString = NULL;
230 zebraPosSetDestroy (zh, poset, num_recs);
232 zebra_register_unlock (zh);
236 void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
237 oid_value attributeset,
238 int num_bases, char **basenames,
239 int *position, int *num_entries, ZebraScanEntry **entries,
243 zebra_register_lock (zh);
244 rpn_scan (zh, stream, zapt, attributeset,
245 num_bases, basenames, position,
246 num_entries, entries, is_partial);
247 zebra_register_unlock (zh);
250 void zebra_sort (ZebraHandle zh, ODR stream,
251 int num_input_setnames, char **input_setnames,
252 char *output_setname, Z_SortKeySpecList *sort_sequence,
255 zebra_register_lock (zh);
256 resultSetSort (zh, stream, num_input_setnames, input_setnames,
257 output_setname, sort_sequence, sort_status);
258 zebra_register_unlock (zh);
261 void zebra_setDB (ZebraHandle zh, int num_bases, char **basenames)
266 void zebra_setRecordType (ZebraHandle zh, const char *type)
271 void zebra_setGroup (ZebraHandle zh, const char *group)
276 void zebra_admin (ZebraHandle zh, const char *command)