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