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