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