Support for relations on text operands. Open range support in
[idzebra-moved-to-github.git] / index / zserver.h
1 /*
2  * Copyright (C) 1994-1998, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: zserver.h,v $
7  * Revision 1.36  1998-06-24 12:16:16  adam
8  * Support for relations on text operands. Open range support in
9  * DFA module (i.e. [-j], [g-]).
10  *
11  * Revision 1.35  1998/06/23 15:33:35  adam
12  * Added feature to specify sort criteria in query (type 7 specifies
13  * sort flags).
14  *
15  * Revision 1.34  1998/06/22 11:36:50  adam
16  * Added authentication check facility to zebra.
17  *
18  * Revision 1.33  1998/06/12 12:22:14  adam
19  * Work on Zebra API.
20  *
21  * Revision 1.32  1998/05/27 16:57:47  adam
22  * Zebra returns surrogate diagnostic for single records when
23  * appropriate.
24  *
25  * Revision 1.31  1998/05/20 10:12:23  adam
26  * Implemented automatic EXPLAIN database maintenance.
27  * Modified Zebra to work with ASN.1 compiled version of YAZ.
28  *
29  * Revision 1.30  1998/03/05 08:45:13  adam
30  * New result set model and modular ranking system. Moved towards
31  * descent server API. System information stored as "SGML" records.
32  *
33  * Revision 1.29  1998/02/10 12:03:06  adam
34  * Implemented Sort.
35  *
36  * Revision 1.28  1998/01/29 13:40:11  adam
37  * Better logging for scan service.
38  *
39  * Revision 1.27  1997/10/27 14:33:06  adam
40  * Moved towards generic character mapping depending on "structure"
41  * field in abstract syntax file. Fixed a few memory leaks. Fixed
42  * bug with negative integers when doing searches with relational
43  * operators.
44  *
45  * Revision 1.26  1997/09/29 12:41:35  adam
46  * Fixed bug regarding USE_TIMES var.
47  *
48  * Revision 1.25  1997/09/29 09:08:36  adam
49  * Revised locking system to be thread safe for the server.
50  *
51  * Revision 1.24  1997/09/17 12:19:19  adam
52  * Zebra version corresponds to YAZ version 1.4.
53  * Changed Zebra server so that it doesn't depend on global common_resource.
54  *
55  * Revision 1.23  1996/12/23 15:30:46  adam
56  * Work on truncation.
57  * Bug fix: result sets weren't deleted after server shut down.
58  *
59  * Revision 1.22  1996/11/04 14:07:49  adam
60  * Moved truncation code to trunc.c.
61  *
62  * Revision 1.21  1996/10/29 14:09:58  adam
63  * Use of cisam system - enabled if setting isamc is 1.
64  *
65  * Revision 1.20  1996/06/04 10:19:02  adam
66  * Minor changes - removed include of ctype.h.
67  *
68  * Revision 1.19  1996/05/14  11:34:01  adam
69  * Scan support in multiple registers/databases.
70  *
71  * Revision 1.18  1996/05/14  06:16:50  adam
72  * Compact use/set bytes used in search service.
73  *
74  * Revision 1.17  1995/12/08 16:22:57  adam
75  * Work on update while servers are running. Three lock files introduced.
76  * The servers reload their registers when necessary, but they don't
77  * reestablish result sets yet.
78  *
79  * Revision 1.16  1995/12/07  17:38:48  adam
80  * Work locking mechanisms for concurrent updates/commit.
81  *
82  * Revision 1.15  1995/11/21  15:29:13  adam
83  * Config file 'base' read by default by both indexer and server.
84  *
85  * Revision 1.14  1995/11/16  17:00:57  adam
86  * Better logging of rpn query.
87  *
88  * Revision 1.13  1995/11/16  15:34:56  adam
89  * Uses new record management system in both indexer and server.
90  *
91  * Revision 1.12  1995/10/27  14:00:12  adam
92  * Implemented detection of database availability.
93  *
94  * Revision 1.11  1995/10/17  18:02:12  adam
95  * New feature: databases. Implemented as prefix to words in dictionary.
96  *
97  * Revision 1.10  1995/10/09  16:18:38  adam
98  * Function dict_lookup_grep got extra client data parameter.
99  *
100  * Revision 1.9  1995/10/06  14:38:01  adam
101  * New result set method: r_score.
102  * Local no (sysno) and score is transferred to retrieveCtrl.
103  *
104  * Revision 1.8  1995/10/06  13:52:06  adam
105  * Bug fixes. Handler may abort further scanning.
106  *
107  * Revision 1.7  1995/10/06  10:43:57  adam
108  * Scan added. 'occurrences' in scan entries not set yet.
109  *
110  * Revision 1.6  1995/09/28  09:19:48  adam
111  * xfree/xmalloc used everywhere.
112  * Extract/retrieve method seems to work for text records.
113  *
114  * Revision 1.5  1995/09/27  16:17:32  adam
115  * More work on retrieve.
116  *
117  * Revision 1.4  1995/09/14  11:53:28  adam
118  * First work on regular expressions/truncations.
119  *
120  * Revision 1.3  1995/09/08  08:53:23  adam
121  * Record buffer maintained in server_info.
122  *
123  * Revision 1.2  1995/09/06  16:11:19  adam
124  * Option: only one word key per file.
125  *
126  * Revision 1.1  1995/09/05  15:28:40  adam
127  * More work on search engine.
128  *
129  */
130
131
132 #ifndef USE_TIMES
133 #ifdef __linux__
134 #define USE_TIMES 1
135 #else
136 #define USE_TIMES 0
137 #endif
138 #endif
139
140 #if USE_TIMES
141 #include <sys/times.h>
142 #endif
143
144 #include <backend.h>
145 #include <rset.h>
146
147 #include <sortidx.h>
148 #include <passwddb.h>
149 #include "index.h"
150 #include "zebraapi.h"
151 #include "zinfo.h"
152
153 typedef struct {
154     int sysno;
155     int score;
156 } *ZebraPosSet;
157
158 typedef struct zebra_set *ZebraSet;
159
160 typedef struct zebra_rank_class {
161     struct rank_control *control;
162     int init_flag;
163     void *class_handle;
164     struct zebra_rank_class *next;
165 } *ZebraRankClass;
166
167 struct zebra_info {
168     int registerState; /* 0 (no commit pages), 1 (use commit pages) */
169     time_t registerChange;
170     ZebraSet sets;
171     Dict dict;
172     SortIdx sortIdx;
173     ISAM isam;
174     ISAMC isamc;
175     Records records;
176     int errCode;
177     int hits;
178     char *errString;
179     ZebraExplainInfo zei;
180     data1_handle dh;
181     BFiles bfs;
182     Res res;
183
184     ZebraLockHandle server_lock_cmt;
185     ZebraLockHandle server_lock_org;
186     char *server_path_prefix;
187 #if USE_TIMES
188     struct tms tms1;
189     struct tms tms2;    
190 #endif
191     ZebraMaps zebra_maps;
192     ZebraRankClass rank_classes;
193     Passwd_db passwd_db;
194 };
195
196
197 struct rank_control {
198     char *name;
199     void *(*create)(ZebraHandle zh);
200     void (*destroy)(ZebraHandle zh, void *class_handle);
201     void *(*begin)(ZebraHandle zh, void *class_handle, RSET rset);
202     void (*end)(ZebraHandle zh, void *set_handle);
203     int (*calc)(void *set_handle, int sysno);
204     void (*add)(void *set_handle, int seqno, int term_index);
205 };
206
207 void rpn_search (ZebraHandle zh, ODR stream,
208                  Z_RPNQuery *rpn, int num_bases, char **basenames, 
209                  const char *setname);
210
211
212 void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
213                oid_value attributeset,
214                int num_bases, char **basenames,
215                int *position, int *num_entries, ZebraScanEntry **list,
216                int *is_partial);
217
218 RSET rset_trunc (ZebraHandle zh, ISAM_P *isam_p, int no,
219                  const char *term, int length_term, const char *flags);
220
221 ZebraSet resultSetAdd (ZebraHandle zh, const char *name,
222                           int ov, RSET rset, int *hits);
223 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
224 RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
225 void resultSetDestroy (ZebraHandle zh);
226
227 ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
228                                int num, int *positions);
229 void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
230
231 void resultSetSort (ZebraHandle zh, ODR stream,
232                     int num_input_setnames, const char **input_setnames,
233                     const char *output_setname,
234                     Z_SortKeySpecList *sort_sequence, int *sort_status);
235
236 void zebra_sort (ZebraHandle zh, ODR stream,
237                  int num_input_setnames, const char **input_setnames,
238                  const char *output_setname, Z_SortKeySpecList *sort_sequence,
239                  int *sort_status);
240
241 void zlog_rpn (Z_RPNQuery *rpn);
242 void zlog_scan (Z_AttributesPlusTerm *zapt, oid_value ast);
243
244 int zebra_server_lock_init (ZebraHandle zh);
245 int zebra_server_lock_destroy (ZebraHandle zh);
246 int zebra_server_lock (ZebraHandle zh, int lockCommit);
247 void zebra_server_unlock (ZebraHandle zh, int commitPhase);
248 int zebra_server_lock_get_state (ZebraHandle zh, time_t *timep);
249
250 typedef struct attent
251 {
252     int attset_ordinal;
253     data1_local_attribute *local_attributes;
254 } attent;
255
256 void zebraRankInstall (ZebraHandle zh, struct rank_control *ctrl);
257 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
258 void zebraRankDestroy (ZebraHandle zh);
259
260 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
261
262 extern struct rank_control *rank1_class;
263
264 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
265                         oid_value input_format, Z_RecordComposition *comp,
266                         oid_value *output_format, char **rec_bufp,
267                         int *rec_lenp, char **basenamep);
268