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