2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.28 1999-05-26 07:49:13 adam
10 * Revision 1.27 1999/05/12 13:08:06 adam
11 * First version of ISAMS.
13 * Revision 1.26 1999/02/02 14:50:54 adam
14 * Updated WIN32 code specific sections. Changed header.
16 * Revision 1.25 1998/06/08 15:26:06 adam
19 * Revision 1.24 1998/06/08 14:43:12 adam
20 * Added suport for EXPLAIN Proxy servers - added settings databasePath
21 * and explainDatabase to facilitate this. Increased maximum number
22 * of databases and attributes in one register.
24 * Revision 1.23 1998/03/05 08:45:12 adam
25 * New result set model and modular ranking system. Moved towards
26 * descent server API. System information stored as "SGML" records.
28 * Revision 1.22 1997/09/22 12:39:06 adam
29 * Added get_pos method for the ranked result sets.
31 * Revision 1.21 1997/09/17 12:19:13 adam
32 * Zebra version corresponds to YAZ version 1.4.
33 * Changed Zebra server so that it doesn't depend on global common_resource.
35 * Revision 1.20 1996/12/23 15:30:44 adam
37 * Bug fix: result sets weren't deleted after server shut down.
39 * Revision 1.19 1996/12/11 12:08:00 adam
40 * Added better compression.
42 * Revision 1.18 1996/10/29 14:09:44 adam
43 * Use of cisam system - enabled if setting isamc is 1.
45 * Revision 1.17 1996/06/04 10:18:58 adam
46 * Minor changes - removed include of ctype.h.
48 * Revision 1.16 1996/05/13 14:23:05 adam
49 * Work on compaction of set/use bytes in dictionary.
51 * Revision 1.15 1995/11/20 16:59:46 adam
52 * New update method: the 'old' keys are saved for each records.
54 * Revision 1.14 1995/10/30 15:08:08 adam
57 * Revision 1.13 1995/10/27 14:00:11 adam
58 * Implemented detection of database availability.
60 * Revision 1.12 1995/10/17 18:02:08 adam
61 * New feature: databases. Implemented as prefix to words in dictionary.
63 * Revision 1.11 1995/10/06 16:33:37 adam
64 * Use attribute mappings.
66 * Revision 1.10 1995/09/29 14:01:41 adam
69 * Revision 1.9 1995/09/28 12:10:32 adam
70 * Bug fixes. Field prefix used in queries.
72 * Revision 1.8 1995/09/28 09:19:42 adam
73 * xfree/xmalloc used everywhere.
74 * Extract/retrieve method seems to work for text records.
76 * Revision 1.7 1995/09/27 12:22:28 adam
77 * More work on extract in record control.
78 * Field name is not in isam keys but in prefix in dictionary words.
80 * Revision 1.6 1995/09/14 07:48:23 adam
81 * Record control management.
83 * Revision 1.5 1995/09/11 13:09:34 adam
84 * More work on relevance feedback.
86 * Revision 1.4 1995/09/08 14:52:27 adam
87 * Minor changes. Dictionary is lower case now.
89 * Revision 1.3 1995/09/07 13:58:36 adam
90 * New parameter: result-set file descriptor (RSFD) to support multiple
91 * positions within the same result-set.
92 * Boolean operators: and, or, not implemented.
93 * Result-set references.
95 * Revision 1.2 1995/09/06 16:11:17 adam
96 * Option: only one word key per file.
98 * Revision 1.1 1995/09/04 09:10:36 adam
99 * More work on index add/del/update.
100 * Merge sort implemented.
101 * Initial work on z39 server.
112 void key_logdump (int logmask, const void *p)
116 memcpy (&key, p, sizeof(key));
117 logf (logmask, "%7d s=%-4d", key.sysno, key.seqno);
120 int key_compare_it (const void *p1, const void *p2)
122 if (((struct it_key *) p1)->sysno != ((struct it_key *) p2)->sysno)
124 if (((struct it_key *) p1)->sysno > ((struct it_key *) p2)->sysno)
129 if (((struct it_key *) p1)->seqno != ((struct it_key *) p2)->seqno)
131 if (((struct it_key *) p1)->seqno > ((struct it_key *) p2)->seqno)
139 int key_compare (const void *p1, const void *p2)
141 struct it_key i1, i2;
142 memcpy (&i1, p1, sizeof(i1));
143 memcpy (&i2, p2, sizeof(i2));
144 if (i1.sysno != i2.sysno)
146 if (i1.sysno > i2.sysno)
151 if (i1.seqno != i2.seqno)
153 if (i1.seqno > i2.seqno)
161 int key_qsort_compare (const void *p1, const void *p2)
165 char *cp1 = *(char **) p1;
166 char *cp2 = *(char **) p2;
168 if ((r = strcmp (cp1, cp2)))
171 if ((r = key_compare (cp1+l+1, cp2+l+1)))
173 return cp1[l] - cp2[l];
176 int key_get_pos (const void *p)
179 memcpy (&key, p, sizeof(key));
183 struct iscz1_code_info {
187 static void *iscz1_code_start (int mode)
189 struct iscz1_code_info *p = (struct iscz1_code_info *)
190 xmalloc (sizeof(*p));
196 static void iscz1_code_stop (int mode, void *p)
201 void iscz1_encode_int (unsigned d, char **dst)
203 unsigned char *bp = (unsigned char*) *dst;
212 else if (d <= 4194303)
214 *bp++ = 128 + (d>>16);
215 *bp++ = (d>>8) & 255;
220 *bp++ = 192 + (d>>24);
221 *bp++ = (d>>16) & 255;
222 *bp++ = (d>>8) & 255;
228 int iscz1_decode_int (unsigned char **src)
230 unsigned c = *(*src)++;
236 return ((c & 63) << 8) + *(*src)++;
238 c = ((c & 63) << 8) + *(*src)++;
239 c = (c << 8) + *(*src)++;
242 c = ((c & 63) << 8) + *(*src)++;
243 c = (c << 8) + *(*src)++;
244 c = (c << 8) + *(*src)++;
248 static void iscz1_code_item (int mode, void *vp, char **dst, char **src)
250 struct iscz1_code_info *p = (struct iscz1_code_info *) vp;
254 if (mode == ISAMC_ENCODE)
256 memcpy (&tkey, *src, sizeof(struct it_key));
257 d = tkey.sysno - p->key.sysno;
260 iscz1_encode_int (2*tkey.seqno + 1, dst);
261 iscz1_encode_int (d, dst);
263 p->key.seqno = tkey.seqno;
267 iscz1_encode_int (2*(tkey.seqno - p->key.seqno), dst);
268 p->key.seqno = tkey.seqno;
270 (*src) += sizeof(struct it_key);
274 d = iscz1_decode_int ((unsigned char **) src);
278 p->key.sysno += iscz1_decode_int ((unsigned char **) src);
281 p->key.seqno += d>>1;
282 memcpy (*dst, &p->key, sizeof(struct it_key));
283 (*dst) += sizeof(struct it_key);
287 ISAMC_M key_isamc_m (Res res)
289 static ISAMC_M me = NULL;
294 me = isc_getmethod ();
296 me->compare_item = key_compare;
298 me->code_start = iscz1_code_start;
299 me->code_item = iscz1_code_item;
300 me->code_stop = iscz1_code_stop;
302 me->debug = atoi(res_get_def (res, "isamcDebug", "0"));
307 ISAMS_M key_isams_m (Res res)
309 static ISAMS_M me = NULL;
314 me = isams_getmethod ();
316 me->compare_item = key_compare;
318 me->code_start = iscz1_code_start;
319 me->code_item = iscz1_code_item;
320 me->code_stop = iscz1_code_stop;
322 me->debug = atoi(res_get_def (res, "isamsDebug", "0"));
328 int key_SU_code (int ch, char *out)
334 out[i] = 128 + (ch & 63);