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