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