2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 2002-03-20 20:24:30 adam
8 * Hits per term. Returned in SearchResult-1
10 * Revision 1.8 1999/11/30 13:48:04 adam
11 * Improved installation. Updated for inclusion of YAZ header files.
13 * Revision 1.7 1999/05/26 07:49:14 adam
16 * Revision 1.6 1999/02/02 14:51:35 adam
17 * Updated WIN32 code specific sections. Changed header.
19 * Revision 1.5 1998/03/05 08:36:28 adam
20 * New result set model.
22 * Revision 1.4 1997/12/18 10:54:25 adam
23 * New method result set method rs_hits that returns the number of
24 * hits in result-set (if known). The ranked result set returns real
25 * number of hits but only when not combined with other operands.
27 * Revision 1.3 1997/10/31 12:37:01 adam
28 * Code calls xfree() instead of free().
30 * Revision 1.2 1996/11/08 11:15:57 adam
31 * Compressed isam fully supported.
33 * Revision 1.1 1996/10/29 13:41:48 adam
45 static void *r_create(RSET ct, const struct rset_control *sel, void *parms);
46 static RSFD r_open (RSET ct, int flag);
47 static void r_close (RSFD rfd);
48 static void r_delete (RSET ct);
49 static void r_rewind (RSFD rfd);
50 static int r_count (RSET ct);
51 static int r_read (RSFD rfd, void *buf, int *term_index);
52 static int r_write (RSFD rfd, const void *buf);
54 static const struct rset_control control =
67 const struct rset_control *rset_kind_isamc = &control;
71 struct rset_pp_info *next;
72 struct rset_isamc_info *info;
77 struct rset_isamc_info {
81 int (*cmp)(const void *p1, const void *p2);
82 struct rset_pp_info *ispt_list;
85 static void *r_create(RSET ct, const struct rset_control *sel, void *parms)
87 rset_isamc_parms *pt = (rset_isamc_parms *) parms;
88 struct rset_isamc_info *info;
90 ct->flags |= RSET_FLAG_VOLATILE;
91 info = (struct rset_isamc_info *) xmalloc (sizeof(*info));
94 info->key_size = pt->key_size;
95 yaz_log (LOG_LOG, "info->key_size = %d\n", info->key_size);
97 info->ispt_list = NULL;
98 ct->no_rset_terms = 1;
99 ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms));
100 ct->rset_terms[0] = pt->rset_term;
104 RSFD r_open (RSET ct, int flag)
106 struct rset_isamc_info *info = (struct rset_isamc_info *) ct->buf;
107 struct rset_pp_info *ptinfo;
109 logf (LOG_DEBUG, "risamc_open");
110 if (flag & RSETF_WRITE)
112 logf (LOG_FATAL, "ISAMC set type is read-only");
115 ptinfo = (struct rset_pp_info *) xmalloc (sizeof(*ptinfo));
116 ptinfo->next = info->ispt_list;
117 info->ispt_list = ptinfo;
118 ptinfo->pt = isc_pp_open (info->is, info->pos);
120 if (ct->rset_terms[0]->nn < 0)
121 ct->rset_terms[0]->nn = isc_pp_num (ptinfo->pt);
122 ct->rset_terms[0]->count = 0;
123 ptinfo->countp = &ct->rset_terms[0]->count;
124 ptinfo->buf = xmalloc (info->key_size);
128 static void r_close (RSFD rfd)
130 struct rset_isamc_info *info = ((struct rset_pp_info*) rfd)->info;
131 struct rset_pp_info **ptinfop;
133 for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
136 xfree ((*ptinfop)->buf);
137 isc_pp_close ((*ptinfop)->pt);
138 *ptinfop = (*ptinfop)->next;
142 logf (LOG_FATAL, "r_close but no rfd match!");
146 static void r_delete (RSET ct)
148 struct rset_isamc_info *info = (struct rset_isamc_info *) ct->buf;
150 logf (LOG_DEBUG, "rsisamc_delete");
151 assert (info->ispt_list == NULL);
152 rset_term_destroy (ct->rset_terms[0]);
153 xfree (ct->rset_terms);
157 static void r_rewind (RSFD rfd)
159 logf (LOG_DEBUG, "rsisamc_rewind");
163 static int r_count (RSET ct)
168 static int r_read (RSFD rfd, void *buf, int *term_index)
170 struct rset_pp_info *pinfo = (struct rset_pp_info *) rfd;
173 r = isc_pp_read(pinfo->pt, buf);
176 if (*pinfo->countp == 0 || (*pinfo->info->cmp)(buf, pinfo->buf) > 1)
178 memcpy (pinfo->buf, buf, pinfo->info->key_size);
185 static int r_write (RSFD rfd, const void *buf)
187 logf (LOG_FATAL, "ISAMC set type is read-only");