2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.35 1996-02-12 15:56:11 adam
8 * New code command: unread.
10 * Revision 1.34 1996/02/07 14:06:39 adam
11 * Better progress report during register merge.
12 * New command: clean - removes temporary shadow files.
14 * Revision 1.33 1996/02/06 17:11:18 adam
17 * Revision 1.32 1996/02/01 20:50:04 adam
18 * Bug fix: zebraIndexUnlock was always called even though zebraIndexLock
19 * was never called - happens when no commands are specified.
21 * Revision 1.31 1996/01/08 19:15:46 adam
22 * New input filter that works!
24 * Revision 1.30 1995/12/12 16:00:59 adam
25 * System call sync(2) used after update/commit.
26 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
29 * Revision 1.29 1995/12/11 11:43:30 adam
30 * Locking based on fcntl instead of flock.
31 * Setting commitEnable removed. Command line option -n can be used to
32 * prevent commit if commit setting is defined in the configuration file.
34 * Revision 1.28 1995/12/08 16:22:56 adam
35 * Work on update while servers are running. Three lock files introduced.
36 * The servers reload their registers when necessary, but they don't
37 * reestablish result sets yet.
39 * Revision 1.27 1995/12/07 17:38:47 adam
40 * Work locking mechanisms for concurrent updates/commit.
42 * Revision 1.26 1995/12/06 12:41:23 adam
43 * New command 'stat' for the index program.
44 * Filenames can be read from stdin by specifying '-'.
45 * Bug fix/enhancement of the transformation from terms to regular
46 * expressons in the search engine.
48 * Revision 1.25 1995/12/01 16:24:39 adam
49 * Commit files use separate meta file area.
51 * Revision 1.24 1995/11/30 17:01:38 adam
52 * New setting commitCache: points to commit directories/files.
53 * New command commit: commits at the end of a zebraidx run.
55 * Revision 1.23 1995/11/30 08:34:31 adam
56 * Started work on commit facility.
57 * Changed a few malloc/free to xmalloc/xfree.
59 * Revision 1.22 1995/11/28 09:09:42 adam
60 * Zebra config renamed.
61 * Use setting 'recordId' to identify record now.
62 * Bug fix in recindex.c: rec_release_blocks was invokeded even
63 * though the blocks were already released.
64 * File traversal properly deletes records when needed.
66 * Revision 1.21 1995/11/27 14:27:39 adam
67 * Renamed 'update' command to 'dir'.
69 * Revision 1.20 1995/11/27 13:58:53 adam
70 * New option -t. storeStore data implemented in server.
72 * Revision 1.19 1995/11/25 10:24:06 adam
73 * More record fields - they are enumerated now.
74 * New options: flagStoreData flagStoreKey.
76 * Revision 1.18 1995/11/22 17:19:17 adam
77 * Record management uses the bfile system.
79 * Revision 1.17 1995/11/21 15:01:16 adam
80 * New general match criteria implemented.
81 * New feature: document groups.
83 * Revision 1.16 1995/11/20 11:56:27 adam
84 * Work on new traversal.
86 * Revision 1.15 1995/11/01 16:25:51 quinn
87 * *** empty log message ***
89 * Revision 1.14 1995/10/17 18:02:09 adam
90 * New feature: databases. Implemented as prefix to words in dictionary.
92 * Revision 1.13 1995/10/10 12:24:39 adam
93 * Temporary sort files are compressed.
95 * Revision 1.12 1995/10/04 16:57:20 adam
96 * Key input and merge sort in one pass.
98 * Revision 1.11 1995/09/29 14:01:45 adam
101 * Revision 1.10 1995/09/28 14:22:57 adam
102 * Sort uses smaller temporary files.
104 * Revision 1.9 1995/09/14 07:48:24 adam
105 * Record control management.
107 * Revision 1.8 1995/09/06 16:11:18 adam
108 * Option: only one word key per file.
110 * Revision 1.7 1995/09/05 15:28:39 adam
111 * More work on search engine.
113 * Revision 1.6 1995/09/04 12:33:43 adam
114 * Various cleanup. YAZ util used instead.
116 * Revision 1.5 1995/09/04 09:10:39 adam
117 * More work on index add/del/update.
118 * Merge sort implemented.
119 * Initial work on z39 server.
121 * Revision 1.4 1995/09/01 14:06:36 adam
122 * Split of work into more files.
124 * Revision 1.3 1995/09/01 10:57:07 adam
127 * Revision 1.2 1995/09/01 10:30:24 adam
128 * More work on indexing. Not working yet.
130 * Revision 1.1 1995/08/31 14:50:24 adam
131 * New simple file index tool.
138 #include <alexutil.h>
143 size_t mem_max = 4*1024*1024;
144 extern char *data1_tabpath;
146 static void abort_func (int level, const char *msg, void *info)
148 if (level & LOG_FATAL)
152 int main (int argc, char **argv)
157 char *configName = NULL;
159 int disableCommit = 0;
161 struct recordGroup rGroupDef;
163 rGroupDef.groupName = NULL;
164 rGroupDef.databaseName = NULL;
165 rGroupDef.path = NULL;
166 rGroupDef.recordId = NULL;
167 rGroupDef.recordType = NULL;
168 rGroupDef.flagStoreData = -1;
169 rGroupDef.flagStoreKeys = -1;
174 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
176 " update <dir> Update index with files below <dir>.\n"
177 " If <dir> is empty filenames are read from stdin.\n"
178 " delete <dir> Delete index with files below <dir>.\n"
179 " commit Commit changes\n"
180 " clean Clean shadow files\n"
182 " -t <type> Index files as <type> (grs or text).\n"
183 " -c <config> Read configuration file <config>.\n"
184 " -g <group> Index files according to group settings.\n"
185 " -d <database> Records belong to Z39.50 database <database>.\n"
186 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
187 " -n Don't use shadow system\n"
188 " -v <level> Set logging to <level>.\n");
191 log_event_end (abort_func, NULL);
192 while ((ret = options ("t:c:g:d:m:v:n", argv, argc, &arg)) != -2)
197 if(cmd == 0) /* command */
199 if (!common_resource)
201 common_resource = res_open (configName ?
202 configName : FNAME_CONFIG);
203 if (!common_resource)
205 logf (LOG_FATAL, "Cannot open resource `%s'",
209 data1_tabpath = res_get (common_resource, "profilePath");
211 if (!strcmp (arg, "update"))
213 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
215 else if (!strcmp (arg, "commit"))
218 rval = res_get (common_resource, "shadow");
223 logf (LOG_FATAL, "Cannot perform commit");
224 logf (LOG_FATAL, "No shadow area defined");
227 if (bf_commitExists ())
229 logf (LOG_LOG, "Commit start");
230 zebraIndexLockMsg ("c");
232 logf (LOG_LOG, "Commit execute");
235 zebraIndexLockMsg ("d");
237 logf (LOG_LOG, "Commit clean");
241 logf (LOG_LOG, "Nothing to commit");
243 else if (!strcmp (arg, "clean"))
246 if (bf_commitExists ())
248 zebraIndexLockMsg ("d");
250 logf (LOG_LOG, "Commit clean");
254 logf (LOG_LOG, "Nothing to clean");
256 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
259 rval = res_get (common_resource, "shadow");
263 zebraIndexLockMsg ("r");
269 logf (LOG_FATAL, "Unknown command: %s", arg);
275 struct recordGroup rGroup;
278 rval = res_get (common_resource, "shadow");
279 if (rval && *rval && !disableCommit)
282 zebraIndexLockMsg ("r");
287 zebraIndexLockMsg ("w");
291 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
296 logf (LOG_LOG, "Updating %s", rGroup.path);
297 repositoryUpdate (&rGroup);
301 logf (LOG_LOG, "Deleting %s", rGroup.path);
302 repositoryDelete (&rGroup);
305 nsections = key_close ();
308 logf (LOG_LOG, "Merging with index");
309 key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections,
317 log_init (log_mask_str(arg), prog, NULL);
321 mem_max = 1024*1024*atoi(arg);
325 rGroupDef.databaseName = arg;
329 rGroupDef.groupName = arg;
334 rGroupDef.recordType = arg;
339 logf (LOG_FATAL, "Unknown option '-%s'", arg);