IDZEBRA  2.1.2
rset.h
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
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
7 version.
8 
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
12 for more details.
13 
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
17 
18 */
19 
20 #ifndef RSET_H
21 #define RSET_H
22 
23 #include <yaz/yaz-util.h>
24 /* unfortunately we need the isam includes here, for the arguments for */
25 /* rsisamX_create */
26 #include <idzebra/isamb.h>
27 #include <idzebra/isamc.h>
28 #include <idzebra/isams.h>
29 
30 YAZ_BEGIN_CDECL
31 
32 typedef struct rsfd *RSFD;
33 typedef struct rset *RSET;
34 
35 struct ord_list {
36  int ord;
37  struct ord_list *next;
38 };
39 
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);
44 
50 struct rset_term {
51  char *name;
52  char *flags;
53  int type;
59  int reg_type;
60  RSET rset;
61  void *rankpriv;
63  char *ref_id;
64  struct ord_list *ol;
65 };
66 
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);
71 
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 */
78  char *counted_buf;
79 };
80 
81 
90 {
92  char *desc;
93 /* RSET rs_something_create(const struct rset_control *sel, ...); */
94  void (*f_delete)(RSET ct);
95 
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);
100 
101  RSFD (*f_open)(RSET ct, int wflag);
102  void (*f_close)(RSFD rfd);
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);
109 };
110 
112 int rset_default_forward(RSFD rfd, void *buf, TERMID *term,
113  const void *untilbuf);
114 
116 int rset_default_read(RSFD rfd, void *buf, TERMID *term);
117 
118 void rset_get_one_term(RSET ct,TERMID *terms,int maxterms,int *curterm);
119 
127  void *context;
128  int key_size;
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);
136  void *filter_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 */
142 };
143 
150 typedef struct rset
151 {
152  const struct rset_control *control;
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 */
162  RSET *children;
167 } rset;
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. */
171 
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.
183  */
184 
185 RSFD rfd_create_base(RSET rs);
186 int rfd_is_last(RSFD rfd);
187 
188 RSET rset_create_base(const struct rset_control *sel,
189  NMEM nmem,
190  struct rset_key_control *kcontrol,
191  int scope,
192  TERMID term,
193  int no_children, RSET *children);
194 
195 void rset_delete(RSET rs);
196 RSET rset_dup (RSET rs);
197 void rset_close(RSFD rfd);
198 
199 #define RSETF_READ 0
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))
203 
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))
207 
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))
211 
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))
215 
216 /* int rset_read(RSFD rfd, void *buf, TERMID term); */
217 #define rset_read(rfd, buf, term) rset_default_read((rfd), (buf), (term))
218 
219 /* int rset_write(RSFD rfd, const void *buf); */
220 #define rset_write(rfd, buf) (*(rfd)->rset->control->f_write)((rfd), (buf))
221 
222 /* int rset_type (RSET) */
223 #define rset_type(rs) ((rs)->control->desc)
224 
226 zint rset_count(RSET rs);
227 
228 RSET rset_create_temp(NMEM nmem, struct rset_key_control *kcontrol,
229  int scope, const char *temp_path, TERMID term);
230 
231 RSET rset_create_null(NMEM nmem, struct rset_key_control *kcontrol, TERMID term);
232 
233 RSET rset_create_not(NMEM nmem, struct rset_key_control *kcontrol,
234  int scope, RSET rset_l, RSET rset_r);
235 
236 RSET rset_create_between(NMEM nmem, struct rset_key_control *kcontrol,
237  int scope, RSET rset_l, RSET rset_m1, RSET rset_m2,
238  RSET rset_r, RSET rset_attr);
239 
240 RSET rset_create_or(NMEM nmem, struct rset_key_control *kcontrol,
241  int scope, TERMID termid, int no_rsets, RSET* rsets);
242 
243 RSET rset_create_and(NMEM nmem, struct rset_key_control *kcontrol,
244  int scope, int no_rsets, RSET* rsets);
245 
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);
249 
250 RSET rsisamb_create(NMEM nmem, struct rset_key_control *kcontrol,
251  int scope, ISAMB is, ISAM_P pos, TERMID term);
252 
253 RSET rsisamc_create(NMEM nmem, struct rset_key_control *kcontrol,
254  int scope, ISAMC is, ISAM_P pos, TERMID term);
255 
256 RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol,
257  int scope, ISAMS is, ISAM_P pos, TERMID term);
258 
259 void rset_visit(RSET rset, int level);
260 
261 void rset_set_hits_limit(RSET rs, zint l);
262 
263 int rset_no_write(RSFD rfd, const void *buf);
264 
265 YAZ_END_CDECL
266 
267 #endif
268 /*
269  * Local variables:
270  * c-basic-offset: 4
271  * c-file-style: "Stroustrup"
272  * indent-tabs-mode: nil
273  * End:
274  * vim: shiftwidth=4 tabstop=8 expandtab
275  */
276 
RSET rset_create_prox(NMEM nmem, struct rset_key_control *kcontrol, int scope, int rset_no, RSET *rset, int ordered, int exclusion, int relation, int distance)
Definition: rsprox.c:72
zint hits_limit
Definition: rset.h:62
int type
Definition: rset.h:53
RSFD next
Definition: rset.h:76
void * rankpriv
Definition: rset.h:61
zint hits_limit
Definition: rset.h:163
void ord_list_print(struct ord_list *list)
Definition: rset.c:323
zint ISAM_P
Definition: isamc.h:28
TERMID term
Definition: rset.h:160
struct rset_key_control * keycontrol
Definition: rset.h:153
struct rset rset
int rset_default_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
Definition: rset.c:396
Definition: isams.c:40
RSFD rfd_create_base(RSET rs)
Common constuctor for RFDs.
Definition: rset.c:43
zint hits_round
Definition: rset.h:165
int ord
Definition: rset.h:36
RSET rset_dup(RSET rs)
Duplicate an RSET.
Definition: rset.c:255
int no_children
Definition: rset.h:161
int scope
Definition: rset.h:159
int hits_approx
Definition: rset.h:166
int key_size
Definition: rset.h:128
RSFD free_list
Definition: rset.h:157
int rset_no_write(RSFD rfd, const void *buf)
Definition: rset.c:431
const struct rset_control * control
Definition: rset.h:152
int refcount
Definition: rset.h:154
RSET rset
Definition: rset.h:74
RSET rsisamb_create(NMEM nmem, struct rset_key_control *kcontrol, int scope, ISAMB is, ISAM_P pos, TERMID term)
Definition: rsisamb.c:76
char * flags
Definition: rset.h:52
const char * scope
Definition: tstlockscope.c:40
struct ord_list * ord_list_create(NMEM nmem)
Definition: rset.c:301
void rset_delete(RSET rs)
Destructor RSETs.
Definition: rset.c:218
struct rsfd * RSFD
Definition: rset.h:32
zint rset_count(RSET rs)
Estimates hit count for result set.
Definition: rset.c:272
void * priv
Definition: rset.h:155
struct ord_list * ol
Definition: rset.h:64
RSET rset_create_and(NMEM nmem, struct rset_key_control *kcontrol, int scope, int no_rsets, RSET *rsets)
Definition: rsmultiandor.c:280
void rset_set_hits_limit(RSET rs, zint l)
Definition: rset.c:88
zint counted_items
Definition: rset.h:77
void * filter_data
Definition: rset.h:136
RSET * children
Definition: rset.h:162
zint hits_count
Definition: rset.h:164
RSET rset_create_null(NMEM nmem, struct rset_key_control *kcontrol, TERMID term)
Definition: rsnull.c:47
char * desc
Definition: rset.h:92
Definition: isamb.c:94
void rset_get_one_term(RSET ct, TERMID *terms, int maxterms, int *curterm)
is a getterms function for those that don&#39;t have any
Definition: rset.c:291
void rset_visit(RSET rset, int level)
Definition: rset.c:421
TERMID rset_term_create(const char *name, int length, const char *flags, int type, NMEM nmem, struct ord_list *ol, int reg_type, zint hits_limit, const char *ref_id)
Creates a TERMID entry.
Definition: rset.c:340
void(* dec)(struct rset_key_control *kc)
Definition: rset.h:138
struct rset * RSET
Definition: rset.h:33
struct ord_list * next
Definition: rset.h:37
char * ref_id
Definition: rset.h:63
int reg_type
Definition: rset.h:59
RSET rset_create_between(NMEM nmem, struct rset_key_control *kcontrol, int scope, RSET rset_l, RSET rset_m1, RSET rset_m2, RSET rset_r, RSET rset_attr)
Definition: rsbetween.c:101
RSFD use_list
Definition: rset.h:158
long zint
Zebra integer.
Definition: util.h:66
NMEM nmem
Definition: rset.h:156
RSET rset_create_or(NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID termid, int no_rsets, RSET *rsets)
Definition: rsmultiandor.c:273
char * counted_buf
Definition: rset.h:78
Definition: rset.h:150
Definition: rset.h:73
RSET rset
Definition: rset.h:60
RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol, int scope, ISAMS is, ISAM_P pos, TERMID term)
Definition: rsisams.c:57
struct ord_list * ord_list_append(NMEM nmem, struct ord_list *list, int ord)
Definition: rset.c:306
void * priv
Definition: rset.h:75
int rset_default_read(RSFD rfd, void *buf, TERMID *term)
Definition: rset.c:371
RSET rset_create_temp(NMEM nmem, struct rset_key_control *kcontrol, int scope, const char *temp_path, TERMID term)
Definition: rstemp.c:84
void rset_close(RSFD rfd)
Closes a result set RFD handle.
Definition: rset.c:98
Definition: rset.h:50
Definition: rset.h:35
int rfd_is_last(RSFD rfd)
Test for last use of RFD.
Definition: rset.c:242
RSET rset_create_not(NMEM nmem, struct rset_key_control *kcontrol, int scope, RSET rset_l, RSET rset_r)
Definition: rsbool.c:92
RSET rset_create_base(const struct rset_control *sel, NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID term, int no_children, RSET *children)
Common constuctor for RSETs.
Definition: rset.c:164
RSET rsisamc_create(NMEM nmem, struct rset_key_control *kcontrol, int scope, ISAMC is, ISAM_P pos, TERMID term)
Definition: rsisamc.c:61
struct rset_term * TERMID
Definition: rset.h:67
void key_logdump_txt(int logmask, const void *p, const char *txt)
Definition: it_key.c:37
struct ord_list * ord_list_dup(NMEM nmem, struct ord_list *list)
Definition: rset.c:315
void * context
Definition: rset.h:127
char * name
Definition: rset.h:51