2 * Copyright (C) 1995-1998, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.56 1998-01-12 15:04:08 adam
8 * The test option (-s) only uses read-lock (and not write lock).
10 * Revision 1.55 1997/10/27 14:33:04 adam
11 * Moved towards generic character mapping depending on "structure"
12 * field in abstract syntax file. Fixed a few memory leaks. Fixed
13 * bug with negative integers when doing searches with relational
16 * Revision 1.54 1997/09/29 09:08:36 adam
17 * Revised locking system to be thread safe for the server.
19 * Revision 1.53 1997/09/25 14:54:43 adam
20 * WIN32 files lock support.
22 * Revision 1.52 1997/09/22 12:39:06 adam
23 * Added get_pos method for the ranked result sets.
25 * Revision 1.51 1997/09/18 08:59:19 adam
26 * Extra generic handle for the character mapping routines.
28 * Revision 1.50 1997/09/17 12:19:13 adam
29 * Zebra version corresponds to YAZ version 1.4.
30 * Changed Zebra server so that it doesn't depend on global common_resource.
32 * Revision 1.49 1997/09/05 15:30:08 adam
33 * Changed prototype for chr_map_input - added const.
34 * Added support for C++, headers uses extern "C" for public definitions.
36 * Revision 1.48 1997/02/12 20:39:45 adam
37 * Implemented options -f <n> that limits the log to the first <n>
39 * Changed some log messages also.
41 * Revision 1.47 1996/12/23 15:30:44 adam
43 * Bug fix: result sets weren't deleted after server shut down.
45 * Revision 1.46 1996/11/08 11:10:19 adam
46 * Buffers used during file match got bigger.
47 * Compressed ISAM support everywhere.
48 * Bug fixes regarding masking characters in queries.
49 * Redesigned Regexp-2 queries.
51 * Revision 1.45 1996/10/29 14:09:42 adam
52 * Use of cisam system - enabled if setting isamc is 1.
54 * Revision 1.44 1996/06/06 12:08:40 quinn
55 * Added showRecord function
57 * Revision 1.43 1996/06/04 10:18:12 adam
58 * Search/scan uses character mapping module.
60 * Revision 1.42 1996/06/04 08:20:16 quinn
63 * Revision 1.41 1996/06/04 07:54:55 quinn
66 * Revision 1.40 1996/05/31 09:06:58 quinn
67 * Work on character-set handling
69 * Revision 1.39 1996/05/14 14:04:33 adam
70 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
73 * Revision 1.38 1996/04/12 07:02:23 adam
74 * File update of single files.
76 * Revision 1.37 1996/03/26 16:01:13 adam
77 * New setting lockPath: directory of various lock files.
79 * Revision 1.36 1996/03/21 14:50:09 adam
80 * File update uses modify-time instead of change-time.
82 * Revision 1.35 1996/02/12 18:45:36 adam
83 * New fileVerboseFlag in record group control.
85 * Revision 1.34 1995/12/11 11:43:29 adam
86 * Locking based on fcntl instead of flock.
87 * Setting commitEnable removed. Command line option -n can be used to
88 * prevent commit if commit setting is defined in the configuration file.
90 * Revision 1.33 1995/12/08 16:22:53 adam
91 * Work on update while servers are running. Three lock files introduced.
92 * The servers reload their registers when necessary, but they don't
93 * reestablish result sets yet.
95 * Revision 1.32 1995/12/07 17:38:46 adam
96 * Work locking mechanisms for concurrent updates/commit.
98 * Revision 1.31 1995/12/06 12:41:22 adam
99 * New command 'stat' for the index program.
100 * Filenames can be read from stdin by specifying '-'.
101 * Bug fix/enhancement of the transformation from terms to regular
102 * expressons in the search engine.
104 * Revision 1.30 1995/12/05 11:25:02 adam
105 * Include of zebraver.h.
107 * Revision 1.29 1995/11/28 09:09:40 adam
108 * Zebra config renamed.
109 * Use setting 'recordId' to identify record now.
110 * Bug fix in recindex.c: rec_release_blocks was invokeded even
111 * though the blocks were already released.
112 * File traversal properly deletes records when needed.
114 * Revision 1.28 1995/11/27 13:58:53 adam
115 * New option -t. storeStore data implemented in server.
117 * Revision 1.27 1995/11/25 10:24:06 adam
118 * More record fields - they are enumerated now.
119 * New options: flagStoreData flagStoreKey.
121 * Revision 1.26 1995/11/22 17:19:17 adam
122 * Record management uses the bfile system.
124 * Revision 1.25 1995/11/21 15:29:12 adam
125 * Config file 'base' read by default by both indexer and server.
127 * Revision 1.24 1995/11/21 15:01:15 adam
128 * New general match criteria implemented.
129 * New feature: document groups.
131 * Revision 1.23 1995/11/20 16:59:45 adam
132 * New update method: the 'old' keys are saved for each records.
134 * Revision 1.22 1995/11/20 11:56:26 adam
135 * Work on new traversal.
137 * Revision 1.21 1995/11/16 15:34:55 adam
138 * Uses new record management system in both indexer and server.
140 * Revision 1.20 1995/11/15 14:46:18 adam
141 * Started work on better record management system.
143 * Revision 1.19 1995/10/27 14:00:11 adam
144 * Implemented detection of database availability.
146 * Revision 1.18 1995/10/17 18:02:08 adam
147 * New feature: databases. Implemented as prefix to words in dictionary.
149 * Revision 1.17 1995/10/13 16:01:49 adam
152 * Revision 1.16 1995/10/10 12:24:38 adam
153 * Temporary sort files are compressed.
155 * Revision 1.15 1995/10/04 16:57:19 adam
156 * Key input and merge sort in one pass.
158 * Revision 1.14 1995/09/29 14:01:40 adam
161 * Revision 1.13 1995/09/28 14:22:56 adam
162 * Sort uses smaller temporary files.
164 * Revision 1.12 1995/09/28 12:10:32 adam
165 * Bug fixes. Field prefix used in queries.
167 * Revision 1.11 1995/09/27 12:22:28 adam
168 * More work on extract in record control.
169 * Field name is not in isam keys but in prefix in dictionary words.
171 * Revision 1.10 1995/09/14 07:48:23 adam
172 * Record control management.
174 * Revision 1.9 1995/09/11 13:09:33 adam
175 * More work on relevance feedback.
177 * Revision 1.8 1995/09/08 14:52:27 adam
178 * Minor changes. Dictionary is lower case now.
180 * Revision 1.7 1995/09/06 16:11:16 adam
181 * Option: only one word key per file.
183 * Revision 1.6 1995/09/05 15:28:39 adam
184 * More work on search engine.
186 * Revision 1.5 1995/09/04 12:33:42 adam
187 * Various cleanup. YAZ util used instead.
189 * Revision 1.4 1995/09/04 09:10:35 adam
190 * More work on index add/del/update.
191 * Merge sort implemented.
192 * Initial work on z39 server.
194 * Revision 1.3 1995/09/01 14:06:35 adam
195 * Split of work into more files.
197 * Revision 1.2 1995/09/01 10:30:24 adam
198 * More work on indexing. Not working yet.
200 * Revision 1.1 1995/08/31 14:50:24 adam
201 * New simple file index tool.
205 #include <zebraver.h>
206 #include <zebrautl.h>
207 #include <zebramap.h>
214 #define IT_MAX_WORD 256
215 #define IT_KEY_HAVE_SEQNO 1
216 #define IT_KEY_HAVE_FIELD 0
225 enum dirsKind { dirs_dir, dirs_file };
250 int fileVerboseLimit;
253 ZebraMaps zebra_maps;
256 void getFnameTmp (char *fname, int no);
258 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
259 struct dirs_info *dirs_fopen (Dict dict, const char *path);
260 struct dirs_entry *dirs_read (struct dirs_info *p);
261 struct dirs_entry *dirs_last (struct dirs_info *p);
262 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
263 void dirs_rmdir (struct dirs_info *p, const char *src);
264 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime);
265 void dirs_del (struct dirs_info *p, const char *src);
266 void dirs_free (struct dirs_info **pp);
268 struct dir_entry *dir_open (const char *rep);
269 void dir_sort (struct dir_entry *e);
270 void dir_free (struct dir_entry **e_p);
272 void repositoryUpdate (struct recordGroup *rGroup);
273 void repositoryAdd (struct recordGroup *rGroup);
274 void repositoryDelete (struct recordGroup *rGroup);
275 void repositoryShow (struct recordGroup *rGroup);
277 int key_open (BFiles bfs, int mem, int rw);
278 int key_close (void);
279 int key_compare (const void *p1, const void *p2);
280 int key_get_pos (const void *p);
281 int key_compare_it (const void *p1, const void *p2);
282 int key_qsort_compare (const void *p1, const void *p2);
283 void key_logdump (int mask, const void *p);
284 void inv_prstat (BFiles bfs);
285 void key_input (BFiles bfs, int nkeys, int cache);
286 ISAMC_M key_isamc_m (Res res);
287 int merge_sort (char **buf, int from, int to);
289 #define FNAME_DICT "dict"
290 #define FNAME_ISAM "isam"
291 #define FNAME_ISAMC "isamc"
292 #define FNAME_CONFIG "zebra.cfg"
294 #define GMATCH_DICT "gmatch"
295 #define FMATCH_DICT "fmatch"
297 struct strtab *strtab_mk (void);
298 int strtab_src (struct strtab *t, const char *name, void ***infop);
299 void strtab_del (struct strtab *t,
300 void (*func)(const char *name, void *info, void *data),
302 int index_char_cvt (int c);
303 int index_word_prefix (char *string, int attset_ordinal,
304 int local_attribute, const char *databaseName);
306 int fileExtract (SYSNO *sysno, const char *fname,
307 const struct recordGroup *rGroup, int deleteFlag);
309 void zebraIndexLockMsg (const char *str);
310 void zebraIndexUnlock (void);
311 void zebraIndexLock (BFiles bfs, int commitNow, const char *rval);
312 int zebraIndexWait (int commitPhase);
314 #define FNAME_MAIN_LOCK "zebraidx.LCK"
315 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
316 #define FNAME_ORG_LOCK "zebraorg.LCK"
317 #define FNAME_TOUCH_TIME "zebraidx.time"
319 typedef struct zebra_lock_info *ZebraLockHandle;
320 ZebraLockHandle zebra_lock_create(const char *file, int excl_flag);
321 void zebra_lock_destroy (ZebraLockHandle h);
322 int zebra_lock (ZebraLockHandle h);
323 int zebra_lock_nb (ZebraLockHandle h);
324 int zebra_unlock (ZebraLockHandle h);
325 int zebra_lock_fd (ZebraLockHandle h);
326 void zebra_lock_prefix (Res res, char *dst);
329 extern Res common_resource;