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