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