2 * Copyright (C) 1995-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.63 1999-05-26 07:49:13 adam
10 * Revision 1.62 1999/05/12 13:08:06 adam
11 * First version of ISAMS.
13 * Revision 1.61 1999/03/09 16:27:49 adam
14 * More work on SDRKit integration.
16 * Revision 1.60 1998/10/16 08:14:31 adam
17 * Updated record control system.
19 * Revision 1.59 1998/06/08 14:43:11 adam
20 * Added suport for EXPLAIN Proxy servers - added settings databasePath
21 * and explainDatabase to facilitate this. Increased maximum number
22 * of databases and attributes in one register.
24 * Revision 1.58 1998/05/20 10:12:16 adam
25 * Implemented automatic EXPLAIN database maintenance.
26 * Modified Zebra to work with ASN.1 compiled version of YAZ.
28 * Revision 1.57 1998/03/05 08:45:12 adam
29 * New result set model and modular ranking system. Moved towards
30 * descent server API. System information stored as "SGML" records.
32 * Revision 1.56 1998/01/12 15:04:08 adam
33 * The test option (-s) only uses read-lock (and not write lock).
35 * Revision 1.55 1997/10/27 14:33:04 adam
36 * Moved towards generic character mapping depending on "structure"
37 * field in abstract syntax file. Fixed a few memory leaks. Fixed
38 * bug with negative integers when doing searches with relational
41 * Revision 1.54 1997/09/29 09:08:36 adam
42 * Revised locking system to be thread safe for the server.
44 * Revision 1.53 1997/09/25 14:54:43 adam
45 * WIN32 files lock support.
47 * Revision 1.52 1997/09/22 12:39:06 adam
48 * Added get_pos method for the ranked result sets.
50 * Revision 1.51 1997/09/18 08:59:19 adam
51 * Extra generic handle for the character mapping routines.
53 * Revision 1.50 1997/09/17 12:19:13 adam
54 * Zebra version corresponds to YAZ version 1.4.
55 * Changed Zebra server so that it doesn't depend on global common_resource.
57 * Revision 1.49 1997/09/05 15:30:08 adam
58 * Changed prototype for chr_map_input - added const.
59 * Added support for C++, headers uses extern "C" for public definitions.
61 * Revision 1.48 1997/02/12 20:39:45 adam
62 * Implemented options -f <n> that limits the log to the first <n>
64 * Changed some log messages also.
66 * Revision 1.47 1996/12/23 15:30:44 adam
68 * Bug fix: result sets weren't deleted after server shut down.
70 * Revision 1.46 1996/11/08 11:10:19 adam
71 * Buffers used during file match got bigger.
72 * Compressed ISAM support everywhere.
73 * Bug fixes regarding masking characters in queries.
74 * Redesigned Regexp-2 queries.
76 * Revision 1.45 1996/10/29 14:09:42 adam
77 * Use of cisam system - enabled if setting isamc is 1.
79 * Revision 1.44 1996/06/06 12:08:40 quinn
80 * Added showRecord function
82 * Revision 1.43 1996/06/04 10:18:12 adam
83 * Search/scan uses character mapping module.
85 * Revision 1.42 1996/06/04 08:20:16 quinn
88 * Revision 1.41 1996/06/04 07:54:55 quinn
91 * Revision 1.40 1996/05/31 09:06:58 quinn
92 * Work on character-set handling
94 * Revision 1.39 1996/05/14 14:04:33 adam
95 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
98 * Revision 1.38 1996/04/12 07:02:23 adam
99 * File update of single files.
101 * Revision 1.37 1996/03/26 16:01:13 adam
102 * New setting lockPath: directory of various lock files.
104 * Revision 1.36 1996/03/21 14:50:09 adam
105 * File update uses modify-time instead of change-time.
107 * Revision 1.35 1996/02/12 18:45:36 adam
108 * New fileVerboseFlag in record group control.
110 * Revision 1.34 1995/12/11 11:43:29 adam
111 * Locking based on fcntl instead of flock.
112 * Setting commitEnable removed. Command line option -n can be used to
113 * prevent commit if commit setting is defined in the configuration file.
115 * Revision 1.33 1995/12/08 16:22:53 adam
116 * Work on update while servers are running. Three lock files introduced.
117 * The servers reload their registers when necessary, but they don't
118 * reestablish result sets yet.
120 * Revision 1.32 1995/12/07 17:38:46 adam
121 * Work locking mechanisms for concurrent updates/commit.
123 * Revision 1.31 1995/12/06 12:41:22 adam
124 * New command 'stat' for the index program.
125 * Filenames can be read from stdin by specifying '-'.
126 * Bug fix/enhancement of the transformation from terms to regular
127 * expressons in the search engine.
129 * Revision 1.30 1995/12/05 11:25:02 adam
130 * Include of zebraver.h.
132 * Revision 1.29 1995/11/28 09:09:40 adam
133 * Zebra config renamed.
134 * Use setting 'recordId' to identify record now.
135 * Bug fix in recindex.c: rec_release_blocks was invokeded even
136 * though the blocks were already released.
137 * File traversal properly deletes records when needed.
139 * Revision 1.28 1995/11/27 13:58:53 adam
140 * New option -t. storeStore data implemented in server.
142 * Revision 1.27 1995/11/25 10:24:06 adam
143 * More record fields - they are enumerated now.
144 * New options: flagStoreData flagStoreKey.
146 * Revision 1.26 1995/11/22 17:19:17 adam
147 * Record management uses the bfile system.
149 * Revision 1.25 1995/11/21 15:29:12 adam
150 * Config file 'base' read by default by both indexer and server.
152 * Revision 1.24 1995/11/21 15:01:15 adam
153 * New general match criteria implemented.
154 * New feature: document groups.
156 * Revision 1.23 1995/11/20 16:59:45 adam
157 * New update method: the 'old' keys are saved for each records.
159 * Revision 1.22 1995/11/20 11:56:26 adam
160 * Work on new traversal.
162 * Revision 1.21 1995/11/16 15:34:55 adam
163 * Uses new record management system in both indexer and server.
165 * Revision 1.20 1995/11/15 14:46:18 adam
166 * Started work on better record management system.
168 * Revision 1.19 1995/10/27 14:00:11 adam
169 * Implemented detection of database availability.
171 * Revision 1.18 1995/10/17 18:02:08 adam
172 * New feature: databases. Implemented as prefix to words in dictionary.
174 * Revision 1.17 1995/10/13 16:01:49 adam
177 * Revision 1.16 1995/10/10 12:24:38 adam
178 * Temporary sort files are compressed.
180 * Revision 1.15 1995/10/04 16:57:19 adam
181 * Key input and merge sort in one pass.
183 * Revision 1.14 1995/09/29 14:01:40 adam
186 * Revision 1.13 1995/09/28 14:22:56 adam
187 * Sort uses smaller temporary files.
189 * Revision 1.12 1995/09/28 12:10:32 adam
190 * Bug fixes. Field prefix used in queries.
192 * Revision 1.11 1995/09/27 12:22:28 adam
193 * More work on extract in record control.
194 * Field name is not in isam keys but in prefix in dictionary words.
196 * Revision 1.10 1995/09/14 07:48:23 adam
197 * Record control management.
199 * Revision 1.9 1995/09/11 13:09:33 adam
200 * More work on relevance feedback.
202 * Revision 1.8 1995/09/08 14:52:27 adam
203 * Minor changes. Dictionary is lower case now.
205 * Revision 1.7 1995/09/06 16:11:16 adam
206 * Option: only one word key per file.
208 * Revision 1.6 1995/09/05 15:28:39 adam
209 * More work on search engine.
211 * Revision 1.5 1995/09/04 12:33:42 adam
212 * Various cleanup. YAZ util used instead.
214 * Revision 1.4 1995/09/04 09:10:35 adam
215 * More work on index add/del/update.
216 * Merge sort implemented.
217 * Initial work on z39 server.
219 * Revision 1.3 1995/09/01 14:06:35 adam
220 * Split of work into more files.
222 * Revision 1.2 1995/09/01 10:30:24 adam
223 * More work on indexing. Not working yet.
225 * Revision 1.1 1995/08/31 14:50:24 adam
226 * New simple file index tool.
230 #include <zebraver.h>
231 #include <zebrautl.h>
232 #include <zebramap.h>
245 #define IT_MAX_WORD 256
246 #define IT_KEY_HAVE_SEQNO 1
247 #define IT_KEY_HAVE_FIELD 0
256 enum dirsKind { dirs_dir, dirs_file };
280 int fileVerboseLimit;
281 int databaseNamePath;
288 ZebraMaps zebra_maps;
292 void getFnameTmp (char *fname, int no);
294 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
295 struct dirs_info *dirs_fopen (Dict dict, const char *path);
296 struct dirs_entry *dirs_read (struct dirs_info *p);
297 struct dirs_entry *dirs_last (struct dirs_info *p);
298 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
299 void dirs_rmdir (struct dirs_info *p, const char *src);
300 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime);
301 void dirs_del (struct dirs_info *p, const char *src);
302 void dirs_free (struct dirs_info **pp);
304 struct dir_entry *dir_open (const char *rep);
305 void dir_sort (struct dir_entry *e);
306 void dir_free (struct dir_entry **e_p);
308 void repositoryUpdate (struct recordGroup *rGroup);
309 void repositoryAdd (struct recordGroup *rGroup);
310 void repositoryDelete (struct recordGroup *rGroup);
311 void repositoryShow (struct recordGroup *rGroup);
313 int key_open (struct recordGroup *rGroup, int mem);
314 int key_close (struct recordGroup *group);
315 int key_compare (const void *p1, const void *p2);
316 int key_get_pos (const void *p);
317 int key_compare_it (const void *p1, const void *p2);
318 int key_qsort_compare (const void *p1, const void *p2);
319 void key_logdump (int mask, const void *p);
320 void inv_prstat (BFiles bfs);
321 void inv_compact (BFiles bfs);
322 void key_input (BFiles bfs, int nkeys, int cache);
323 ISAMC_M key_isamc_m (Res res);
324 ISAMS_M key_isams_m (Res res);
325 int merge_sort (char **buf, int from, int to);
326 int key_SU_code (int ch, char *out);
328 #define FNAME_DICT "dict"
329 #define FNAME_ISAM "isam"
330 #define FNAME_ISAMC "isamc"
331 #define FNAME_ISAMS "isams"
332 #define FNAME_CONFIG "zebra.cfg"
334 #define GMATCH_DICT "gmatch"
335 #define FMATCH_DICT "fmatch"
337 struct strtab *strtab_mk (void);
338 int strtab_src (struct strtab *t, const char *name, void ***infop);
339 void strtab_del (struct strtab *t,
340 void (*func)(const char *name, void *info, void *data),
342 int index_char_cvt (int c);
343 int index_word_prefix (char *string, int attset_ordinal,
344 int local_attribute, const char *databaseName);
346 int fileExtract (SYSNO *sysno, const char *fname,
347 const struct recordGroup *rGroup, int deleteFlag);
349 void zebraIndexLockMsg (const char *str);
350 void zebraIndexUnlock (void);
351 void zebraIndexLock (BFiles bfs, int commitNow, const char *rval);
352 int zebraIndexWait (int commitPhase);
354 #define FNAME_MAIN_LOCK "zebraidx.LCK"
355 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
356 #define FNAME_ORG_LOCK "zebraorg.LCK"
357 #define FNAME_TOUCH_TIME "zebraidx.time"
359 typedef struct zebra_lock_info *ZebraLockHandle;
360 ZebraLockHandle zebra_lock_create(const char *file, int excl_flag);
361 void zebra_lock_destroy (ZebraLockHandle h);
362 int zebra_lock (ZebraLockHandle h);
363 int zebra_lock_nb (ZebraLockHandle h);
364 int zebra_unlock (ZebraLockHandle h);
365 int zebra_lock_fd (ZebraLockHandle h);
366 void zebra_lock_prefix (Res res, char *dst);
368 void zebra_load_atts (data1_handle dh, Res res);
370 extern Res common_resource;