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