1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <yaz/yaz-util.h>
24 /* unfortunately we need the isam includes here, for the arguments for */
26 #include <idzebra/isamb.h>
27 #include <idzebra/isamc.h>
28 #include <idzebra/isams.h>
32 typedef struct rsfd *RSFD;
33 typedef struct rset *RSET;
37 struct ord_list *next;
40 struct ord_list *ord_list_create(NMEM nmem);
41 struct ord_list *ord_list_append(NMEM nmem, struct ord_list *list, int ord);
42 struct ord_list *ord_list_dup(NMEM nmem, struct ord_list *list);
43 void ord_list_print(struct ord_list *list);
46 * rset_term is all we need to know of a term to do ranking etc.
47 * As far as the rsets are concerned, it is just a dummy pointer to
51 char *name; /** the term itself in internal encoding (UTF-8/raw) */
52 char *flags; /** flags for rank method */
53 int type; /** Term_type from RPN Query. Actually this
54 is Z_Term_general, Z_Term_numeric,
55 Z_Term_characterString, ..
56 This info is used to return encoded term back for
59 int reg_type; /** register type */
60 RSET rset; /** the rset corresponding to this term */
61 void *rankpriv;/** private stuff for the ranking algorithm */
62 zint hits_limit;/** limit for hits if > 0 */
63 char *ref_id; /** reference for this term */
67 typedef struct rset_term *TERMID;
68 TERMID rset_term_create (const char *name, int length, const char *flags,
69 int type, NMEM nmem, struct ord_list *ol,
70 int reg_type, zint hits_limit, const char *ref_id);
72 /** rsfd is a "file descriptor" for reading from a rset */
73 struct rsfd { /* the stuff common to all rsfd's. */
74 RSET rset; /* ptr to the rset this FD is opened to */
75 void *priv; /* private parameters for this type */
76 RSFD next; /* to keep lists of used/free rsfd's */
83 * rset_control has function pointers to all the important functions
84 * of a rset. Each type of rset will have its own control block, pointing
85 * to the functions for that type. They all have their own create function
86 * which is not part of the control block, as it takes different args for
91 /** text description of set type (for debugging) */
93 /* RSET rs_something_create(const struct rset_control *sel, ...); */
94 void (*f_delete)(RSET ct);
96 /** recursively fills the terms array with terms. call with curterm=0 */
97 /* always counts them all into cur, but of course won't touch the term */
98 /* array past max. You can use this to count, set max=0 */
99 void (*f_getterms)(RSET ct, TERMID *terms, int maxterms, int *curterm);
101 RSFD (*f_open)(RSET ct, int wflag);
102 void (*f_close)(RSFD rfd);
103 /** forward behaves like a read, but it skips some items first */
104 int (*f_forward)(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
105 void (*f_pos)(RSFD rfd, double *current, double *total);
106 /* returns -1,-1 if pos function not implemented for this type */
107 int (*f_read)(RSFD rfd, void *buf, TERMID *term);
108 int (*f_write)(RSFD rfd, const void *buf);
111 /** rset_default_forward implements a generic forward with a read-loop */
112 int rset_default_forward(RSFD rfd, void *buf, TERMID *term,
113 const void *untilbuf);
115 /** rset_default_read implements a generic read */
116 int rset_default_read(RSFD rfd, void *buf, TERMID *term);
118 void rset_get_one_term(RSET ct,TERMID *terms,int maxterms,int *curterm);
121 * key_control contains all there is to know about the keys stored in
122 * an isam, and therefore operated by the rsets. Other than this info,
123 * all we assume is that all keys are the same size, and they can be
126 struct rset_key_control {
129 int scope; /* default for what level we operate (book/chapter/verse) on*/
130 /* usual sysno/seqno is 2 */
131 int (*cmp)(const void *p1, const void *p2);
132 void (*key_logdump_txt) (int logmask, const void *p, const char *txt);
133 zint (*getseq)(const void *p);
134 zint (*get_segment)(const void *p);
135 int (*filter_func)(const void *p, void *data);
137 void (*inc)(struct rset_key_control *kc);
138 void (*dec)(struct rset_key_control *kc);
139 /* FIXME - Should not need a getseq, it won't make much sense with */
140 /* higher-order keys. Use a (generalized) cmp instead, or something */
141 /* FIXME - decode and encode, and lots of other stuff */
145 * A rset is an ordered sequence of keys, either directly from an underlaying
146 * isam, or from one of the higher-level operator rsets (and, or, ...).
147 * Actually, it is "virtual base class", no pure rsets exist in the system,
148 * they all are of some derived type.
152 const struct rset_control *control;
153 struct rset_key_control *keycontrol;
154 int refcount; /* reference count */
155 void *priv; /* stuff private to the given type of rset */
156 NMEM nmem; /* nibble memory for various allocs */
157 RSFD free_list; /* all rfd's allocated but not currently in use */
158 RSFD use_list; /* all rfd's in use */
159 int scope; /* On what level do we count hits and compare them? */
160 TERMID term; /* the term thing for ranking etc */
168 /* rset is a "virtual base class", which will never exist on its own
169 * all instances are rsets of some specific type, like rsisamb, or rsbool
170 * They keep their own stuff behind the priv pointer. */
172 /* On the old sysno-seqno type isams, the scope was hard-coded to be 2.
173 * This means that we count hits on the sysno level, and when matching an
174 * 'and', we consider it a match if both term occur within the same sysno.
175 * In more complex isams we can specify on what level we wish to do the
176 * matching and counting of hits. For example, we can have book / chapter /
177 * verse, and a seqno. Scope 2 means then "give me all verses that match",
178 * 3 would be chapters, 4 books.
179 * The resolution tells how much of the occurences we need to return. If we
180 * are doing some sort of proximity, we need to get the seqnos of all
181 * occurences, whereas if we are only counting hits, we do not need anything
182 * below the scope. Again 1 is seqnos, 2 sysnos (or verses), 3 books, etc.
185 RSFD rfd_create_base(RSET rs);
186 int rfd_is_last(RSFD rfd);
188 RSET rset_create_base(const struct rset_control *sel,
190 struct rset_key_control *kcontrol,
193 int no_children, RSET *children);
195 void rset_delete(RSET rs);
196 RSET rset_dup (RSET rs);
197 void rset_close(RSFD rfd);
200 #define RSETF_WRITE 1
201 /* RSFD rset_open(RSET rs, int wflag); */
202 #define rset_open(rs, wflag) (*(rs)->control->f_open)((rs), (wflag))
204 /* int rset_forward(RSFD rfd, void *buf, TERMID term, void *untilbuf); */
205 #define rset_forward(rfd, buf, term, untilbuf) \
206 rset_default_forward((rfd), (buf), (term), (untilbuf))
208 /* void rset_getterms(RSET ct, TERMID *terms, int maxterms, int *curterm); */
209 #define rset_getterms(ct, terms, maxterms, curterm) \
210 (*(ct)->control->f_getterms)((ct),(terms),(maxterms),(curterm))
212 /* int rset_pos(RSFD fd, double *current, double *total); */
213 #define rset_pos(rfd,cur,tot) \
214 (*(rfd)->rset->control->f_pos)((rfd),(cur),(tot))
216 /* int rset_read(RSFD rfd, void *buf, TERMID term); */
217 #define rset_read(rfd, buf, term) rset_default_read((rfd), (buf), (term))
219 /* int rset_write(RSFD rfd, const void *buf); */
220 #define rset_write(rfd, buf) (*(rfd)->rset->control->f_write)((rfd), (buf))
222 /* int rset_type (RSET) */
223 #define rset_type(rs) ((rs)->control->desc)
225 /** rset_count counts or estimates the keys in it*/
226 zint rset_count(RSET rs);
228 RSET rset_create_temp(NMEM nmem, struct rset_key_control *kcontrol,
229 int scope, const char *temp_path, TERMID term);
231 RSET rset_create_null(NMEM nmem, struct rset_key_control *kcontrol, TERMID term);
233 RSET rset_create_not(NMEM nmem, struct rset_key_control *kcontrol,
234 int scope, RSET rset_l, RSET rset_r);
236 RSET rset_create_between(NMEM nmem, struct rset_key_control *kcontrol,
237 int scope, RSET rset_l, RSET rset_m, RSET rset_r,
240 RSET rset_create_or(NMEM nmem, struct rset_key_control *kcontrol,
241 int scope, TERMID termid, int no_rsets, RSET* rsets);
243 RSET rset_create_and(NMEM nmem, struct rset_key_control *kcontrol,
244 int scope, int no_rsets, RSET* rsets);
246 RSET rset_create_prox(NMEM nmem, struct rset_key_control *kcontrol,
247 int scope, int rset_no, RSET *rset,
248 int ordered, int exclusion, int relation, int distance);
250 RSET rsisamb_create(NMEM nmem, struct rset_key_control *kcontrol,
251 int scope, ISAMB is, ISAM_P pos, TERMID term);
253 RSET rsisamc_create(NMEM nmem, struct rset_key_control *kcontrol,
254 int scope, ISAMC is, ISAM_P pos, TERMID term);
256 RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol,
257 int scope, ISAMS is, ISAM_P pos, TERMID term);
259 void rset_visit(RSET rset, int level);
261 void rset_set_hits_limit(RSET rs, zint l);
269 * c-file-style: "Stroustrup"
270 * indent-tabs-mode: nil
272 * vim: shiftwidth=4 tabstop=8 expandtab