2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.70 1999-09-07 07:19:21 adam
8 * Work on character mapping. Implemented replace rules.
10 * Revision 1.69 1999/07/21 08:31:33 adam
11 * More version info on WIN32.
13 * Revision 1.68 1999/07/14 10:59:26 adam
14 * Changed functions isc_getmethod, isams_getmethod.
15 * Improved fatal error handling (such as missing EXPLAIN schema).
17 * Revision 1.67 1999/07/06 12:28:04 adam
18 * Updated record index structure. Format includes version ID. Compression
19 * algorithm ID is stored for each record block.
21 * Revision 1.66 1999/06/25 13:48:02 adam
22 * Updated MSVC project files.
23 * Added BZIP2 record compression (not very well tested).
25 * Revision 1.65 1999/05/20 12:57:18 adam
26 * Implemented TCL filter. Updated recctrl system.
28 * Revision 1.64 1999/05/15 14:36:38 adam
29 * Updated dictionary. Implemented "compression" of dictionary.
31 * Revision 1.63 1999/03/09 16:27:49 adam
32 * More work on SDRKit integration.
34 * Revision 1.62 1999/02/18 15:01:24 adam
37 * Revision 1.61 1999/02/02 14:51:00 adam
38 * Updated WIN32 code specific sections. Changed header.
40 * Revision 1.60 1998/10/28 10:54:39 adam
43 * Revision 1.59 1998/10/16 08:14:32 adam
44 * Updated record control system.
46 * Revision 1.58 1998/06/08 14:43:13 adam
47 * Added suport for EXPLAIN Proxy servers - added settings databasePath
48 * and explainDatabase to facilitate this. Increased maximum number
49 * of databases and attributes in one register.
51 * Revision 1.57 1998/05/20 10:12:18 adam
52 * Implemented automatic EXPLAIN database maintenance.
53 * Modified Zebra to work with ASN.1 compiled version of YAZ.
55 * Revision 1.56 1998/03/05 08:45:12 adam
56 * New result set model and modular ranking system. Moved towards
57 * descent server API. System information stored as "SGML" records.
59 * Revision 1.55 1998/01/26 10:37:34 adam
62 * Revision 1.54 1998/01/12 15:04:08 adam
63 * The test option (-s) only uses read-lock (and not write lock).
65 * Revision 1.53 1997/11/18 10:05:08 adam
66 * Changed character map facility so that admin can specify character
67 * mapping files for each register type, w, p, etc.
69 * Revision 1.52 1997/10/31 12:34:04 adam
70 * Added missing nmem_init.
72 * Revision 1.51 1997/10/27 14:33:05 adam
73 * Moved towards generic character mapping depending on "structure"
74 * field in abstract syntax file. Fixed a few memory leaks. Fixed
75 * bug with negative integers when doing searches with relational
78 * Revision 1.50 1997/09/25 14:55:52 adam
81 * Revision 1.49 1997/09/17 12:19:15 adam
82 * Zebra version corresponds to YAZ version 1.4.
83 * Changed Zebra server so that it doesn't depend on global common_resource.
85 * Revision 1.48 1997/09/09 13:38:08 adam
86 * Partial port to WIN95/NT.
88 * Revision 1.47 1997/02/12 20:39:46 adam
89 * Implemented options -f <n> that limits the log to the first <n>
91 * Changed some log messages also.
93 * Revision 1.46 1997/02/10 10:20:13 adam
94 * Flag fileVerboseFlag set to 0 (default).
96 * Revision 1.45 1996/11/08 11:10:26 adam
97 * Buffers used during file match got bigger.
98 * Compressed ISAM support everywhere.
99 * Bug fixes regarding masking characters in queries.
100 * Redesigned Regexp-2 queries.
102 * Revision 1.44 1996/10/29 14:09:48 adam
103 * Use of cisam system - enabled if setting isamc is 1.
105 * Revision 1.43 1996/06/06 12:08:42 quinn
106 * Added showRecord function
108 * Revision 1.42 1996/05/31 09:07:01 quinn
109 * Work on character-set handling
111 * Revision 1.41 1996/05/14 14:04:34 adam
112 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
115 * Revision 1.40 1996/04/26 10:00:23 adam
116 * Added option -V to zebraidx to display version information.
117 * Removed stupid warnings from file update.
119 * Revision 1.39 1996/04/09 10:05:21 adam
120 * Bug fix: prev_name buffer possibly too small; allocated in key_file_init.
122 * Revision 1.38 1996/03/26 16:01:14 adam
123 * New setting lockPath: directory of various lock files.
125 * Revision 1.37 1996/03/19 12:43:26 adam
126 * Bug fix: File update traversal didn't handle trailing slashes correctly.
127 * Bug fix: Update of sub directory groups wasn't handled correctly.
129 * Revision 1.36 1996/02/12 18:45:37 adam
130 * New fileVerboseFlag in record group control.
132 * Revision 1.35 1996/02/12 15:56:11 adam
133 * New code command: unread.
135 * Revision 1.34 1996/02/07 14:06:39 adam
136 * Better progress report during register merge.
137 * New command: clean - removes temporary shadow files.
139 * Revision 1.33 1996/02/06 17:11:18 adam
142 * Revision 1.32 1996/02/01 20:50:04 adam
143 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
144 * was never called - happens when no commands are specified.
146 * Revision 1.31 1996/01/08 19:15:46 adam
147 * New input filter that works!
149 * Revision 1.30 1995/12/12 16:00:59 adam
150 * System call sync(2) used after update/commit.
151 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
154 * Revision 1.29 1995/12/11 11:43:30 adam
155 * Locking based on fcntl instead of flock.
156 * Setting commitEnable removed. Command line option -n can be used to
157 * prevent commit if commit setting is defined in the configuration file.
159 * Revision 1.28 1995/12/08 16:22:56 adam
160 * Work on update while servers are running. Three lock files introduced.
161 * The servers reload their registers when necessary, but they don't
162 * reestablish result sets yet.
164 * Revision 1.27 1995/12/07 17:38:47 adam
165 * Work locking mechanisms for concurrent updates/commit.
167 * Revision 1.26 1995/12/06 12:41:23 adam
168 * New command 'stat' for the index program.
169 * Filenames can be read from stdin by specifying '-'.
170 * Bug fix/enhancement of the transformation from terms to regular
171 * expressons in the search engine.
173 * Revision 1.25 1995/12/01 16:24:39 adam
174 * Commit files use separate meta file area.
176 * Revision 1.24 1995/11/30 17:01:38 adam
177 * New setting commitCache: points to commit directories/files.
178 * New command commit: commits at the end of a zebraidx run.
180 * Revision 1.23 1995/11/30 08:34:31 adam
181 * Started work on commit facility.
182 * Changed a few malloc/free to xmalloc/xfree.
184 * Revision 1.22 1995/11/28 09:09:42 adam
185 * Zebra config renamed.
186 * Use setting 'recordId' to identify record now.
187 * Bug fix in recindex.c: rec_release_blocks was invokeded even
188 * though the blocks were already released.
189 * File traversal properly deletes records when needed.
191 * Revision 1.21 1995/11/27 14:27:39 adam
192 * Renamed 'update' command to 'dir'.
194 * Revision 1.20 1995/11/27 13:58:53 adam
195 * New option -t. storeStore data implemented in server.
197 * Revision 1.19 1995/11/25 10:24:06 adam
198 * More record fields - they are enumerated now.
199 * New options: flagStoreData flagStoreKey.
201 * Revision 1.18 1995/11/22 17:19:17 adam
202 * Record management uses the bfile system.
204 * Revision 1.17 1995/11/21 15:01:16 adam
205 * New general match criteria implemented.
206 * New feature: document groups.
208 * Revision 1.16 1995/11/20 11:56:27 adam
209 * Work on new traversal.
211 * Revision 1.15 1995/11/01 16:25:51 quinn
212 * *** empty log message ***
214 * Revision 1.14 1995/10/17 18:02:09 adam
215 * New feature: databases. Implemented as prefix to words in dictionary.
217 * Revision 1.13 1995/10/10 12:24:39 adam
218 * Temporary sort files are compressed.
220 * Revision 1.12 1995/10/04 16:57:20 adam
221 * Key input and merge sort in one pass.
223 * Revision 1.11 1995/09/29 14:01:45 adam
226 * Revision 1.10 1995/09/28 14:22:57 adam
227 * Sort uses smaller temporary files.
229 * Revision 1.9 1995/09/14 07:48:24 adam
230 * Record control management.
232 * Revision 1.8 1995/09/06 16:11:18 adam
233 * Option: only one word key per file.
235 * Revision 1.7 1995/09/05 15:28:39 adam
236 * More work on search engine.
238 * Revision 1.6 1995/09/04 12:33:43 adam
239 * Various cleanup. YAZ util used instead.
241 * Revision 1.5 1995/09/04 09:10:39 adam
242 * More work on index add/del/update.
243 * Merge sort implemented.
244 * Initial work on z39 server.
246 * Revision 1.4 1995/09/01 14:06:36 adam
247 * Split of work into more files.
249 * Revision 1.3 1995/09/01 10:57:07 adam
252 * Revision 1.2 1995/09/01 10:30:24 adam
253 * More work on indexing. Not working yet.
255 * Revision 1.1 1995/08/31 14:50:24 adam
256 * New simple file index tool.
269 #include "recindex.h"
276 #include "zebrasdr.h"
281 Res common_resource = 0;
283 int main (int argc, char **argv)
288 char *configName = NULL;
290 int disableCommit = 0;
293 struct recordGroup rGroupDef;
299 rGroupDef.useSDR = 0;
301 rGroupDef.groupName = NULL;
302 rGroupDef.databaseName = NULL;
303 rGroupDef.path = NULL;
304 rGroupDef.recordId = NULL;
305 rGroupDef.recordType = NULL;
306 rGroupDef.flagStoreData = -1;
307 rGroupDef.flagStoreKeys = -1;
308 rGroupDef.flagRw = 1;
309 rGroupDef.databaseNamePath = 0;
310 rGroupDef.explainDatabase = 0;
311 rGroupDef.fileVerboseLimit = 100000;
312 rGroupDef.zebra_maps = NULL;
313 rGroupDef.dh = data1_create ();
314 rGroupDef.recTypes = recTypes_init (rGroupDef.dh);
315 recTypes_default_handlers (rGroupDef.recTypes);
320 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
322 " update <dir> Update index with files below <dir>.\n"
323 " If <dir> is empty filenames are read from stdin.\n"
324 " delete <dir> Delete index with files below <dir>.\n"
325 " commit Commit changes\n"
326 " clean Clean shadow files\n"
328 " -t <type> Index files as <type> (grs or text).\n"
329 " -c <config> Read configuration file <config>.\n"
330 " -g <group> Index files according to group settings.\n"
331 " -d <database> Records belong to Z39.50 database <database>.\n"
332 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
333 " -n Don't use shadow system.\n"
334 " -s Show analysis on stdout, but do no work.\n"
335 " -v <level> Set logging to <level>.\n"
336 " -l <file> Write log to <file>.\n"
337 " -f <n> Display information for the first <n> records.\n"
341 " -V Show version.\n"
345 while ((ret = options ("sVt:c:g:d:m:v:nf:l:"
349 , argv, argc, &arg)) != -2)
354 if(cmd == 0) /* command */
356 if (!common_resource)
358 logf (LOG_LOG, "zebra version %s %s",
359 ZEBRAVER, ZEBRADATE);
360 common_resource = res_open (configName ?
361 configName : FNAME_CONFIG);
362 if (!common_resource)
364 logf (LOG_FATAL, "cannot configuration file `%s'",
368 data1_set_tabpath (rGroupDef.dh, res_get (common_resource,
372 bfs_create (res_get (common_resource, "register"));
374 bf_lockDir (rGroupDef.bfs,
375 res_get (common_resource, "lockDir"));
376 rGroupDef.zebra_maps = zebra_maps_open (common_resource);
378 if (!strcmp (arg, "update"))
380 else if (!strcmp (arg, "update1"))
382 else if (!strcmp (arg, "update2"))
384 else if (!strcmp (arg, "dump"))
386 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
388 else if (!strcmp (arg, "commit"))
390 rval = res_get (common_resource, "shadow");
391 zebraIndexLock (rGroupDef.bfs, 1, rval);
393 bf_cache (rGroupDef.bfs, rval);
396 logf (LOG_FATAL, "Cannot perform commit");
397 logf (LOG_FATAL, "No shadow area defined");
400 if (bf_commitExists (rGroupDef.bfs))
402 logf (LOG_LOG, "commit start");
403 zebraIndexLockMsg ("c");
405 logf (LOG_LOG, "commit execute");
406 bf_commitExec (rGroupDef.bfs);
410 zebraIndexLockMsg ("d");
412 logf (LOG_LOG, "commit clean");
413 bf_commitClean (rGroupDef.bfs, rval);
416 logf (LOG_LOG, "cothing to commit");
418 else if (!strcmp (arg, "clean"))
420 rval = res_get (common_resource, "shadow");
421 zebraIndexLock (rGroupDef.bfs, 1, rval);
422 if (bf_commitExists (rGroupDef.bfs))
424 zebraIndexLockMsg ("d");
426 logf (LOG_LOG, "commit clean");
427 bf_commitClean (rGroupDef.bfs, rval);
430 logf (LOG_LOG, "nothing to clean");
432 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
435 rval = res_get (common_resource, "shadow");
436 zebraIndexLock (rGroupDef.bfs, 0, rval);
439 bf_cache (rGroupDef.bfs, rval);
440 zebraIndexLockMsg ("r");
442 records = rec_open (rGroupDef.bfs, 0, 0);
443 rec_prstat (records);
444 rec_close (&records);
445 inv_prstat (rGroupDef.bfs);
447 else if (!strcmp (arg, "compact"))
449 rval = res_get (common_resource, "shadow");
450 zebraIndexLock (rGroupDef.bfs, 0, rval);
453 bf_cache (rGroupDef.bfs, rval);
454 zebraIndexLockMsg ("r");
456 inv_compact(rGroupDef.bfs);
460 logf (LOG_FATAL, "unknown command: %s", arg);
466 struct recordGroup rGroup;
468 rval = res_get (common_resource, "shadow");
469 zebraIndexLock (rGroupDef.bfs, 0, rval);
470 if (rGroupDef.flagRw)
472 if (rval && *rval && !disableCommit)
474 bf_cache (rGroupDef.bfs, rval);
475 zebraIndexLockMsg ("r");
479 bf_cache (rGroupDef.bfs, 0);
480 zebraIndexLockMsg ("w");
484 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
489 if (!key_open (&rGroup, mem_max))
491 logf (LOG_LOG, "updating %s", rGroup.path);
492 repositoryUpdate (&rGroup);
493 nsections = key_close (&rGroup);
497 if (!key_open (&rGroup, mem_max))
499 logf (LOG_LOG, "updating (pass 1) %s", rGroup.path);
500 repositoryUpdate (&rGroup);
506 if (!key_open (&rGroup,mem_max))
508 logf (LOG_LOG, "deleting %s", rGroup.path);
509 repositoryDelete (&rGroup);
510 nsections = key_close (&rGroup);
514 logf (LOG_LOG, "dumping %s", rGroup.path);
515 repositoryShow (&rGroup);
527 logf (LOG_LOG, "merging with index");
528 key_input (rGroup.bfs, nsections, 60);
533 log_event_end (NULL, NULL);
538 fprintf (stderr, "Zebra %s %s\n", ZEBRAVER, ZEBRADATE);
539 fprintf (stderr, " (C) 1994-1999, Index Data ApS\n");
542 fprintf (stderr, " WIN32 Debug\n");
544 fprintf (stderr, " WIN32 Release\n");
548 fprintf (stderr, "libbzip2\n"
549 " (C) 1996-1999 Julian R Seward. All rights reserved.\n");
553 log_init_level (log_mask_str(arg));
557 mem_max = 1024*1024*atoi(arg);
559 rGroupDef.databaseName = arg;
561 rGroupDef.flagRw = 0;
563 rGroupDef.groupName = arg;
565 rGroupDef.fileVerboseLimit = atoi(arg);
569 rGroupDef.recordType = arg;
574 rGroupDef.useSDR = 1;
577 logf (LOG_WARN, "unknown option '-%s'", arg);
579 recTypes_destroy (rGroupDef.recTypes);
583 bfs_destroy (rGroupDef.bfs);
585 data1_destroy (rGroupDef.dh);