1 /* $Id: rset.h,v 1.49 2005-04-15 10:47:48 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include <yaz/yaz-util.h>
27 /* unfortunately we need the isam includes here, for the arguments for */
29 #include <idzebra/isamb.h>
30 #include <idzebra/isamc.h>
31 #include <idzebra/isams.h>
35 typedef struct rsfd *RSFD; /* Rset "file descriptor" */
36 typedef struct rset *RSET; /* Result set */
40 * rset_term is all we need to know of a term to do ranking etc.
41 * As far as the rsets are concerned, it is just a dummy pointer to
46 /** the term itself */
50 /** the rset corresponding to this term */
52 /** private stuff for the ranking algorithm */
56 typedef struct rset_term *TERMID;
57 TERMID rset_term_create (const char *name, int length, const char *flags,
62 /** rsfd is a "file descriptor" for reading from a rset */
63 struct rsfd { /* the stuff common to all rsfd's. */
64 RSET rset; /* ptr to the rset this FD is opened to */
65 void *priv; /* private parameters for this type */
66 RSFD next; /* to keep lists of used/free rsfd's */
71 * rset_control has function pointers to all the important functions
72 * of a rset. Each type of rset will have its own control block, pointing
73 * to the functions for that type. They all have their own create function
74 * which is not part of the control block, as it takes different args for
79 /** text description of set type (for debugging) */
81 /* RSET rs_something_create(const struct rset_control *sel, ...); */
82 void (*f_delete)(RSET ct);
84 /** recursively fills the terms array with terms. call with curterm=0 */
85 /* always counts them all into cur, but of course won't touch the term */
86 /* array past max. You can use this to count, set max=0 */
87 void (*f_getterms)(RSET ct, TERMID *terms, int maxterms, int *curterm);
89 RSFD (*f_open)(RSET ct, int wflag);
90 void (*f_close)(RSFD rfd);
91 /** forward behaves like a read, but it skips some items first */
92 int (*f_forward)(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
93 void (*f_pos)(RSFD rfd, double *current, double *total);
94 /* returns -1,-1 if pos function not implemented for this type */
95 int (*f_read)(RSFD rfd, void *buf, TERMID *term);
96 int (*f_write)(RSFD rfd, const void *buf);
99 /** rset_default_forward implements a generic forward with a read-loop */
100 int rset_default_forward(RSFD rfd, void *buf, TERMID *term,
101 const void *untilbuf);
103 /** rset_get_no_terms is a getterms function for those that don't have any */
104 void rset_get_no_terms(RSET ct, TERMID *terms, int maxterms, int *curterm);
107 * rset_get_one_term is a getterms function for those rsets that have
108 * exactly one term, like all rsisamX types.
110 void rset_get_one_term(RSET ct,TERMID *terms,int maxterms,int *curterm);
113 * key_control contains all there is to know about the keys stored in
114 * an isam, and therefore operated by the rsets. Other than this info,
115 * all we assume is that all keys are the same size, and they can be
120 int scope; /* default for what level we operate (book/chapter/verse) on*/
121 /* usual sysno/seqno is 2 */
122 int (*cmp) (const void *p1, const void *p2);
123 void (*key_logdump_txt) (int logmask, const void *p, const char *txt);
124 zint (*getseq)(const void *p);
125 /* FIXME - Should not need a getseq, it won't make much sense with */
126 /* higher-order keys. Use a (generalized) cmp instead, or something */
127 /* FIXME - decode and encode, and lots of other stuff */
131 * A rset is an ordered sequence of keys, either directly from an underlaying
132 * isam, or from one of the higher-level operator rsets (and, or, ...).
133 * Actually, it is "virtual base class", no pure rsets exist in the system,
134 * they all are of some derived type.
138 const struct rset_control *control;
139 const struct key_control *keycontrol;
140 int count; /* reference count */
141 void *priv; /* stuff private to the given type of rset */
142 NMEM nmem; /* nibble memory for various allocs */
143 char my_nmem; /* Should the nmem be destroyed with the rset? */
144 /* 1 if created with it, 0 if passed from above */
145 RSFD free_list; /* all rfd's allocated but not currently in use */
146 RSFD use_list; /* all rfd's in use */
147 int scope; /* On what level do we count hits and compare them? */
148 TERMID term; /* the term thing for ranking etc */
150 /* rset is a "virtual base class", which will never exist on its own
151 * all instances are rsets of some specific type, like rsisamb, or rsbool
152 * They keep their own stuff behind the priv pointer. */
154 /* On the old sysno-seqno type isams, the scope was hard-coded to be 2.
155 * This means that we count hits on the sysno level, and when matching an
156 * 'and', we consider it a match if both term occur within the same sysno.
157 * In more complex isams we can specify on what level we wish to do the
158 * matching and counting of hits. For example, we can have book / chapter /
159 * verse, and a seqno. Scope 2 means then "give me all verses that match",
160 * 3 would be chapters, 4 books.
161 * The resolution tells how much of the occurences we need to return. If we
162 * are doing some sort of proximity, we need to get the seqnos of all
163 * occurences, whereas if we are only counting hits, we do not need anything
164 * below the scope. Again 1 is seqnos, 2 sysnos (or verses), 3 books, etc.
167 RSFD rfd_create_base(RSET rs);
168 void rfd_delete_base(RSFD rfd);
169 int rfd_is_last(RSFD rfd);
171 RSET rset_create_base(const struct rset_control *sel,
173 const struct key_control *kcontrol,
177 void rset_delete(RSET rs);
178 RSET rset_dup (RSET rs);
182 #define RSETF_WRITE 1
183 /* RSFD rset_open(RSET rs, int wflag); */
184 #define rset_open(rs, wflag) (*(rs)->control->f_open)((rs), (wflag))
186 /* void rset_close(RSFD rfd); */
187 #define rset_close(rfd) (*(rfd)->rset->control->f_close)(rfd)
189 /* int rset_forward(RSFD rfd, void *buf, TERMID term, void *untilbuf); */
190 #define rset_forward(rfd, buf, term, untilbuf) \
191 (*(rfd)->rset->control->f_forward)((rfd),(buf),(term),(untilbuf))
193 /* void rset_getterms(RSET ct, TERMID *terms, int maxterms, int *curterm); */
194 #define rset_getterms(ct, terms, maxterms, curterm) \
195 (*(ct)->control->f_getterms)((ct),(terms),(maxterms),(curterm))
197 /* int rset_pos(RSFD fd, double *current, double *total); */
198 #define rset_pos(rfd,cur,tot) \
199 (*(rfd)->rset->control->f_pos)((rfd),(cur),(tot))
201 /* int rset_read(RSFD rfd, void *buf, TERMID term); */
202 #define rset_read(rfd, buf, term) \
203 (*(rfd)->rset->control->f_read)((rfd), (buf), (term))
205 /* int rset_write(RSFD rfd, const void *buf); */
206 #define rset_write(rfd, buf) (*(rfd)->rset->control->f_write)((rfd), (buf))
208 /* int rset_type (RSET) */
209 #define rset_type(rs) ((rs)->control->desc)
211 /** rset_count counts or estimates the keys in it*/
212 zint rset_count(RSET rs);
214 RSET rstemp_create(NMEM nmem, const struct key_control *kcontrol,
216 const char *temp_path, TERMID term);
218 RSET rsnull_create(NMEM nmem, const struct key_control *kcontrol);
220 RSET rsbool_create_and(NMEM nmem, const struct key_control *kcontrol,
221 int scope, RSET rset_l, RSET rset_r);
223 RSET rsbool_create_or (NMEM nmem, const struct key_control *kcontrol,
224 int scope, RSET rset_l, RSET rset_r);
226 RSET rsbool_create_not(NMEM nmem, const struct key_control *kcontrol,
227 int scope, RSET rset_l, RSET rset_r);
229 RSET rsbetween_create(NMEM nmem, const struct key_control *kcontrol,
230 int scope, RSET rset_l, RSET rset_m, RSET rset_r,
233 RSET rsmulti_or_create(NMEM nmem, const struct key_control *kcontrol,
234 int scope, int no_rsets, RSET* rsets);
236 RSET rsmulti_and_create(NMEM nmem, const struct key_control *kcontrol,
237 int scope, int no_rsets, RSET* rsets);
239 RSET rsprox_create(NMEM nmem, const struct key_control *kcontrol,
240 int scope, int rset_no, RSET *rset,
241 int ordered, int exclusion, int relation, int distance);
243 RSET rsisamb_create(NMEM nmem, const struct key_control *kcontrol,
244 int scope, ISAMB is, ISAM_P pos, TERMID term);
246 RSET rsisamc_create(NMEM nmem, const struct key_control *kcontrol,
247 int scope, ISAMC is, ISAM_P pos, TERMID term);
249 RSET rsisams_create(NMEM nmem, const struct key_control *kcontrol,
250 int scope, ISAMS is, ISAM_P pos, TERMID term);