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