2 * Copyright (C) 1994-1997, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.22 1997-09-22 12:39:06 adam
8 * Added get_pos method for the ranked result sets.
10 * Revision 1.21 1997/09/17 12:19:13 adam
11 * Zebra version corresponds to YAZ version 1.4.
12 * Changed Zebra server so that it doesn't depend on global common_resource.
14 * Revision 1.20 1996/12/23 15:30:44 adam
16 * Bug fix: result sets weren't deleted after server shut down.
18 * Revision 1.19 1996/12/11 12:08:00 adam
19 * Added better compression.
21 * Revision 1.18 1996/10/29 14:09:44 adam
22 * Use of cisam system - enabled if setting isamc is 1.
24 * Revision 1.17 1996/06/04 10:18:58 adam
25 * Minor changes - removed include of ctype.h.
27 * Revision 1.16 1996/05/13 14:23:05 adam
28 * Work on compaction of set/use bytes in dictionary.
30 * Revision 1.15 1995/11/20 16:59:46 adam
31 * New update method: the 'old' keys are saved for each records.
33 * Revision 1.14 1995/10/30 15:08:08 adam
36 * Revision 1.13 1995/10/27 14:00:11 adam
37 * Implemented detection of database availability.
39 * Revision 1.12 1995/10/17 18:02:08 adam
40 * New feature: databases. Implemented as prefix to words in dictionary.
42 * Revision 1.11 1995/10/06 16:33:37 adam
43 * Use attribute mappings.
45 * Revision 1.10 1995/09/29 14:01:41 adam
48 * Revision 1.9 1995/09/28 12:10:32 adam
49 * Bug fixes. Field prefix used in queries.
51 * Revision 1.8 1995/09/28 09:19:42 adam
52 * xfree/xmalloc used everywhere.
53 * Extract/retrieve method seems to work for text records.
55 * Revision 1.7 1995/09/27 12:22:28 adam
56 * More work on extract in record control.
57 * Field name is not in isam keys but in prefix in dictionary words.
59 * Revision 1.6 1995/09/14 07:48:23 adam
60 * Record control management.
62 * Revision 1.5 1995/09/11 13:09:34 adam
63 * More work on relevance feedback.
65 * Revision 1.4 1995/09/08 14:52:27 adam
66 * Minor changes. Dictionary is lower case now.
68 * Revision 1.3 1995/09/07 13:58:36 adam
69 * New parameter: result-set file descriptor (RSFD) to support multiple
70 * positions within the same result-set.
71 * Boolean operators: and, or, not implemented.
72 * Result-set references.
74 * Revision 1.2 1995/09/06 16:11:17 adam
75 * Option: only one word key per file.
77 * Revision 1.1 1995/09/04 09:10:36 adam
78 * More work on index add/del/update.
79 * Merge sort implemented.
80 * Initial work on z39 server.
91 void key_logdump (int logmask, const void *p)
95 memcpy (&key, p, sizeof(key));
96 logf (logmask, "%7d s=%-4d", key.sysno, key.seqno);
99 int key_compare_it (const void *p1, const void *p2)
101 if (((struct it_key *) p1)->sysno != ((struct it_key *) p2)->sysno)
103 if (((struct it_key *) p1)->sysno > ((struct it_key *) p2)->sysno)
108 if (((struct it_key *) p1)->seqno != ((struct it_key *) p2)->seqno)
110 if (((struct it_key *) p1)->seqno > ((struct it_key *) p2)->seqno)
118 int key_compare (const void *p1, const void *p2)
120 struct it_key i1, i2;
121 memcpy (&i1, p1, sizeof(i1));
122 memcpy (&i2, p2, sizeof(i2));
123 if (i1.sysno != i2.sysno)
125 if (i1.sysno > i2.sysno)
130 if (i1.seqno != i2.seqno)
132 if (i1.seqno > i2.seqno)
140 int key_qsort_compare (const void *p1, const void *p2)
144 char *cp1 = *(char **) p1;
145 char *cp2 = *(char **) p2;
147 if ((r = strcmp (cp1, cp2)))
150 if ((r = key_compare (cp1+l+1, cp2+l+1)))
152 return cp1[l] - cp2[l];
155 int key_get_pos (const void *p)
158 memcpy (&key, p, sizeof(key));
162 struct iscz1_code_info {
166 static void *iscz1_code_start (int mode)
168 struct iscz1_code_info *p = xmalloc (sizeof(*p));
174 static void iscz1_code_stop (int mode, void *p)
179 void iscz1_encode_int (unsigned d, char **dst)
181 unsigned char *bp = (unsigned char*) *dst;
190 else if (d <= 4194303)
192 *bp++ = 128 + (d>>16);
193 *bp++ = (d>>8) & 255;
198 *bp++ = 192 + (d>>24);
199 *bp++ = (d>>16) & 255;
200 *bp++ = (d>>8) & 255;
206 int iscz1_decode_int (unsigned char **src)
208 unsigned c = *(*src)++;
214 return ((c & 63) << 8) + *(*src)++;
216 c = ((c & 63) << 8) + *(*src)++;
217 c = (c << 8) + *(*src)++;
220 c = ((c & 63) << 8) + *(*src)++;
221 c = (c << 8) + *(*src)++;
222 c = (c << 8) + *(*src)++;
226 static void iscz1_code_item (int mode, void *vp, char **dst, char **src)
228 struct iscz1_code_info *p = vp;
232 if (mode == ISAMC_ENCODE)
234 memcpy (&tkey, *src, sizeof(struct it_key));
235 d = tkey.sysno - p->key.sysno;
238 iscz1_encode_int (2*tkey.seqno + 1, dst);
239 iscz1_encode_int (d, dst);
241 p->key.seqno = tkey.seqno;
245 iscz1_encode_int (2*(tkey.seqno - p->key.seqno), dst);
246 p->key.seqno = tkey.seqno;
248 (*src) += sizeof(struct it_key);
252 d = iscz1_decode_int ((unsigned char **) src);
256 p->key.sysno += iscz1_decode_int ((unsigned char **) src);
259 p->key.seqno += d>>1;
260 memcpy (*dst, &p->key, sizeof(struct it_key));
261 (*dst) += sizeof(struct it_key);
265 ISAMC_M key_isamc_m (Res res)
267 static ISAMC_M me = NULL;
272 me = isc_getmethod ();
274 me->compare_item = key_compare;
276 me->code_start = iscz1_code_start;
277 me->code_item = iscz1_code_item;
278 me->code_stop = iscz1_code_stop;
280 me->debug = atoi(res_get_def (res, "isamcDebug", "0"));
282 logf (LOG_LOG, "ISAMC system active");