d0c936b45889b774f293ac5b572aff8c03671112
[idzebra-moved-to-github.git] / index / zserver.h
1 /*
2  * Copyright (C) 1994-2001, Index Data 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: zserver.h,v 1.51 2001-10-15 19:53:43 adam Exp $
7  */
8
9 #if HAVE_SYS_TIMES_H
10 #include <sys/times.h>
11 #endif
12
13 #include <yaz/backend.h>
14 #include <rset.h>
15
16 #include <sortidx.h>
17 #include <passwddb.h>
18 #include "index.h"
19 #include "zebraapi.h"
20 #include "zinfo.h"
21
22 YAZ_BEGIN_CDECL
23
24 typedef struct {
25     char *term;
26     char *db;
27     int sysno;
28     int score;
29 } *ZebraPosSet;
30
31 typedef struct zebra_set *ZebraSet;
32
33 typedef struct zebra_rank_class {
34     struct rank_control *control;
35     int init_flag;
36     void *class_handle;
37     struct zebra_rank_class *next;
38 } *ZebraRankClass;
39
40 struct zebra_service {
41     char *configName;
42     struct zebra_session *sessions;
43     ISAMS isams;
44 #if ZMBOL
45     ISAM isam;
46     ISAMC isamc;
47     ISAMD isamd;
48 #endif
49     Dict dict;
50     SortIdx sortIdx;
51     int registerState; /* 0 (no commit pages), 1 (use commit pages) */
52     time_t registerChange;
53     BFiles bfs;
54     Records records;
55     ZebraExplainInfo zei;
56     Res res;
57     ZebraLockHandle server_lock_cmt;
58     ZebraLockHandle server_lock_org;
59     char *server_path_prefix;
60     data1_handle dh;
61     ZebraMaps zebra_maps;
62     ZebraRankClass rank_classes;
63     RecTypes recTypes;
64     Passwd_db passwd_db;
65     Zebra_mutex_cond session_lock;
66     int stop_flag;
67     int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
68 };
69
70 struct recKeys {
71     int buf_used;
72     int buf_max;
73     char *buf;
74     char prevAttrSet;
75     short prevAttrUse;
76     int prevSeqNo;
77 };
78
79 struct sortKey {
80     char *string;
81     int length;
82     int attrSet;
83     int attrUse;
84     struct sortKey *next;
85 };
86
87 struct zebra_session {
88     struct zebra_session *next;
89     struct zebra_service *service;
90
91     struct recKeys keys;
92     struct sortKey *sortKeys;
93
94     char **key_buf;
95     size_t ptr_top;
96     size_t ptr_i;
97     size_t key_buf_used;
98     int key_file_no;
99     char *admin_databaseName;
100
101     int destroyed;
102     ZebraSet sets;
103     int errCode;
104     int hits;
105     char *errString;
106 #if HAVE_SYS_TIMES_H
107     struct tms tms1;
108     struct tms tms2;    
109 #endif
110 };
111
112 struct rank_control {
113     char *name;
114     void *(*create)(ZebraService zh);
115     void (*destroy)(ZebraService zh, void *class_handle);
116     void *(*begin)(ZebraHandle zh, void *class_handle, RSET rset);
117     void (*end)(ZebraHandle zh, void *set_handle);
118     int (*calc)(void *set_handle, int sysno);
119     void (*add)(void *set_handle, int seqno, int term_index);
120 };
121
122 struct term_set_entry {
123     char *term;
124     struct term_set_entry *next;
125 };
126
127 struct term_set_list {
128     struct term_set_entry *first;
129     struct term_set_entry *last;
130 };
131
132 RSET rpn_search (ZebraHandle zh, NMEM mem,
133                  Z_RPNQuery *rpn, int num_bases, char **basenames, 
134                  const char *setname, ZebraSet sset);
135
136
137 void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
138                oid_value attributeset,
139                int num_bases, char **basenames,
140                int *position, int *num_entries, ZebraScanEntry **list,
141                int *is_partial);
142
143 RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
144                  const char *term, int length_term, const char *flags);
145
146 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
147                        const char *db, int set,
148                        int use, const char *term);
149 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
150 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
151 ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode,
152                           Z_RPNQuery *rpn, int num_bases, char **basenames,
153                           const char *setname);
154 RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
155 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
156                        int *statuses);
157
158 ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
159                                int num, int *positions);
160 void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
161
162 void resultSetSort (ZebraHandle zh, NMEM nmem,
163                     int num_input_setnames, const char **input_setnames,
164                     const char *output_setname,
165                     Z_SortKeySpecList *sort_sequence, int *sort_status);
166 void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
167                           ZebraSet sset, RSET rset,
168                           Z_SortKeySpecList *sort_sequence, int *sort_status);
169 void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
170
171 void zebra_sort (ZebraHandle zh, ODR stream,
172                  int num_input_setnames, const char **input_setnames,
173                  const char *output_setname, Z_SortKeySpecList *sort_sequence,
174                  int *sort_status);
175
176 int zebra_server_lock_init (ZebraService zh);
177 int zebra_server_lock_destroy (ZebraService zh);
178 int zebra_server_lock (ZebraService zh, int lockCommit);
179 void zebra_server_unlock (ZebraService zh, int commitPhase);
180 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
181
182 typedef struct attent
183 {
184     int attset_ordinal;
185     data1_local_attribute *local_attributes;
186 } attent;
187
188 void zebraRankInstall (ZebraService zh, struct rank_control *ctrl);
189 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
190 void zebraRankDestroy (ZebraService zh);
191
192 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
193
194 extern struct rank_control *rank1_class;
195
196 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
197                         oid_value input_format, Z_RecordComposition *comp,
198                         oid_value *output_format, char **rec_bufp,
199                         int *rec_lenp, char **basenamep);
200
201 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
202 void zebra_index_merge (ZebraHandle zh);
203
204
205 struct zebra_fetch_control {
206     off_t offset_end;
207     off_t record_offset;
208     off_t record_int_pos;
209     const char *record_int_buf;
210     int record_int_len;
211     int fd;
212 };
213
214 int zebra_record_ext_read (void *fh, char *buf, size_t count);
215 off_t zebra_record_ext_seek (void *fh, off_t offset);
216 off_t zebra_record_ext_tell (void *fh);
217 off_t zebra_record_int_seek (void *fh, off_t offset);
218 off_t zebra_record_int_tell (void *fh);
219 int zebra_record_int_read (void *fh, char *buf, size_t count);
220 void zebra_record_int_end (void *fh, off_t offset);
221
222 YAZ_END_CDECL