Disable X-Path indexing for explain records (in the case where
[idzebra-moved-to-github.git] / index / index.h
1 /* $Id: index.h,v 1.167 2006-06-13 12:02:08 adam Exp $
2    Copyright (C) 1995-2005
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 #ifndef INDEX_H
24 #define INDEX_H
25
26 #include <time.h>
27 #include <stdlib.h>
28 #include <idzebra/version.h>
29 #include <idzebra/util.h>
30 #include <idzebra/flock.h>
31 #include <sortidx.h>
32
33 #if HAVE_SYS_TIMES_H
34 #include <sys/times.h>
35 #endif
36 #include <sys/stat.h>
37
38 #include <idzebra/dict.h>
39 #include <idzebra/isams.h>
40 #include <idzebra/isamc.h>
41 #include <idzebra/isamb.h>
42 #include <d1_absyn.h>
43 #include <idzebra/recgrs.h>
44 #include "recindex.h"
45 #include <idzebra/api.h>
46 #include "zinfo.h"
47 #include <passwddb.h>
48 #include <rset.h>
49
50 YAZ_BEGIN_CDECL
51
52 #define ISAM_DEFAULT "b"
53
54 #define SU_SCHEME 1
55
56 #define IT_MAX_WORD 256
57
58 #define IT_KEY_LEVEL_MAX 5
59 struct it_key {
60     int  len;
61     zint mem[IT_KEY_LEVEL_MAX];
62 };
63
64 enum dirsKind { dirs_dir, dirs_file };
65
66 struct dir_entry {
67     enum dirsKind kind;
68     char *name;
69     time_t mtime;
70 };
71
72 struct dirs_entry {
73     enum dirsKind kind;
74     char path[256];
75     SYSNO sysno;
76     time_t mtime;
77 };
78
79 void getFnameTmp (Res res, char *fname, int no);
80         
81 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
82 struct dirs_info *dirs_fopen (Dict dict, const char *path, int rw);
83 struct dirs_entry *dirs_read (struct dirs_info *p);
84 struct dirs_entry *dirs_last (struct dirs_info *p);
85 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
86 void dirs_rmdir (struct dirs_info *p, const char *src);
87 void dirs_add (struct dirs_info *p, const char *src, SYSNO sysno, time_t mtime);
88 void dirs_del (struct dirs_info *p, const char *src);
89 void dirs_free (struct dirs_info **pp);
90
91 struct dir_entry *dir_open (const char *rep, const char *base,
92                             int follow_links);
93 void dir_sort (struct dir_entry *e);
94 void dir_free (struct dir_entry **e_p);
95
96 void repositoryUpdate (ZebraHandle zh, const char *path);
97 void repositoryAdd (ZebraHandle zh, const char *path);
98 void repositoryDelete (ZebraHandle zh, const char *path);
99 void repositoryShow (ZebraHandle zh, const char *path);
100
101 int key_open (ZebraHandle zh, int mem);
102 int key_close (ZebraHandle zh);
103 int key_compare (const void *p1, const void *p2);
104 void key_init(struct it_key *k);
105 char *key_print_it (const void *p, char *buf);
106 zint key_get_seq (const void *p);
107 int key_compare_it (const void *p1, const void *p2);
108 int key_qsort_compare (const void *p1, const void *p2);
109 void key_logdump (int mask, const void *p);
110 void key_logdump_txt (int logmask, const void *p, const char *txt);
111 void inv_prstat (ZebraHandle zh);
112 void inv_compact (BFiles bfs);
113 void key_input (ZebraHandle zh, int nkeys, int cache, Res res);
114 ISAMS_M *key_isams_m (Res res, ISAMS_M *me);
115 ISAMC_M *key_isamc_m (Res res, ISAMC_M *me);
116 int merge_sort (char **buf, int from, int to);
117 int key_SU_code (int ch, char *out);
118
119 #define FNAME_DICT "dict"
120 #define FNAME_ISAM "isam"
121 #define FNAME_ISAMC "isamc"
122 #define FNAME_ISAMS "isams"
123 #define FNAME_ISAMH "isamh"
124 #define FNAME_ISAMD "isamd"
125 #define FNAME_CONFIG "zebra.cfg"
126
127 #define GMATCH_DICT "gmatch"
128 #define FMATCH_DICT "fmatch"
129
130 struct strtab *strtab_mk (void);
131 int strtab_src (struct strtab *t, const char *name, void ***infop);
132 void strtab_del (struct strtab *t,
133                  void (*func)(const char *name, void *info, void *data),
134                  void *data);
135
136 void zebraIndexLockMsg (ZebraHandle zh, const char *str);
137 void zebraIndexUnlock (ZebraHandle zh);
138 int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
139 int zebraIndexWait (ZebraHandle zh, int commitPhase);
140
141 void zebra_lock_prefix (Res res, char *dst);
142
143 #define FNAME_MAIN_LOCK   "zebraidx.LCK"
144 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
145 #define FNAME_ORG_LOCK    "zebraorg.LCK"
146 #define FNAME_TOUCH_TIME  "zebraidx.time"
147
148 int key_SU_decode (int *ch, const unsigned char *out);
149 int key_SU_encode (int ch, char *out);
150
151 typedef struct zebra_set *ZebraSet;
152
153 typedef struct zebra_rank_class {
154     struct rank_control *control;
155     int init_flag;
156     void *class_handle;
157     struct zebra_rank_class *next;
158 } *ZebraRankClass;
159
160 #include "reckeys.h"
161
162 struct zebra_register {
163     char *name;
164     
165     ISAMS isams;
166     ISAMC isamc;
167     ISAMB isamb;
168     Dict dict;
169     Dict matchDict;
170     SortIdx sortIdx;
171     int registerState; /* 0 (no commit pages), 1 (use commit pages) */
172     time_t registerChange;
173     BFiles bfs;
174     Records records;
175     ZebraExplainInfo zei;
176
177     char *server_path_prefix;
178     data1_handle dh;
179     ZebraMaps zebra_maps;
180     ZebraRankClass rank_classes;
181     RecTypes recTypes;
182     int seqno;
183     int last_val;
184     int stop_flag;
185
186     zebra_rec_keys_t keys;
187     zebra_rec_keys_t sortKeys;
188     char **key_buf;
189     size_t ptr_top;
190     size_t ptr_i;
191     size_t key_buf_used;
192     int key_file_no;
193 };
194
195 struct zebra_service {
196     int stop_flag;
197     Res global_res;
198     struct zebra_session *sessions;
199     struct zebra_register *regs;
200     Zebra_mutex_cond session_lock;
201     Passwd_db passwd_db;
202     Res dbaccess;
203     const char *path_root;
204     RecTypeClass record_classes;
205     NMEM nmem;
206 };
207
208
209 struct zebra_session {
210     struct zebra_session *next;
211     struct zebra_service *service;
212     struct zebra_register *reg;
213
214     char *xadmin_databaseName;
215
216     char **basenames;
217     int num_basenames;
218     zint approx_limit;
219     char *reg_name;
220     char *path_reg;
221
222     ZebraLockHandle lock_normal;
223     ZebraLockHandle lock_shadow;
224
225     int trans_no;
226     int trans_w_no;
227
228     int destroyed;
229     ZebraSet sets;
230     Res res;
231     Res session_res;
232     char *user_perm;
233     char *dbaccesslist;
234     int errCode;
235     zint hits;
236     char *errString;
237 #if HAVE_SYS_TIMES_H
238     struct tms tms1;
239     struct tms tms2;    
240 #endif
241     int  shadow_enable;
242
243     int m_staticrank;
244
245     zint records_inserted;
246     zint records_updated;
247     zint records_deleted;
248     zint records_processed;
249     char *record_encoding;
250
251     yaz_iconv_t iconv_to_utf8;
252     yaz_iconv_t iconv_from_utf8;
253
254     int m_follow_links;
255     const char *m_group;
256     const char *m_record_id;
257     const char *m_record_type;
258     int m_store_data;
259     int m_store_keys;
260     int m_explain_database;
261     int m_flag_rw;
262     int m_file_verbose_limit;
263
264     void *store_data_buf;
265     size_t store_data_size;
266     NMEM nmem_error;
267
268     struct zebra_limit *m_limit;
269 };
270
271
272 struct term_set_entry {
273     char *term;
274     struct term_set_entry *next;
275 };
276
277 struct term_set_list {
278     struct term_set_entry *first;
279     struct term_set_entry *last;
280 };
281
282
283 void zebra_limit_destroy(struct zebra_limit *zl);
284 struct zebra_limit *zebra_limit_create(int exclude_flag, zint *ids);
285 void zebra_limit_for_rset(struct zebra_limit *zl,
286                           int (**filter_func)(const void *buf, void *data),
287                           void (**filter_destroy)(void *data),
288                           void **filter_data);
289
290 struct rset_key_control *zebra_key_control_create(ZebraHandle zh);
291
292 ZEBRA_RES rpn_search_top(ZebraHandle zh, Z_RPNStructure *zs,
293                          oid_value attributeSet, 
294                          NMEM stream, NMEM rset_nmem,
295                          Z_SortKeySpecList *sort_sequence,
296                          int num_bases, char **basenames,
297                          RSET *result_set);
298
299 ZEBRA_RES rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
300                     oid_value attributeset,
301                     int num_bases, char **basenames,
302                     int *position, int *num_entries, ZebraScanEntry **list,
303                     int *is_partial, RSET limit_set, int return_zero);
304
305 RSET rset_trunc(ZebraHandle zh, ISAM_P *isam_p, int no,
306                 const char *term, int length_term, const char *flags,
307                 int preserve_position, int term_type, NMEM rset_nmem,
308                 struct rset_key_control *kctrl, int scope,
309                 struct ord_list *ol, int reg_type,
310                 zint hits_limit, const char *term_ref_id);
311
312 void resultSetAddTerm(ZebraHandle zh, ZebraSet s, int reg_type,
313                       const char *db, const char *index_name,
314                       const char *term);
315 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
316 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
317 ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
318                      int num_bases, char **basenames,
319                      const char *setname);
320 RSET resultSetRef (ZebraHandle zh, const char *resultSetId);
321 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
322                        int *statuses);
323 ZEBRA_RES resultSetSort (ZebraHandle zh, NMEM nmem,
324                          int num_input_setnames, const char **input_setnames,
325                          const char *output_setname,
326                          Z_SortKeySpecList *sort_sequence, int *sort_status);
327 ZEBRA_RES resultSetSortSingle (ZebraHandle zh, NMEM nmem,
328                                ZebraSet sset, RSET rset,
329                                Z_SortKeySpecList *sort_sequence,
330                                int *sort_status);
331 ZEBRA_RES resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset,
332                          NMEM nmem);
333 void resultSetInvalidate (ZebraHandle zh);
334
335 int zebra_server_lock_init (ZebraService zh);
336 int zebra_server_lock_destroy (ZebraService zh);
337 int zebra_server_lock (ZebraService zh, int lockCommit);
338 void zebra_server_unlock (ZebraService zh, int commitPhase);
339 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
340
341 int zebra_record_fetch (ZebraHandle zh, SYSNO sysno, int score, 
342                         zebra_snippets *hit_snippet, ODR stream,
343                         oid_value input_format, Z_RecordComposition *comp,
344                         oid_value *output_format, char **rec_bufp,
345                         int *rec_lenp, char **basenamep,
346                         char **addinfo);
347
348 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
349
350 void zebra_index_merge (ZebraHandle zh);
351
352 ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh, 
353                                       const char *buf, size_t buf_size,
354                                       int delete_flag,
355                                       int test_mode, 
356                                       const char *recordType,
357                                       SYSNO *sysno,
358                                       const char *match_criteria,
359                                       const char *fname,
360                                       int force_update,
361                                       int allow_update);
362
363 #if 0
364 int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
365                         const char *buf, size_t buf_size,
366                         const char *databaseName, int delete_flag,
367                         int test_mode, int *sysno,
368                         int store_keys, int store_data,
369                         const char *match_criteria);
370 #endif
371 void extract_flushWriteKeys (ZebraHandle zh, int final);
372
373 struct zebra_fetch_control {
374     off_t offset_end;
375     off_t record_offset;
376     off_t record_int_pos;
377     const char *record_int_buf;
378     int record_int_len;
379     int fd;
380 };
381
382 int zebra_record_ext_read (void *fh, char *buf, size_t count);
383 off_t zebra_record_ext_seek (void *fh, off_t offset);
384 off_t zebra_record_ext_tell (void *fh);
385 off_t zebra_record_int_seek (void *fh, off_t offset);
386 off_t zebra_record_int_tell (void *fh);
387 int zebra_record_int_read (void *fh, char *buf, size_t count);
388 void zebra_record_int_end (void *fh, off_t offset);
389
390 void print_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys);
391
392 ZEBRA_RES zebra_snippets_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys,
393                                   zebra_snippets *snippets);
394 ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
395                                     zint sysno, zebra_snippets *snippets);
396
397 ZEBRA_RES zebra_extract_explain(void *handle, Record rec, data1_node *n);
398
399 ZEBRA_RES zebra_extract_file(ZebraHandle zh, SYSNO *sysno, const char *fname,
400                              int deleteFlag);
401
402 ZEBRA_RES zebra_begin_read (ZebraHandle zh);
403 ZEBRA_RES zebra_end_read (ZebraHandle zh);
404
405 int zebra_file_stat (const char *file_name, struct stat *buf,
406                      int follow_links);
407
408 void zebra_livcode_transform(ZebraHandle zh, Z_RPNQuery *query);
409
410 void *iscz1_start ();
411 void iscz1_reset (void *vp);
412 void iscz1_stop (void *p);
413 void iscz1_decode (void *vp, char **dst, const char **src);
414 void iscz1_encode (void *vp, char **dst, const char **src);
415
416 Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw,
417                     int compact_flag, Res res);
418
419 void zebra_setError(ZebraHandle zh, int code, const char *addinfo);
420 void zebra_setError_zint(ZebraHandle zh, int code, zint i);
421
422 void zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream, int reg_type,
423                               char **dst, const char *src);
424
425 ZEBRA_RES zebra_get_hit_vector(ZebraHandle zh, const char *setname, zint sysno);
426
427 void zebra_term_untrans(ZebraHandle zh, int reg_type,
428                         char *dst, const char *src);
429
430 ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh,
431                             Z_AttributesPlusTerm *zapt,
432                             int index_type,
433                             const char *xpath_use,
434                             oid_value curAttributeSet,
435                             int *ord);
436
437 ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh,
438                                   Z_AttributeList *attr_list,
439                                   int index_type,
440                                   oid_value curAttributeSet,
441                                   int *ord);
442
443 ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh,
444                              Z_SortAttributes *sortAttributes,
445                              int *ord,
446                              int *numerical);
447
448 ZEBRA_RES zebra_update_file_match(ZebraHandle zh, const char *path);
449 ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path);
450 ZEBRA_RES zebra_delete_from_path(ZebraHandle zh, const char *path);
451
452 YAZ_END_CDECL
453
454 #endif
455 /*
456  * Local variables:
457  * c-basic-offset: 4
458  * indent-tabs-mode: nil
459  * End:
460  * vim: shiftwidth=4 tabstop=8 expandtab
461  */
462