2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.32 1996-02-01 20:50:04 adam
8 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
9 * was never called - happens when no commands are specified.
11 * Revision 1.31 1996/01/08 19:15:46 adam
12 * New input filter that works!
14 * Revision 1.30 1995/12/12 16:00:59 adam
15 * System call sync(2) used after update/commit.
16 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
19 * Revision 1.29 1995/12/11 11:43:30 adam
20 * Locking based on fcntl instead of flock.
21 * Setting commitEnable removed. Command line option -n can be used to
22 * prevent commit if commit setting is defined in the configuration file.
24 * Revision 1.28 1995/12/08 16:22:56 adam
25 * Work on update while servers are running. Three lock files introduced.
26 * The servers reload their registers when necessary, but they don't
27 * reestablish result sets yet.
29 * Revision 1.27 1995/12/07 17:38:47 adam
30 * Work locking mechanisms for concurrent updates/commit.
32 * Revision 1.26 1995/12/06 12:41:23 adam
33 * New command 'stat' for the index program.
34 * Filenames can be read from stdin by specifying '-'.
35 * Bug fix/enhancement of the transformation from terms to regular
36 * expressons in the search engine.
38 * Revision 1.25 1995/12/01 16:24:39 adam
39 * Commit files use separate meta file area.
41 * Revision 1.24 1995/11/30 17:01:38 adam
42 * New setting commitCache: points to commit directories/files.
43 * New command commit: commits at the end of a zebraidx run.
45 * Revision 1.23 1995/11/30 08:34:31 adam
46 * Started work on commit facility.
47 * Changed a few malloc/free to xmalloc/xfree.
49 * Revision 1.22 1995/11/28 09:09:42 adam
50 * Zebra config renamed.
51 * Use setting 'recordId' to identify record now.
52 * Bug fix in recindex.c: rec_release_blocks was invokeded even
53 * though the blocks were already released.
54 * File traversal properly deletes records when needed.
56 * Revision 1.21 1995/11/27 14:27:39 adam
57 * Renamed 'update' command to 'dir'.
59 * Revision 1.20 1995/11/27 13:58:53 adam
60 * New option -t. storeStore data implemented in server.
62 * Revision 1.19 1995/11/25 10:24:06 adam
63 * More record fields - they are enumerated now.
64 * New options: flagStoreData flagStoreKey.
66 * Revision 1.18 1995/11/22 17:19:17 adam
67 * Record management uses the bfile system.
69 * Revision 1.17 1995/11/21 15:01:16 adam
70 * New general match criteria implemented.
71 * New feature: document groups.
73 * Revision 1.16 1995/11/20 11:56:27 adam
74 * Work on new traversal.
76 * Revision 1.15 1995/11/01 16:25:51 quinn
77 * *** empty log message ***
79 * Revision 1.14 1995/10/17 18:02:09 adam
80 * New feature: databases. Implemented as prefix to words in dictionary.
82 * Revision 1.13 1995/10/10 12:24:39 adam
83 * Temporary sort files are compressed.
85 * Revision 1.12 1995/10/04 16:57:20 adam
86 * Key input and merge sort in one pass.
88 * Revision 1.11 1995/09/29 14:01:45 adam
91 * Revision 1.10 1995/09/28 14:22:57 adam
92 * Sort uses smaller temporary files.
94 * Revision 1.9 1995/09/14 07:48:24 adam
95 * Record control management.
97 * Revision 1.8 1995/09/06 16:11:18 adam
98 * Option: only one word key per file.
100 * Revision 1.7 1995/09/05 15:28:39 adam
101 * More work on search engine.
103 * Revision 1.6 1995/09/04 12:33:43 adam
104 * Various cleanup. YAZ util used instead.
106 * Revision 1.5 1995/09/04 09:10:39 adam
107 * More work on index add/del/update.
108 * Merge sort implemented.
109 * Initial work on z39 server.
111 * Revision 1.4 1995/09/01 14:06:36 adam
112 * Split of work into more files.
114 * Revision 1.3 1995/09/01 10:57:07 adam
117 * Revision 1.2 1995/09/01 10:30:24 adam
118 * More work on indexing. Not working yet.
120 * Revision 1.1 1995/08/31 14:50:24 adam
121 * New simple file index tool.
128 #include <alexutil.h>
133 size_t mem_max = 4*1024*1024;
134 extern char *data1_tabpath;
136 int main (int argc, char **argv)
141 char *configName = NULL;
143 int disableCommit = 0;
145 struct recordGroup rGroupDef;
147 rGroupDef.groupName = NULL;
148 rGroupDef.databaseName = NULL;
149 rGroupDef.path = NULL;
150 rGroupDef.recordId = NULL;
151 rGroupDef.recordType = NULL;
152 rGroupDef.flagStoreData = -1;
153 rGroupDef.flagStoreKeys = -1;
158 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
160 " update <dir> Update index with files below <dir>.\n"
161 " If <dir> is empty filenames are read from stdin.\n"
162 " delete <dir> Delete index with files below <dir>.\n"
163 " commit Commit changes\n"
165 " -t <type> Index files as <type> (grs or text).\n"
166 " -c <config> Read configuration file <config>.\n"
167 " -g <group> Index files according to group settings.\n"
168 " -d <database> Records belong to Z39.50 database <database>.\n"
169 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
170 " -n Don't use shadow system\n"
171 " -v <level> Set logging to <level>.\n");
174 while ((ret = options ("t:c:g:d:m:v:n", argv, argc, &arg)) != -2)
179 if(cmd == 0) /* command */
181 if (!common_resource)
183 common_resource = res_open (configName ?
184 configName : FNAME_CONFIG);
185 if (!common_resource)
187 logf (LOG_FATAL, "Cannot open resource `%s'",
191 data1_tabpath = res_get (common_resource, "profilePath");
193 if (!strcmp (arg, "update"))
195 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
197 else if (!strcmp (arg, "commit"))
200 rval = res_get (common_resource, "shadow");
205 logf (LOG_FATAL, "Cannot perform commit");
206 logf (LOG_FATAL, "No shadow area defined");
209 if (bf_commitExists ())
211 logf (LOG_LOG, "Commit start");
212 zebraIndexLockMsg ("c");
214 logf (LOG_LOG, "Commit execute");
217 zebraIndexLockMsg ("d");
219 logf (LOG_LOG, "Commit clean");
223 logf (LOG_LOG, "Nothing to commit");
225 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
228 rval = res_get (common_resource, "shadow");
232 zebraIndexLockMsg ("r");
238 logf (LOG_FATAL, "Unknown command: %s", arg);
244 struct recordGroup rGroup;
247 rval = res_get (common_resource, "shadow");
248 if (rval && *rval && !disableCommit)
251 zebraIndexLockMsg ("r");
256 zebraIndexLockMsg ("w");
260 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
265 logf (LOG_LOG, "Updating %s", rGroup.path);
266 repositoryUpdate (&rGroup);
270 logf (LOG_LOG, "Deleting %s", rGroup.path);
271 repositoryDelete (&rGroup);
274 nsections = key_close ();
277 logf (LOG_LOG, "Merging with index");
278 key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections,
286 log_init (log_mask_str(arg), prog, NULL);
290 mem_max = 1024*1024*atoi(arg);
294 rGroupDef.databaseName = arg;
298 rGroupDef.groupName = arg;
303 rGroupDef.recordType = arg;
308 logf (LOG_FATAL, "Unknown option '-%s'", arg);