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