New set types: sand/sor/snot - ranked versions of and/or/not in
[idzebra-moved-to-github.git] / rset / rsisam.c
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: rsisam.c,v $
7  * Revision 1.14  1995-12-11 09:15:24  adam
8  * New set types: sand/sor/snot - ranked versions of and/or/not in
9  * ranked/semi-ranked result sets.
10  * Note: the snot not finished yet.
11  * New rset member: flag.
12  * Bug fix: r_delete in rsrel.c did free bad memory block.
13  *
14  * Revision 1.13  1995/10/12  12:41:56  adam
15  * Private info (buf) moved from struct rset_control to struct rset.
16  * Bug fixes in relevance.
17  *
18  * Revision 1.12  1995/10/10  14:00:04  adam
19  * Function rset_open changed its wflag parameter to general flags.
20  *
21  * Revision 1.11  1995/10/06  14:38:05  adam
22  * New result set method: r_score.
23  * Local no (sysno) and score is transferred to retrieveCtrl.
24  *
25  * Revision 1.10  1995/09/08  14:52:42  adam
26  * Work on relevance feedback.
27  *
28  * Revision 1.9  1995/09/07  13:58:43  adam
29  * New parameter: result-set file descriptor (RSFD) to support multiple
30  * positions within the same result-set.
31  * Boolean operators: and, or, not implemented.
32  *
33  * Revision 1.8  1995/09/06  16:11:56  adam
34  * More work on boolean sets.
35  *
36  * Revision 1.7  1995/09/06  10:35:44  adam
37  * Null set implemented.
38  *
39  * Revision 1.6  1995/09/05  11:43:24  adam
40  * Complete version of temporary sets. Not tested yet though.
41  *
42  * Revision 1.5  1995/09/04  12:33:56  adam
43  * Various cleanup. YAZ util used instead.
44  *
45  * Revision 1.4  1995/09/04  09:10:55  adam
46  * Minor changes.
47  *
48  * Revision 1.3  1994/11/22  13:15:37  quinn
49  * Simple
50  *
51  * Revision 1.2  1994/11/04  14:53:12  quinn
52  * Work
53  *
54  */
55
56 #include <stdio.h>
57 #include <assert.h>
58 #include <rsisam.h>
59 #include <alexutil.h>
60
61 static void *r_create(const struct rset_control *sel, void *parms,
62                       int *flags);
63 static RSFD r_open (RSET ct, int flag);
64 static void r_close (RSFD rfd);
65 static void r_delete (RSET ct);
66 static void r_rewind (RSFD rfd);
67 static int r_count (RSET ct);
68 static int r_read (RSFD rfd, void *buf);
69 static int r_write (RSFD rfd, const void *buf);
70 static int r_score (RSFD rfd, int *score);
71
72 static const rset_control control = 
73 {
74     "isam",
75     r_create,
76     r_open,
77     r_close,
78     r_delete,
79     r_rewind,
80     r_count,
81     r_read,
82     r_write,
83     r_score
84 };
85
86 const rset_control *rset_kind_isam = &control;
87
88 struct rset_ispt_info {
89     ISPT   pt;
90     struct rset_ispt_info *next;
91     struct rset_isam_info *info;
92 };
93
94 struct rset_isam_info {
95     ISAM   is;
96     ISAM_P pos;
97     struct rset_ispt_info *ispt_list;
98 };
99
100 static void *r_create(const struct rset_control *sel, void *parms,
101                       int *flags)
102 {
103     rset_isam_parms *pt = parms;
104     struct rset_isam_info *info;
105
106     *flags |= RSET_FLAG_VOLATILE;
107     info = xmalloc (sizeof(struct rset_isam_info));
108     info->is = pt->is;
109     info->pos = pt->pos;
110     info->ispt_list = NULL;
111     return info;
112 }
113
114 RSFD r_open (RSET ct, int flag)
115 {
116     struct rset_isam_info *info = ct->buf;
117     struct rset_ispt_info *ptinfo;
118
119     logf (LOG_DEBUG, "risam_open");
120     if (flag & RSETF_WRITE)
121     {
122         logf (LOG_FATAL, "ISAM set type is read-only");
123         return NULL;
124     }
125     ptinfo = xmalloc (sizeof(*ptinfo));
126     ptinfo->next = info->ispt_list;
127     info->ispt_list = ptinfo;
128     ptinfo->pt = is_position (info->is, info->pos);
129     ptinfo->info = info;
130     return ptinfo;
131 }
132
133 static void r_close (RSFD rfd)
134 {
135     struct rset_isam_info *info = ((struct rset_ispt_info*) rfd)->info;
136     struct rset_ispt_info **ptinfop;
137
138     for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
139         if (*ptinfop == rfd)
140         {
141             is_pt_free ((*ptinfop)->pt);
142             *ptinfop = (*ptinfop)->next;
143             free (rfd);
144             return;
145         }
146     logf (LOG_FATAL, "r_close but no rfd match!");
147     assert (0);
148 }
149
150 static void r_delete (RSET ct)
151 {
152     struct rset_isam_info *info = ct->buf;
153
154     logf (LOG_DEBUG, "rsisam_delete");
155     assert (info->ispt_list == NULL);
156     xfree (info);
157 }
158
159 static void r_rewind (RSFD rfd)
160 {   
161     logf (LOG_DEBUG, "rsisam_rewind");
162     is_rewind( ((struct rset_ispt_info*) rfd)->pt);
163 }
164
165 static int r_count (RSET ct)
166 {
167     return 0;
168 }
169
170 static int r_read (RSFD rfd, void *buf)
171 {
172     return is_readkey( ((struct rset_ispt_info*) rfd)->pt, buf);
173 }
174
175 static int r_write (RSFD rfd, const void *buf)
176 {
177     logf (LOG_FATAL, "ISAM set type is read-only");
178     return -1;
179 }
180
181 static int r_score (RSFD rfd, int *score)
182 {
183     *score = -1;
184     return -1;
185 }