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