2 * Copyright (C) 1995-1998, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.57 1998-04-03 14:45:18 adam
8 * Fixed setting of last_in_set in bend_fetch.
10 * Revision 1.56 1998/03/05 08:45:13 adam
11 * New result set model and modular ranking system. Moved towards
12 * descent server API. System information stored as "SGML" records.
14 * Revision 1.55 1998/02/10 12:03:06 adam
17 * Revision 1.54 1998/01/29 13:39:13 adam
18 * Compress ISAM is default.
20 * Revision 1.53 1998/01/12 15:04:09 adam
21 * The test option (-s) only uses read-lock (and not write lock).
23 * Revision 1.52 1997/11/18 10:05:08 adam
24 * Changed character map facility so that admin can specify character
25 * mapping files for each register type, w, p, etc.
27 * Revision 1.51 1997/10/27 14:33:06 adam
28 * Moved towards generic character mapping depending on "structure"
29 * field in abstract syntax file. Fixed a few memory leaks. Fixed
30 * bug with negative integers when doing searches with relational
33 * Revision 1.50 1997/09/29 09:08:36 adam
34 * Revised locking system to be thread safe for the server.
36 * Revision 1.49 1997/09/25 14:57:23 adam
39 * Revision 1.48 1997/09/17 12:19:19 adam
40 * Zebra version corresponds to YAZ version 1.4.
41 * Changed Zebra server so that it doesn't depend on global common_resource.
43 * Revision 1.47 1997/09/04 13:58:36 adam
44 * New retrieve/extract method tellf (added).
45 * Added O_BINARY for open calls.
47 * Revision 1.46 1997/07/28 08:30:47 adam
48 * Server returns diagnostic 14 when record doesn't exist.
50 * Revision 1.45 1996/12/23 15:30:45 adam
52 * Bug fix: result sets weren't deleted after server shut down.
54 * Revision 1.44 1996/12/11 12:08:01 adam
55 * Added better compression.
57 * Revision 1.43 1996/11/15 15:03:58 adam
58 * Logging of execution speed by using the times(2) call.
60 * Revision 1.42 1996/11/08 11:10:36 adam
61 * Buffers used during file match got bigger.
62 * Compressed ISAM support everywhere.
63 * Bug fixes regarding masking characters in queries.
64 * Redesigned Regexp-2 queries.
66 * Revision 1.41 1996/10/29 14:09:56 adam
67 * Use of cisam system - enabled if setting isamc is 1.
69 * Revision 1.40 1996/06/04 10:19:02 adam
70 * Minor changes - removed include of ctype.h.
72 * Revision 1.39 1996/05/31 09:07:05 quinn
73 * Work on character-set handling
75 * Revision 1.38 1996/05/14 11:34:01 adam
76 * Scan support in multiple registers/databases.
78 * Revision 1.37 1996/05/14 06:16:48 adam
79 * Compact use/set bytes used in search service.
81 * Revision 1.36 1996/05/01 13:46:37 adam
82 * First work on multiple records in one file.
83 * New option, -offset, to the "unread" command in the filter module.
85 * Revision 1.35 1996/03/26 16:01:14 adam
86 * New setting lockPath: directory of various lock files.
88 * Revision 1.34 1996/03/20 09:36:46 adam
89 * Function dict_lookup_grep got extra parameter, init_pos, which marks
90 * from which position in pattern approximate pattern matching should occur.
91 * Approximate pattern matching is used in relevance=re-2.
93 * Revision 1.33 1996/01/17 14:57:56 adam
94 * Prototype changed for reader functions in extract/retrieve. File
95 * is identified by 'void *' instead of 'int.
97 * Revision 1.32 1995/12/11 09:12:58 adam
98 * The rec_get function returns NULL if record doesn't exist - will
99 * happen in the server if the result set records have been deleted since
100 * the creation of the set (i.e. the search).
101 * The server saves a result temporarily if it is 'volatile', i.e. the
102 * set is register dependent.
104 * Revision 1.31 1995/12/08 16:22:56 adam
105 * Work on update while servers are running. Three lock files introduced.
106 * The servers reload their registers when necessary, but they don't
107 * reestablish result sets yet.
109 * Revision 1.30 1995/12/07 17:38:48 adam
110 * Work locking mechanisms for concurrent updates/commit.
112 * Revision 1.29 1995/12/04 14:22:32 adam
113 * Extra arg to recType_byName.
114 * Started work on new regular expression parsed input to
115 * structured records.
117 * Revision 1.28 1995/11/28 09:09:48 adam
118 * Zebra config renamed.
119 * Use setting 'recordId' to identify record now.
120 * Bug fix in recindex.c: rec_release_blocks was invokeded even
121 * though the blocks were already released.
122 * File traversal properly deletes records when needed.
124 * Revision 1.27 1995/11/27 13:58:54 adam
125 * New option -t. storeStore data implemented in server.
127 * Revision 1.26 1995/11/25 10:24:07 adam
128 * More record fields - they are enumerated now.
129 * New options: flagStoreData flagStoreKey.
131 * Revision 1.25 1995/11/21 15:29:13 adam
132 * Config file 'base' read by default by both indexer and server.
134 * Revision 1.24 1995/11/20 16:59:47 adam
135 * New update method: the 'old' keys are saved for each records.
137 * Revision 1.23 1995/11/16 17:00:56 adam
138 * Better logging of rpn query.
140 * Revision 1.22 1995/11/16 15:34:55 adam
141 * Uses new record management system in both indexer and server.
143 * Revision 1.21 1995/11/01 16:25:52 quinn
144 * *** empty log message ***
146 * Revision 1.20 1995/10/27 14:00:12 adam
147 * Implemented detection of database availability.
149 * Revision 1.19 1995/10/17 18:02:11 adam
150 * New feature: databases. Implemented as prefix to words in dictionary.
152 * Revision 1.18 1995/10/16 14:03:09 quinn
153 * Changes to support element set names and espec1
155 * Revision 1.17 1995/10/16 09:32:40 adam
156 * More work on relational op.
158 * Revision 1.16 1995/10/13 12:26:44 adam
159 * Optimization of truncation.
161 * Revision 1.15 1995/10/12 12:40:55 adam
162 * Bug fixes in rpn_prox.
164 * Revision 1.14 1995/10/09 16:18:37 adam
165 * Function dict_lookup_grep got extra client data parameter.
167 * Revision 1.13 1995/10/06 14:38:00 adam
168 * New result set method: r_score.
169 * Local no (sysno) and score is transferred to retrieveCtrl.
171 * Revision 1.12 1995/10/06 13:52:06 adam
172 * Bug fixes. Handler may abort further scanning.
174 * Revision 1.11 1995/10/06 10:43:57 adam
175 * Scan added. 'occurrences' in scan entries not set yet.
177 * Revision 1.10 1995/10/02 16:43:32 quinn
178 * Set default resulting record type in fetch.
180 * Revision 1.9 1995/10/02 15:18:52 adam
181 * New member in recRetrieveCtrl: diagnostic.
183 * Revision 1.8 1995/09/28 09:19:47 adam
184 * xfree/xmalloc used everywhere.
185 * Extract/retrieve method seems to work for text records.
187 * Revision 1.7 1995/09/27 16:17:32 adam
188 * More work on retrieve.
190 * Revision 1.6 1995/09/08 08:53:22 adam
191 * Record buffer maintained in server_info.
193 * Revision 1.5 1995/09/06 16:11:18 adam
194 * Option: only one word key per file.
196 * Revision 1.4 1995/09/06 10:33:04 adam
197 * More work on present. Some log messages removed.
199 * Revision 1.3 1995/09/05 15:28:40 adam
200 * More work on search engine.
202 * Revision 1.2 1995/09/04 12:33:43 adam
203 * Various cleanup. YAZ util used instead.
205 * Revision 1.1 1995/09/04 09:10:41 adam
206 * More work on index add/del/update.
207 * Merge sort implemented.
208 * Initial work on z39 server.
227 static int bend_sort (void *handle, bend_sort_rr *rr);
229 bend_initresult *bend_init (bend_initrequest *q)
231 bend_initresult *r = odr_malloc (q->stream, sizeof(*r));
233 struct statserv_options_block *sob;
237 q->bend_sort = bend_sort;
239 logf (LOG_DEBUG, "bend_init");
241 sob = statserv_getcontrol ();
242 if (!(zh = zebra_open (NULL, sob->configname)))
244 logf (LOG_FATAL, "Failed to open Zebra `%s'", sob->configname);
252 bend_searchresult *bend_search (void *handle, bend_searchrequest *q, int *fd)
254 ZebraHandle zh = handle;
255 bend_searchresult *r = odr_malloc (q->stream, sizeof(*r));
261 logf (LOG_LOG, "ResultSet '%s'", q->setname);
262 switch (q->query->which)
264 case Z_Query_type_1: case Z_Query_type_101:
265 zebra_search_rpn (zh, q->stream, q->query->u.type_1,
266 q->num_bases, q->basenames, q->setname);
267 r->errcode = zh->errCode;
268 r->errstring = zh->errString;
277 bend_fetchresult *bend_fetch (void *handle, bend_fetchrequest *q, int *num)
279 ZebraHandle zh = handle;
280 bend_fetchresult *r = odr_malloc (q->stream, sizeof(*r));
281 ZebraRetrievalRecord retrievalRecord;
283 retrievalRecord.position = q->number;
286 zebra_records_retrieve (zh, q->stream, q->setname, q->comp,
287 q->format, 1, &retrievalRecord);
291 r->errcode = zh->errCode;
292 r->errstring = zh->errString;
297 r->basename = retrievalRecord.base;
298 r->record = retrievalRecord.buf;
299 r->len = retrievalRecord.len;
300 r->format = retrievalRecord.format;
305 bend_deleteresult *bend_delete (void *handle, bend_deleterequest *q, int *num)
310 bend_scanresult *bend_scan (void *handle, bend_scanrequest *q, int *num)
312 ZebraScanEntry *entries;
313 ZebraHandle zh = handle;
314 bend_scanresult *r = odr_malloc (q->stream, sizeof(*r));
317 r->term_position = q->term_position;
318 r->num_entries = q->num_entries;
320 r->entries = odr_malloc (q->stream, sizeof(*r->entries) * q->num_entries);
321 zebra_scan (zh, q->stream, q->term,
323 q->num_bases, q->basenames,
325 &r->num_entries, &entries, &is_partial);
327 r->status = BEND_SCAN_PARTIAL;
329 r->status = BEND_SCAN_SUCCESS;
330 for (i = 0; i < r->num_entries; i++)
332 r->entries[i].term = entries[i].term;
333 r->entries[i].occurrences = entries[i].occurrences;
335 r->errcode = zh->errCode;
336 r->errstring = zh->errString;
340 void bend_close (void *handle)
342 zebra_close ((ZebraHandle) handle);
345 int bend_sort (void *handle, bend_sort_rr *rr)
347 ZebraHandle zh = handle;
349 zebra_sort (zh, rr->stream, rr->num_input_setnames, rr->input_setnames,
350 rr->output_setname, rr->sort_sequence, &rr->sort_status);
351 rr->errcode = zh->errCode;
352 rr->errstring = zh->errString;
357 static void pre_init (struct statserv_options_block *sob)
359 char *pidfile = "zebrasrv.pid";
360 int fd = creat (pidfile, 0666);
363 logf (LOG_WARN|LOG_ERRNO, "creat %s", pidfile);
368 sprintf (pidstr, "%ld", (long) getpid ());
369 write (fd, pidstr, strlen(pidstr));
375 int main (int argc, char **argv)
377 struct statserv_options_block *sob;
379 sob = statserv_getcontrol ();
380 strcpy (sob->configname, FNAME_CONFIG);
382 sob->pre_init = pre_init;
384 statserv_setcontrol (sob);
386 return statserv_main (argc, argv);