ae1dd371d24f8eb2601665dbb882631e5532bb9c
[idzebra-moved-to-github.git] / include / rset.h
1 /* $Id: rset.h,v 1.37 2004-10-15 10:07:32 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA.
21 */
22
23
24
25 #ifndef RSET_H
26 #define RSET_H
27
28 #include <stdlib.h>
29
30 /* unfortunately we need the isam includes here, for the arguments for */
31 /* rsisamX_create */
32 #include <isamb.h> 
33 #include <isamc.h> 
34 #include <isams.h> 
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 typedef struct rsfd *RSFD; /* Rset "file descriptor" */
41 typedef struct rset *RSET; /* Result set */
42
43 /*
44 typedef struct terminfo *TERMID; 
45 */
46 typedef int TERMID; 
47        /* term thing for the rsets. They don't need to   */
48        /* know what it is. FIXME - define that somewhere */
49 /* using int while testing, to get more type checking to work */
50
51 struct rsfd {  /* the stuff common to all rsfd's. */
52     RSET rset;  /* ptr to the rset this FD is opened to */
53     void *priv; /* private parameters for this type */
54     RSFD next;  /* to keep lists of used/free rsfd's */
55 };
56
57
58 struct rset_control
59 {
60     char *desc; /* text description of set type (for debugging) */
61 /* RSET rs_something_create(const struct rset_control *sel, ...); */
62     void (*f_delete)(RSET ct);
63     RSFD (*f_open)(RSET ct, int wflag);
64     void (*f_close)(RSFD rfd);
65     int (*f_forward)(RSFD rfd, void *buf, TERMID *term, const void *untilbuf);
66     void (*f_pos)(RSFD rfd, double *current, double *total);
67        /* returns -1,-1 if pos function not implemented for this type */
68     int (*f_read)(RSFD rfd, void *buf, TERMID *term);
69     int (*f_write)(RSFD rfd, const void *buf);
70 };
71
72 int rset_default_forward(RSFD rfd, void *buf, TERMID *term,
73                      const void *untilbuf);
74
75 struct key_control {
76     int key_size;
77     int scope;  /* default for what level we operate (book/chapter/verse) on*/
78                 /* usual sysno/seqno is 2 */
79     int (*cmp) (const void *p1, const void *p2);
80     void (*key_logdump_txt) (int logmask, const void *p, const char *txt);
81     zint (*getseq)(const void *p);
82       /* FIXME - Should not need a getseq, it won't make much sense with */
83       /* higher-order keys. Use a (generalized) cmp instead, or something */
84     /* FIXME - decode and encode, and lots of other stuff */
85 };
86
87 typedef struct rset
88 {
89     const struct rset_control *control;
90     const struct key_control *keycontrol;
91     int  count;  /* reference count */
92     void *priv;  /* stuff private to the given type of rset */
93     NMEM nmem;    /* nibble memory for various allocs */
94     char my_nmem; /* Should the nmem be destroyed with the rset?  */
95                   /* 1 if created with it, 0 if passed from above */
96     RSFD free_list; /* all rfd's allocated but not currently in use */
97     int scope;    /* On what level do we count hits and compare them? */
98     TERMID term; /* the term thing for ranking etc */
99 } rset;
100 /* rset is a "virtual base class", which will never exist on its own 
101  * all instances are rsets of some specific type, like rsisamb, or rsbool
102  * They keep their own stuff behind the priv pointer.  */
103
104 /* On the old sysno-seqno type isams, the scope was hard-coded to be 2.
105  * This means that we count hits on the sysno level, and when matching an
106  * 'and', we consider it a match if both term occur within the same sysno.
107  * In more complex isams we can specify on what level we wish to do the
108  * matching and counting of hits. For example, we can have book / chapter /
109  * verse, and a seqno. Scope 2 means then "give me all verses that match",
110  * 3 would be chapters, 4 books. 
111  * The resolution tells how much of the occurences we need to return. If we 
112  * are doing some sort of proximity, we need to get the seqnos of all
113  * occurences, whereas if we are only counting hits, we do not need anything
114  * below the scope. Again 1 is seqnos, 2 sysnos (or verses), 3 books, etc.
115  */
116
117 RSFD rfd_create_base(RSET rs);
118 void rfd_delete_base(RSFD rfd);
119
120 RSET rset_create_base(const struct rset_control *sel, 
121                       NMEM nmem,
122                       const struct key_control *kcontrol,
123                       int scope,
124                       TERMID term);
125
126 void rset_delete(RSET rs);
127 RSET rset_dup (RSET rs);
128
129
130 #define RSETF_READ       0
131 #define RSETF_WRITE      1
132 /* RSFD rset_open(RSET rs, int wflag); */
133 #define rset_open(rs, wflag) (*(rs)->control->f_open)((rs), (wflag))
134
135 /* void rset_close(RSFD rfd); */
136 #define rset_close(rfd) (*(rfd)->rset->control->f_close)(rfd)
137
138 /* int rset_forward(RSFD rfd, void *buf, TERMID term, void *untilbuf); */
139 #define rset_forward(rfd, buf, term, untilbuf) \
140     (*(rfd)->rset->control->f_forward)((rfd),(buf),(term),(untilbuf))
141
142 /* int rset_pos(RSFD fd, double *current, double *total); */
143 #define rset_pos(rfd,cur,tot) \
144     (*(rfd)->rset->control->f_pos)( (rfd),(cur),(tot))
145
146 /* int rset_read(RSFD rfd, void *buf, TERMID term); */
147 #define rset_read(rfd, buf, term) \
148     (*(rfd)->rset->control->f_read)((rfd), (buf), (term))
149
150 /* int rset_write(RSFD rfd, const void *buf); */
151 #define rset_write(rfd, buf) (*(rfd)->rset->control->f_write)((rfd), (buf))
152
153 /* int rset_type (RSET) */
154 #define rset_type(rs) ((rs)->control->desc)
155
156 RSET rstemp_create( NMEM nmem, const struct key_control *kcontrol,
157                     int scope, 
158                     const char *temp_path);
159
160 RSET rsnull_create(NMEM nmem, const struct key_control *kcontrol);
161
162 RSET rsbool_create_and( NMEM nmem, const struct key_control *kcontrol,
163                         int scope, 
164                         RSET rset_l, RSET rset_r);
165
166 RSET rsbool_create_or ( NMEM nmem, const struct key_control *kcontrol,
167                         int scope,
168                         RSET rset_l, RSET rset_r);
169
170 RSET rsbool_create_not( NMEM nmem, const struct key_control *kcontrol,
171                         int scope,
172                         RSET rset_l, RSET rset_r);
173
174 RSET rsbetween_create(  NMEM nmem, const struct key_control *kcontrol,
175                         int scope, 
176                         RSET rset_l, RSET rset_m, RSET rset_r, 
177                         RSET rset_attr);
178
179 RSET rsmultior_create(  NMEM nmem, const struct key_control *kcontrol,
180                         int scope, 
181                         int no_rsets, RSET* rsets);
182
183 RSET rsmultiand_create( NMEM nmem, const struct key_control *kcontrol,
184                         int scope, 
185                         int no_rsets, RSET* rsets);
186
187 RSET rsprox_create( NMEM nmem, const struct key_control *kcontrol,
188                         int scope, 
189                     int rset_no, RSET *rset,
190                     int ordered, int exclusion,
191                     int relation, int distance);
192
193 RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol,
194                         int scope, 
195                      ISAMB is, ISAMB_P pos,
196                      TERMID term);
197
198 RSET rsisamc_create( NMEM nmem, const struct key_control *kcontrol,
199                         int scope, 
200                      ISAMC is, ISAMC_P pos,
201                      TERMID term);
202
203 RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol,
204                         int scope,
205                      ISAMS is, ISAMS_P pos,
206                      TERMID term);
207
208
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214 #endif