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