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