1 /* $Id: rset.h,v 1.34 2004-09-09 10:08:04 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 */
43 struct rsfd { /* the stuff common to all rsfd's. */
44 RSET rset; /* ptr to the rset this FD is opened to */
45 void *priv; /* private parameters for this type */
46 RSFD next; /* to keep lists of used/free rsfd's */
52 char *desc; /* text description of set type (for debugging) */
53 /* RSET rs_something_create(const struct rset_control *sel, ...); */
54 void (*f_delete)(RSET ct);
55 RSFD (*f_open)(RSET ct, int wflag);
56 void (*f_close)(RSFD rfd);
57 void (*f_rewind)(RSFD rfd);
58 int (*f_forward)(RSFD rfd, void *buf, const void *untilbuf);
59 void (*f_pos)(RSFD rfd, double *current, double *total);
60 /* returns -1,-1 if pos function not implemented for this type */
61 int (*f_read)(RSFD rfd, void *buf);
62 int (*f_write)(RSFD rfd, const void *buf);
65 int rset_default_forward(RSFD rfd, void *buf,
66 const void *untilbuf);
70 int scope; /* default for what level we operate (book/chapter/verse) on*/
71 /* usual sysno/seqno is 2 */
72 int (*cmp) (const void *p1, const void *p2);
73 void (*key_logdump_txt) (int logmask, const void *p, const char *txt);
74 zint (*getseq)(const void *p);
75 /* FIXME - Should not need a getseq, it won't make much sense with */
76 /* higher-order keys. Use a (generalized) cmp instead, or something */
77 /* FIXME - decode and encode, and lots of other stuff */
82 const struct rset_control *control;
83 const struct key_control *keycontrol;
84 int count; /* reference count */
85 void *priv; /* stuff private to the given type of rset */
86 NMEM nmem; /* nibble memory for various allocs */
87 char my_nmem; /* Should the nmem be destroyed with the rset? */
88 /* 1 if created with it, 0 if passed from above */
89 RSFD free_list; /* all rfd's allocated but not currently in use */
90 int scope; /* On what level do we count hits and compare them? */
92 /* rset is a "virtual base class", which will never exist on its own
93 * all instances are rsets of some specific type, like rsisamb, or rsbool
94 * They keep their own stuff behind the priv pointer. */
96 /* On the old sysno-seqno type isams, the scope was hard-coded to be 2.
97 * This means that we count hits on the sysno level, and when matching an
98 * 'and', we consider it a match if both term occur within the same sysno.
99 * In more complex isams we can specify on what level we wish to do the
100 * matching and counting of hits. For example, we can have book / chapter /
101 * verse, and a seqno. Scope 2 means then "give me all verses that match",
102 * 3 would be chapters, 4 books.
103 * The resolution tells how much of the occurences we need to return. If we
104 * are doing some sort of proximity, we need to get the seqnos of all
105 * occurences, whereas if we are only counting hits, we do not need anything
106 * below the scope. Again 1 is seqnos, 2 sysnos (or verses), 3 books, etc.
108 /* FIXME - Add a resolution, to decide on what level we want to return */
109 /* hits. That can well be below scope, if we need to get seqnos for prox */
112 RSFD rfd_create_base(RSET rs);
113 void rfd_delete_base(RSFD rfd);
115 RSET rset_create_base(const struct rset_control *sel,
117 const struct key_control *kcontrol,
119 void rset_delete(RSET rs);
120 RSET rset_dup (RSET rs);
124 #define RSETF_WRITE 1
125 /* RSFD rset_open(RSET rs, int wflag); */
126 #define rset_open(rs, wflag) (*(rs)->control->f_open)((rs), (wflag))
128 /* void rset_close(RSFD rfd); */
129 #define rset_close(rfd) (*(rfd)->rset->control->f_close)(rfd)
131 /* void rset_rewind(RSFD rfd); */
132 #define rset_rewind(rfd) (*(rfd)->rset->control->f_rewind)((rfd))
134 /* int rset_forward(RSFD rfd, void *buf, void *untilbuf); */
135 #define rset_forward(rfd, buf, untilbuf) \
136 (*(rfd)->rset->control->f_forward)((rfd),(buf),(untilbuf))
138 /* int rset_pos(RSFD fd, double *current, double *total); */
139 #define rset_pos(rfd,cur,tot) \
140 (*(rfd)->rset->control->f_pos)( (rfd),(cur),(tot))
142 /* int rset_read(RSFD rfd, void *buf); */
143 #define rset_read(rfd, buf) (*(rfd)->rset->control->f_read)((rfd), (buf))
145 /* int rset_write(RSFD rfd, const void *buf); */
146 #define rset_write(rfd, buf) (*(rfd)->rset->control->f_write)((rfd), (buf))
148 /* int rset_type (RSET) */
149 #define rset_type(rs) ((rs)->control->desc)
151 RSET rstemp_create( NMEM nmem, const struct key_control *kcontrol,
153 const char *temp_path);
155 RSET rsnull_create(NMEM nmem, const struct key_control *kcontrol);
157 RSET rsbool_create_and( NMEM nmem, const struct key_control *kcontrol,
159 RSET rset_l, RSET rset_r);
161 RSET rsbool_create_or ( NMEM nmem, const struct key_control *kcontrol,
163 RSET rset_l, RSET rset_r);
165 RSET rsbool_create_not( NMEM nmem, const struct key_control *kcontrol,
167 RSET rset_l, RSET rset_r);
169 RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol,
171 RSET rset_l, RSET rset_m, RSET rset_r,
174 RSET rsmultior_create( NMEM nmem, const struct key_control *kcontrol,
176 int no_rsets, RSET* rsets);
178 RSET rsprox_create( NMEM nmem, const struct key_control *kcontrol,
180 int rset_no, RSET *rset,
181 int ordered, int exclusion,
182 int relation, int distance);
184 RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol,
186 ISAMB is, ISAMB_P pos);
188 RSET rsisamc_create( NMEM nmem, const struct key_control *kcontrol,
190 ISAMC is, ISAMC_P pos);
192 RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol,
194 ISAMS is, ISAMS_P pos);