Changed functions isc_getmethod, isams_getmethod.
[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, ISAMC_M me);
103 ISAMS_M key_isams_m (Res res, ISAMS_M me);
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.65  1999-07-14 10:59:26  adam
162  * Changed functions isc_getmethod, isams_getmethod.
163  * Improved fatal error handling (such as missing EXPLAIN schema).
164  *
165  * Revision 1.64  1999/06/30 15:07:23  heikki
166  * Adding isamh stuff
167  *
168  * Revision 1.63  1999/05/26 07:49:13  adam
169  * C++ compilation.
170  *
171  * Revision 1.62  1999/05/12 13:08:06  adam
172  * First version of ISAMS.
173  *
174  * Revision 1.61  1999/03/09 16:27:49  adam
175  * More work on SDRKit integration.
176  *
177  * Revision 1.60  1998/10/16 08:14:31  adam
178  * Updated record control system.
179  *
180  * Revision 1.59  1998/06/08 14:43:11  adam
181  * Added suport for EXPLAIN Proxy servers - added settings databasePath
182  * and explainDatabase to facilitate this. Increased maximum number
183  * of databases and attributes in one register.
184  *
185  * Revision 1.58  1998/05/20 10:12:16  adam
186  * Implemented automatic EXPLAIN database maintenance.
187  * Modified Zebra to work with ASN.1 compiled version of YAZ.
188  *
189  * Revision 1.57  1998/03/05 08:45:12  adam
190  * New result set model and modular ranking system. Moved towards
191  * descent server API. System information stored as "SGML" records.
192  *
193  * Revision 1.56  1998/01/12 15:04:08  adam
194  * The test option (-s) only uses read-lock (and not write lock).
195  *
196  * Revision 1.55  1997/10/27 14:33:04  adam
197  * Moved towards generic character mapping depending on "structure"
198  * field in abstract syntax file. Fixed a few memory leaks. Fixed
199  * bug with negative integers when doing searches with relational
200  * operators.
201  *
202  * Revision 1.54  1997/09/29 09:08:36  adam
203  * Revised locking system to be thread safe for the server.
204  *
205  * Revision 1.53  1997/09/25 14:54:43  adam
206  * WIN32 files lock support.
207  *
208  * Revision 1.52  1997/09/22 12:39:06  adam
209  * Added get_pos method for the ranked result sets.
210  *
211  * Revision 1.51  1997/09/18 08:59:19  adam
212  * Extra generic handle for the character mapping routines.
213  *
214  * Revision 1.50  1997/09/17 12:19:13  adam
215  * Zebra version corresponds to YAZ version 1.4.
216  * Changed Zebra server so that it doesn't depend on global common_resource.
217  *
218  * Revision 1.49  1997/09/05 15:30:08  adam
219  * Changed prototype for chr_map_input - added const.
220  * Added support for C++, headers uses extern "C" for public definitions.
221  *
222  * Revision 1.48  1997/02/12 20:39:45  adam
223  * Implemented options -f <n> that limits the log to the first <n>
224  * records.
225  * Changed some log messages also.
226  *
227  * Revision 1.47  1996/12/23 15:30:44  adam
228  * Work on truncation.
229  * Bug fix: result sets weren't deleted after server shut down.
230  *
231  * Revision 1.46  1996/11/08 11:10:19  adam
232  * Buffers used during file match got bigger.
233  * Compressed ISAM support everywhere.
234  * Bug fixes regarding masking characters in queries.
235  * Redesigned Regexp-2 queries.
236  *
237  * Revision 1.45  1996/10/29 14:09:42  adam
238  * Use of cisam system - enabled if setting isamc is 1.
239  *
240  * Revision 1.44  1996/06/06 12:08:40  quinn
241  * Added showRecord function
242  *
243  * Revision 1.43  1996/06/04  10:18:12  adam
244  * Search/scan uses character mapping module.
245  *
246  * Revision 1.42  1996/06/04  08:20:16  quinn
247  * Smallish
248  *
249  * Revision 1.41  1996/06/04  07:54:55  quinn
250  * Added output-map.
251  *
252  * Revision 1.40  1996/05/31  09:06:58  quinn
253  * Work on character-set handling
254  *
255  * Revision 1.39  1996/05/14  14:04:33  adam
256  * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
257  * is collected.
258  *
259  * Revision 1.38  1996/04/12  07:02:23  adam
260  * File update of single files.
261  *
262  * Revision 1.37  1996/03/26 16:01:13  adam
263  * New setting lockPath: directory of various lock files.
264  *
265  * Revision 1.36  1996/03/21  14:50:09  adam
266  * File update uses modify-time instead of change-time.
267  *
268  * Revision 1.35  1996/02/12  18:45:36  adam
269  * New fileVerboseFlag in record group control.
270  *
271  * Revision 1.34  1995/12/11  11:43:29  adam
272  * Locking based on fcntl instead of flock.
273  * Setting commitEnable removed. Command line option -n can be used to
274  * prevent commit if commit setting is defined in the configuration file.
275  *
276  * Revision 1.33  1995/12/08  16:22:53  adam
277  * Work on update while servers are running. Three lock files introduced.
278  * The servers reload their registers when necessary, but they don't
279  * reestablish result sets yet.
280  *
281  * Revision 1.32  1995/12/07  17:38:46  adam
282  * Work locking mechanisms for concurrent updates/commit.
283  *
284  * Revision 1.31  1995/12/06  12:41:22  adam
285  * New command 'stat' for the index program.
286  * Filenames can be read from stdin by specifying '-'.
287  * Bug fix/enhancement of the transformation from terms to regular
288  * expressons in the search engine.
289  *
290  * Revision 1.30  1995/12/05  11:25:02  adam
291  * Include of zebraver.h.
292  *
293  * Revision 1.29  1995/11/28  09:09:40  adam
294  * Zebra config renamed.
295  * Use setting 'recordId' to identify record now.
296  * Bug fix in recindex.c: rec_release_blocks was invokeded even
297  * though the blocks were already released.
298  * File traversal properly deletes records when needed.
299  *
300  * Revision 1.28  1995/11/27  13:58:53  adam
301  * New option -t. storeStore data implemented in server.
302  *
303  * Revision 1.27  1995/11/25  10:24:06  adam
304  * More record fields - they are enumerated now.
305  * New options: flagStoreData flagStoreKey.
306  *
307  * Revision 1.26  1995/11/22  17:19:17  adam
308  * Record management uses the bfile system.
309  *
310  * Revision 1.25  1995/11/21  15:29:12  adam
311  * Config file 'base' read by default by both indexer and server.
312  *
313  * Revision 1.24  1995/11/21  15:01:15  adam
314  * New general match criteria implemented.
315  * New feature: document groups.
316  *
317  * Revision 1.23  1995/11/20  16:59:45  adam
318  * New update method: the 'old' keys are saved for each records.
319  *
320  * Revision 1.22  1995/11/20  11:56:26  adam
321  * Work on new traversal.
322  *
323  * Revision 1.21  1995/11/16  15:34:55  adam
324  * Uses new record management system in both indexer and server.
325  *
326  * Revision 1.20  1995/11/15  14:46:18  adam
327  * Started work on better record management system.
328  *
329  * Revision 1.19  1995/10/27  14:00:11  adam
330  * Implemented detection of database availability.
331  *
332  * Revision 1.18  1995/10/17  18:02:08  adam
333  * New feature: databases. Implemented as prefix to words in dictionary.
334  *
335  * Revision 1.17  1995/10/13  16:01:49  adam
336  * Work on relations.
337  *
338  * Revision 1.16  1995/10/10  12:24:38  adam
339  * Temporary sort files are compressed.
340  *
341  * Revision 1.15  1995/10/04  16:57:19  adam
342  * Key input and merge sort in one pass.
343  *
344  * Revision 1.14  1995/09/29  14:01:40  adam
345  * Bug fixes.
346  *
347  * Revision 1.13  1995/09/28  14:22:56  adam
348  * Sort uses smaller temporary files.
349  *
350  * Revision 1.12  1995/09/28  12:10:32  adam
351  * Bug fixes. Field prefix used in queries.
352  *
353  * Revision 1.11  1995/09/27  12:22:28  adam
354  * More work on extract in record control.
355  * Field name is not in isam keys but in prefix in dictionary words.
356  *
357  * Revision 1.10  1995/09/14  07:48:23  adam
358  * Record control management.
359  *
360  * Revision 1.9  1995/09/11  13:09:33  adam
361  * More work on relevance feedback.
362  *
363  * Revision 1.8  1995/09/08  14:52:27  adam
364  * Minor changes. Dictionary is lower case now.
365  *
366  * Revision 1.7  1995/09/06  16:11:16  adam
367  * Option: only one word key per file.
368  *
369  * Revision 1.6  1995/09/05  15:28:39  adam
370  * More work on search engine.
371  *
372  * Revision 1.5  1995/09/04  12:33:42  adam
373  * Various cleanup. YAZ util used instead.
374  *
375  * Revision 1.4  1995/09/04  09:10:35  adam
376  * More work on index add/del/update.
377  * Merge sort implemented.
378  * Initial work on z39 server.
379  *
380  * Revision 1.3  1995/09/01  14:06:35  adam
381  * Split of work into more files.
382  *
383  * Revision 1.2  1995/09/01  10:30:24  adam
384  * More work on indexing. Not working yet.
385  *
386  * Revision 1.1  1995/08/31  14:50:24  adam
387  * New simple file index tool.
388  *
389  */