IDZEBRA 2.2.8
rset.h
Go to the documentation of this file.
1/* This file is part of the Zebra server.
2 Copyright (C) Index Data
3
4Zebra is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 2, or (at your option) any later
7version.
8
9Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, 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
30YAZ_BEGIN_CDECL
31
32typedef struct rsfd *RSFD;
33typedef struct rset *RSET;
34
35struct ord_list {
36 int ord;
37 struct ord_list *next;
38};
39
40struct ord_list *ord_list_create(NMEM nmem);
41struct ord_list *ord_list_append(NMEM nmem, struct ord_list *list, int ord);
42struct ord_list *ord_list_dup(NMEM nmem, struct ord_list *list);
43void ord_list_print(struct ord_list *list);
44
50struct rset_term {
51 char *name;
52 char *flags;
53 int type;
61 void *rankpriv;
63 char *ref_id;
64 struct ord_list *ol;
65};
66
67typedef struct rset_term *TERMID;
68TERMID 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
73struct 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 */
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
112int rset_default_forward(RSFD rfd, void *buf, TERMID *term,
113 const void *untilbuf);
114
116int rset_default_read(RSFD rfd, void *buf, TERMID *term);
117
118void rset_get_one_term(RSET ct,TERMID *terms,int maxterms,int *curterm);
119
127 void *context;
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 */
142};
143
150typedef 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 */
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
186int rfd_is_last(RSFD rfd);
187
188RSET 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
195void rset_delete(RSET rs);
196RSET rset_dup (RSET rs);
197void 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
227
228RSET rset_create_temp(NMEM nmem, struct rset_key_control *kcontrol,
229 int scope, const char *temp_path, TERMID term);
230
231RSET rset_create_null(NMEM nmem, struct rset_key_control *kcontrol, TERMID term);
232
233RSET rset_create_not(NMEM nmem, struct rset_key_control *kcontrol,
234 int scope, RSET rset_l, RSET rset_r);
235
236RSET 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
240RSET rset_create_or(NMEM nmem, struct rset_key_control *kcontrol,
241 int scope, TERMID termid, int no_rsets, RSET* rsets);
242
243RSET rset_create_and(NMEM nmem, struct rset_key_control *kcontrol,
244 int scope, int no_rsets, RSET* rsets);
245
246RSET 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
250RSET rsisamb_create(NMEM nmem, struct rset_key_control *kcontrol,
251 int scope, ISAMB is, ISAM_P pos, TERMID term);
252
253RSET rsisamc_create(NMEM nmem, struct rset_key_control *kcontrol,
254 int scope, ISAMC is, ISAM_P pos, TERMID term);
255
256RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol,
257 int scope, ISAMS is, ISAM_P pos, TERMID term);
258
259void rset_visit(RSET rset, int level);
260
261void rset_set_hits_limit(RSET rs, zint l);
262
263int rset_no_write(RSFD rfd, const void *buf);
264
265YAZ_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
zint ISAM_P
Definition isamc.h:28
int rfd_is_last(RSFD rfd)
Test for last use of RFD.
Definition rset.c:242
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
void rset_delete(RSET rs)
Destructor RSETs.
Definition rset.c:218
void rset_set_hits_limit(RSET rs, zint l)
Definition rset.c:88
RSET rset_create_or(NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID termid, int no_rsets, RSET *rsets)
void ord_list_print(struct ord_list *list)
Definition rset.c:323
RSET rsisamc_create(NMEM nmem, struct rset_key_control *kcontrol, int scope, ISAMC is, ISAM_P pos, TERMID term)
Definition rsisamc.c:61
RSET rset_create_and(NMEM nmem, struct rset_key_control *kcontrol, int scope, int no_rsets, RSET *rsets)
int rset_default_read(RSFD rfd, void *buf, TERMID *term)
Definition rset.c:371
RSET rsisamb_create(NMEM nmem, struct rset_key_control *kcontrol, int scope, ISAMB is, ISAM_P pos, TERMID term)
Definition rsisamb.c:76
struct rset_term * TERMID
Definition rset.h:67
RSET rset_dup(RSET rs)
Duplicate an RSET.
Definition rset.c:255
RSET rset_create_not(NMEM nmem, struct rset_key_control *kcontrol, int scope, RSET rset_l, RSET rset_r)
Definition rsbool.c:92
void rset_visit(RSET rset, int level)
Definition rset.c:421
int rset_default_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
Definition rset.c:396
struct rsfd * RSFD
Definition rset.h:32
int rset_no_write(RSFD rfd, const void *buf)
Definition rset.c:431
struct ord_list * ord_list_create(NMEM nmem)
Definition rset.c:301
RSFD rfd_create_base(RSET rs)
Common constuctor for RFDs.
Definition rset.c:43
zint rset_count(RSET rs)
Estimates hit count for result set.
Definition rset.c:272
struct ord_list * ord_list_dup(NMEM nmem, struct ord_list *list)
Definition rset.c:315
RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol, int scope, ISAMS is, ISAM_P pos, TERMID term)
Definition rsisams.c:57
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
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
struct ord_list * ord_list_append(NMEM nmem, struct ord_list *list, int ord)
Definition rset.c:306
RSET rset_create_null(NMEM nmem, struct rset_key_control *kcontrol, TERMID term)
Definition rsnull.c:47
void rset_get_one_term(RSET ct, TERMID *terms, int maxterms, int *curterm)
is a getterms function for those that don't have any
Definition rset.c:291
RSET rset_create_temp(NMEM nmem, struct rset_key_control *kcontrol, int scope, const char *temp_path, TERMID term)
Definition rstemp.c:86
struct rset * RSET
Definition rset.h:33
void rset_close(RSFD rfd)
Closes a result set RFD handle.
Definition rset.c:98
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
int ord
Definition rset.h:36
struct ord_list * next
Definition rset.h:37
int(* f_read)(RSFD rfd, void *buf, TERMID *term)
Definition rset.h:107
void(* f_close)(RSFD rfd)
Definition rset.h:102
void(* f_delete)(RSET ct)
Definition rset.h:94
void(* f_pos)(RSFD rfd, double *current, double *total)
Definition rset.h:105
int(* f_write)(RSFD rfd, const void *buf)
Definition rset.h:108
RSFD(* f_open)(RSET ct, int wflag)
Definition rset.h:101
int(* f_forward)(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
Definition rset.h:104
void(* f_getterms)(RSET ct, TERMID *terms, int maxterms, int *curterm)
Definition rset.h:99
char * desc
Definition rset.h:92
void(* dec)(struct rset_key_control *kc)
Definition rset.h:138
void * filter_data
Definition rset.h:136
int(* cmp)(const void *p1, const void *p2)
Definition rset.h:131
void(* key_logdump_txt)(int logmask, const void *p, const char *txt)
Definition rset.h:132
int(* filter_func)(const void *p, void *data)
Definition rset.h:135
void(* inc)(struct rset_key_control *kc)
Definition rset.h:137
zint(* getseq)(const void *p)
Definition rset.h:133
void * context
Definition rset.h:127
zint(* get_segment)(const void *p)
Definition rset.h:134
int type
Definition rset.h:53
char * flags
Definition rset.h:52
struct ord_list * ol
Definition rset.h:64
char * ref_id
Definition rset.h:63
zint hits_limit
Definition rset.h:62
char * name
Definition rset.h:51
int reg_type
Definition rset.h:59
RSET rset
Definition rset.h:60
void * rankpriv
Definition rset.h:61
Definition rset.h:151
int hits_approx
Definition rset.h:166
zint hits_limit
Definition rset.h:163
RSFD free_list
Definition rset.h:157
TERMID term
Definition rset.h:160
zint hits_round
Definition rset.h:165
RSET * children
Definition rset.h:162
const struct rset_control * control
Definition rset.h:152
NMEM nmem
Definition rset.h:156
RSFD use_list
Definition rset.h:158
struct rset_key_control * keycontrol
Definition rset.h:153
zint hits_count
Definition rset.h:164
int scope
Definition rset.h:159
int no_children
Definition rset.h:161
void * priv
Definition rset.h:155
int refcount
Definition rset.h:154
Definition rset.h:73
zint counted_items
Definition rset.h:77
void * priv
Definition rset.h:75
RSFD next
Definition rset.h:76
RSET rset
Definition rset.h:74
char * counted_buf
Definition rset.h:78
const char * scope
long zint
Zebra integer.
Definition util.h:66