2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.31 1996-01-08 19:15:46 adam
8 * New input filter that works!
10 * Revision 1.30 1995/12/12 16:00:59 adam
11 * System call sync(2) used after update/commit.
12 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
15 * Revision 1.29 1995/12/11 11:43:30 adam
16 * Locking based on fcntl instead of flock.
17 * Setting commitEnable removed. Command line option -n can be used to
18 * prevent commit if commit setting is defined in the configuration file.
20 * Revision 1.28 1995/12/08 16:22:56 adam
21 * Work on update while servers are running. Three lock files introduced.
22 * The servers reload their registers when necessary, but they don't
23 * reestablish result sets yet.
25 * Revision 1.27 1995/12/07 17:38:47 adam
26 * Work locking mechanisms for concurrent updates/commit.
28 * Revision 1.26 1995/12/06 12:41:23 adam
29 * New command 'stat' for the index program.
30 * Filenames can be read from stdin by specifying '-'.
31 * Bug fix/enhancement of the transformation from terms to regular
32 * expressons in the search engine.
34 * Revision 1.25 1995/12/01 16:24:39 adam
35 * Commit files use separate meta file area.
37 * Revision 1.24 1995/11/30 17:01:38 adam
38 * New setting commitCache: points to commit directories/files.
39 * New command commit: commits at the end of a zebraidx run.
41 * Revision 1.23 1995/11/30 08:34:31 adam
42 * Started work on commit facility.
43 * Changed a few malloc/free to xmalloc/xfree.
45 * Revision 1.22 1995/11/28 09:09:42 adam
46 * Zebra config renamed.
47 * Use setting 'recordId' to identify record now.
48 * Bug fix in recindex.c: rec_release_blocks was invokeded even
49 * though the blocks were already released.
50 * File traversal properly deletes records when needed.
52 * Revision 1.21 1995/11/27 14:27:39 adam
53 * Renamed 'update' command to 'dir'.
55 * Revision 1.20 1995/11/27 13:58:53 adam
56 * New option -t. storeStore data implemented in server.
58 * Revision 1.19 1995/11/25 10:24:06 adam
59 * More record fields - they are enumerated now.
60 * New options: flagStoreData flagStoreKey.
62 * Revision 1.18 1995/11/22 17:19:17 adam
63 * Record management uses the bfile system.
65 * Revision 1.17 1995/11/21 15:01:16 adam
66 * New general match criteria implemented.
67 * New feature: document groups.
69 * Revision 1.16 1995/11/20 11:56:27 adam
70 * Work on new traversal.
72 * Revision 1.15 1995/11/01 16:25:51 quinn
73 * *** empty log message ***
75 * Revision 1.14 1995/10/17 18:02:09 adam
76 * New feature: databases. Implemented as prefix to words in dictionary.
78 * Revision 1.13 1995/10/10 12:24:39 adam
79 * Temporary sort files are compressed.
81 * Revision 1.12 1995/10/04 16:57:20 adam
82 * Key input and merge sort in one pass.
84 * Revision 1.11 1995/09/29 14:01:45 adam
87 * Revision 1.10 1995/09/28 14:22:57 adam
88 * Sort uses smaller temporary files.
90 * Revision 1.9 1995/09/14 07:48:24 adam
91 * Record control management.
93 * Revision 1.8 1995/09/06 16:11:18 adam
94 * Option: only one word key per file.
96 * Revision 1.7 1995/09/05 15:28:39 adam
97 * More work on search engine.
99 * Revision 1.6 1995/09/04 12:33:43 adam
100 * Various cleanup. YAZ util used instead.
102 * Revision 1.5 1995/09/04 09:10:39 adam
103 * More work on index add/del/update.
104 * Merge sort implemented.
105 * Initial work on z39 server.
107 * Revision 1.4 1995/09/01 14:06:36 adam
108 * Split of work into more files.
110 * Revision 1.3 1995/09/01 10:57:07 adam
113 * Revision 1.2 1995/09/01 10:30:24 adam
114 * More work on indexing. Not working yet.
116 * Revision 1.1 1995/08/31 14:50:24 adam
117 * New simple file index tool.
124 #include <alexutil.h>
129 size_t mem_max = 4*1024*1024;
130 extern char *data1_tabpath;
132 int main (int argc, char **argv)
137 char *configName = NULL;
139 int disableCommit = 0;
141 struct recordGroup rGroupDef;
143 rGroupDef.groupName = NULL;
144 rGroupDef.databaseName = NULL;
145 rGroupDef.path = NULL;
146 rGroupDef.recordId = NULL;
147 rGroupDef.recordType = NULL;
148 rGroupDef.flagStoreData = -1;
149 rGroupDef.flagStoreKeys = -1;
154 fprintf (stderr, "zebraidx [options] command <dir> ...\n"
156 " update <dir> Update index with files below <dir>.\n"
157 " If <dir> is empty filenames are read from stdin.\n"
158 " delete <dir> Delete index with files below <dir>.\n"
159 " commit Commit changes\n"
161 " -t <type> Index files as <type> (grs or text).\n"
162 " -c <config> Read configuration file <config>.\n"
163 " -g <group> Index files according to group settings.\n"
164 " -d <database> Records belong to Z39.50 database <database>.\n"
165 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
166 " -n Don't use shadow system\n"
167 " -v <level> Set logging to <level>.\n");
170 while ((ret = options ("t:c:g:d:m:v:n", argv, argc, &arg)) != -2)
175 if(cmd == 0) /* command */
177 if (!common_resource)
179 common_resource = res_open (configName ?
180 configName : FNAME_CONFIG);
181 if (!common_resource)
183 logf (LOG_FATAL, "Cannot open resource `%s'",
187 data1_tabpath = res_get (common_resource, "profilePath");
189 if (!strcmp (arg, "update"))
191 else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
193 else if (!strcmp (arg, "commit"))
196 rval = res_get (common_resource, "shadow");
201 logf (LOG_FATAL, "Cannot perform commit");
202 logf (LOG_FATAL, "No shadow area defined");
205 if (bf_commitExists ())
207 logf (LOG_LOG, "Commit start");
208 zebraIndexLockMsg ("c");
210 logf (LOG_LOG, "Commit execute");
213 zebraIndexLockMsg ("d");
215 logf (LOG_LOG, "Commit clean");
219 logf (LOG_LOG, "Nothing to commit");
221 else if (!strcmp (arg, "stat") || !strcmp (arg, "status"))
224 rval = res_get (common_resource, "shadow");
228 zebraIndexLockMsg ("r");
234 logf (LOG_FATAL, "Unknown command: %s", arg);
240 struct recordGroup rGroup;
243 rval = res_get (common_resource, "shadow");
244 if (rval && *rval && !disableCommit)
247 zebraIndexLockMsg ("r");
252 zebraIndexLockMsg ("w");
256 memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
261 logf (LOG_LOG, "Updating %s", rGroup.path);
262 repositoryUpdate (&rGroup);
266 logf (LOG_LOG, "Deleting %s", rGroup.path);
267 repositoryDelete (&rGroup);
270 nsections = key_close ();
273 logf (LOG_LOG, "Merging with index");
274 key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections,
282 log_init (log_mask_str(arg), prog, NULL);
286 mem_max = 1024*1024*atoi(arg);
290 rGroupDef.databaseName = arg;
294 rGroupDef.groupName = arg;
299 rGroupDef.recordType = arg;
304 logf (LOG_FATAL, "Unknown option '-%s'", arg);