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