1 /* $Id: rset.h,v 1.38 2004-10-20 14:32:28 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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
30 /* unfortunately we need the isam includes here, for the arguments for */
40 typedef struct rsfd *RSFD; /* Rset "file descriptor" */
41 typedef struct rset *RSET; /* Result set */
45 * rset_term is all we need to know of a term to do ranking etc.
46 * As far as the rsets are concerned, it is just a dummy pointer to
58 typedef struct rset_term *TERMID;
59 TERMID rset_term_create (const char *name, int length, const char *flags,
64 /** rsfd is a "file descriptor" for reading from a rset */
65 struct rsfd { /* the stuff common to all rsfd's. */
66 RSET rset; /* ptr to the rset this FD is opened to */
67 void *priv; /* private parameters for this type */
68 RSFD next; /* to keep lists of used/free rsfd's */
73 * rset_control has function pointers to all the important functions
74 * of a rset. Each type of rset will have its own control block, pointing
75 * to the functions for that type. They all have their own create function
76 * which is not part of the control block, as it takes different args for
81 char *desc; /* text description of set type (for debugging) */
82 /* RSET rs_something_create(const struct rset_control *sel, ...); */
83 void (*f_delete)(RSET ct);
84 RSFD (*f_open)(RSET ct, int wflag);
85 void (*f_close)(RSFD rfd);
86 int (*f_forward)(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
87 void (*f_pos)(RSFD rfd, double *current, double *total);
88 /* returns -1,-1 if pos function not implemented for this type */
89 int (*f_read)(RSFD rfd, void *buf, TERMID *term);
90 int (*f_write)(RSFD rfd, const void *buf);
93 /** rset_default_forward implements a generic forward with a read-loop */
94 int rset_default_forward(RSFD rfd, void *buf, TERMID *term,
95 const void *untilbuf);
98 * key_control contains all there is to know about the keys stored in
99 * an isam, and therefore operated by the rsets. Other than this info,
100 * all we assume is that all keys are the same size, and they can be
105 int scope; /* default for what level we operate (book/chapter/verse) on*/
106 /* usual sysno/seqno is 2 */
107 int (*cmp) (const void *p1, const void *p2);
108 void (*key_logdump_txt) (int logmask, const void *p, const char *txt);
109 zint (*getseq)(const void *p);
110 /* FIXME - Should not need a getseq, it won't make much sense with */
111 /* higher-order keys. Use a (generalized) cmp instead, or something */
112 /* FIXME - decode and encode, and lots of other stuff */
116 * A rset is an ordered sequence of keys, either directly from an underlaying
117 * isam, or from one of the higher-level operator rsets (and, or, ...).
118 * Actually, it is "virtual base class", no pure rsets exist in the system,
119 * they all are of some derived type.
123 const struct rset_control *control;
124 const struct key_control *keycontrol;
125 int count; /* reference count */
126 void *priv; /* stuff private to the given type of rset */
127 NMEM nmem; /* nibble memory for various allocs */
128 char my_nmem; /* Should the nmem be destroyed with the rset? */
129 /* 1 if created with it, 0 if passed from above */
130 RSFD free_list; /* all rfd's allocated but not currently in use */
131 int scope; /* On what level do we count hits and compare them? */
132 TERMID term; /* the term thing for ranking etc */
134 /* rset is a "virtual base class", which will never exist on its own
135 * all instances are rsets of some specific type, like rsisamb, or rsbool
136 * They keep their own stuff behind the priv pointer. */
138 /* On the old sysno-seqno type isams, the scope was hard-coded to be 2.
139 * This means that we count hits on the sysno level, and when matching an
140 * 'and', we consider it a match if both term occur within the same sysno.
141 * In more complex isams we can specify on what level we wish to do the
142 * matching and counting of hits. For example, we can have book / chapter /
143 * verse, and a seqno. Scope 2 means then "give me all verses that match",
144 * 3 would be chapters, 4 books.
145 * The resolution tells how much of the occurences we need to return. If we
146 * are doing some sort of proximity, we need to get the seqnos of all
147 * occurences, whereas if we are only counting hits, we do not need anything
148 * below the scope. Again 1 is seqnos, 2 sysnos (or verses), 3 books, etc.
151 RSFD rfd_create_base(RSET rs);
152 void rfd_delete_base(RSFD rfd);
154 RSET rset_create_base(const struct rset_control *sel,
156 const struct key_control *kcontrol,
160 void rset_delete(RSET rs);
161 RSET rset_dup (RSET rs);
165 #define RSETF_WRITE 1
166 /* RSFD rset_open(RSET rs, int wflag); */
167 #define rset_open(rs, wflag) (*(rs)->control->f_open)((rs), (wflag))
169 /* void rset_close(RSFD rfd); */
170 #define rset_close(rfd) (*(rfd)->rset->control->f_close)(rfd)
172 /* int rset_forward(RSFD rfd, void *buf, TERMID term, void *untilbuf); */
173 #define rset_forward(rfd, buf, term, untilbuf) \
174 (*(rfd)->rset->control->f_forward)((rfd),(buf),(term),(untilbuf))
176 /* int rset_pos(RSFD fd, double *current, double *total); */
177 #define rset_pos(rfd,cur,tot) \
178 (*(rfd)->rset->control->f_pos)( (rfd),(cur),(tot))
180 /* int rset_read(RSFD rfd, void *buf, TERMID term); */
181 #define rset_read(rfd, buf, term) \
182 (*(rfd)->rset->control->f_read)((rfd), (buf), (term))
184 /* int rset_write(RSFD rfd, const void *buf); */
185 #define rset_write(rfd, buf) (*(rfd)->rset->control->f_write)((rfd), (buf))
187 /* int rset_type (RSET) */
188 #define rset_type(rs) ((rs)->control->desc)
190 RSET rstemp_create( NMEM nmem, const struct key_control *kcontrol,
192 const char *temp_path);
194 RSET rsnull_create(NMEM nmem, const struct key_control *kcontrol);
196 RSET rsbool_create_and( NMEM nmem, const struct key_control *kcontrol,
198 RSET rset_l, RSET rset_r);
200 RSET rsbool_create_or ( NMEM nmem, const struct key_control *kcontrol,
202 RSET rset_l, RSET rset_r);
204 RSET rsbool_create_not( NMEM nmem, const struct key_control *kcontrol,
206 RSET rset_l, RSET rset_r);
208 RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol,
210 RSET rset_l, RSET rset_m, RSET rset_r,
213 RSET rsmultior_create( NMEM nmem, const struct key_control *kcontrol,
215 int no_rsets, RSET* rsets);
217 RSET rsmultiand_create( NMEM nmem, const struct key_control *kcontrol,
219 int no_rsets, RSET* rsets);
221 RSET rsprox_create( NMEM nmem, const struct key_control *kcontrol,
223 int rset_no, RSET *rset,
224 int ordered, int exclusion,
225 int relation, int distance);
227 RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol,
229 ISAMB is, ISAMB_P pos,
232 RSET rsisamc_create( NMEM nmem, const struct key_control *kcontrol,
234 ISAMC is, ISAMC_P pos,
237 RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol,
239 ISAMS is, ISAMS_P pos,