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