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