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