1 /* $Id: index.h,v 1.145 2005-06-23 06:45:46 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
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
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
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
28 #include <idzebra/version.h>
29 #include <idzebra/util.h>
33 #include <sys/times.h>
37 #include <idzebra/dict.h>
38 #include <idzebra/isams.h>
39 #include <idzebra/isamc.h>
40 #include <idzebra/isamb.h>
42 #include <idzebra/recgrs.h>
44 #include <idzebra/api.h>
51 #define ISAM_DEFAULT "b"
55 #define IT_MAX_WORD 256
57 #define IT_KEY_LEVEL_MAX 4
60 zint mem[IT_KEY_LEVEL_MAX];
63 enum dirsKind { dirs_dir, dirs_file };
78 void getFnameTmp (Res res, char *fname, int no);
80 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
81 struct dirs_info *dirs_fopen (Dict dict, const char *path, int rw);
82 struct dirs_entry *dirs_read (struct dirs_info *p);
83 struct dirs_entry *dirs_last (struct dirs_info *p);
84 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
85 void dirs_rmdir (struct dirs_info *p, const char *src);
86 void dirs_add (struct dirs_info *p, const char *src, SYSNO sysno, time_t mtime);
87 void dirs_del (struct dirs_info *p, const char *src);
88 void dirs_free (struct dirs_info **pp);
90 struct dir_entry *dir_open (const char *rep, const char *base,
92 void dir_sort (struct dir_entry *e);
93 void dir_free (struct dir_entry **e_p);
95 void repositoryUpdate (ZebraHandle zh, const char *path);
96 void repositoryAdd (ZebraHandle zh, const char *path);
97 void repositoryDelete (ZebraHandle zh, const char *path);
98 void repositoryShow (ZebraHandle zh, const char *path);
100 int key_open (ZebraHandle zh, int mem);
101 int key_close (ZebraHandle zh);
102 int key_compare (const void *p1, const void *p2);
103 void key_init(struct it_key *k);
104 char *key_print_it (const void *p, char *buf);
105 zint key_get_seq (const void *p);
106 int key_compare_it (const void *p1, const void *p2);
107 int key_qsort_compare (const void *p1, const void *p2);
108 void key_logdump (int mask, const void *p);
109 void key_logdump_txt (int logmask, const void *p, const char *txt);
110 void inv_prstat (ZebraHandle zh);
111 void inv_compact (BFiles bfs);
112 void key_input (ZebraHandle zh, int nkeys, int cache, Res res);
113 ISAMS_M *key_isams_m (Res res, ISAMS_M *me);
114 ISAMC_M *key_isamc_m (Res res, ISAMC_M *me);
115 int merge_sort (char **buf, int from, int to);
116 int key_SU_code (int ch, char *out);
118 #define FNAME_DICT "dict"
119 #define FNAME_ISAM "isam"
120 #define FNAME_ISAMC "isamc"
121 #define FNAME_ISAMS "isams"
122 #define FNAME_ISAMH "isamh"
123 #define FNAME_ISAMD "isamd"
124 #define FNAME_CONFIG "zebra.cfg"
126 #define GMATCH_DICT "gmatch"
127 #define FMATCH_DICT "fmatch"
129 struct strtab *strtab_mk (void);
130 int strtab_src (struct strtab *t, const char *name, void ***infop);
131 void strtab_del (struct strtab *t,
132 void (*func)(const char *name, void *info, void *data),
134 int index_char_cvt (int c);
135 int index_word_prefix (char *string, int attset_ordinal,
136 int local_attribute, const char *databaseName);
139 void zebraIndexLockMsg (ZebraHandle zh, const char *str);
140 void zebraIndexUnlock (ZebraHandle zh);
141 int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
142 int zebraIndexWait (ZebraHandle zh, int commitPhase);
144 #define FNAME_MAIN_LOCK "zebraidx.LCK"
145 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
146 #define FNAME_ORG_LOCK "zebraorg.LCK"
147 #define FNAME_TOUCH_TIME "zebraidx.time"
149 typedef struct zebra_lock_info *ZebraLockHandle;
150 ZebraLockHandle zebra_lock_create(const char *dir,
151 const char *file, int excl_flag);
152 void zebra_lock_destroy (ZebraLockHandle h);
153 int zebra_lock (ZebraLockHandle h);
154 int zebra_lock_nb (ZebraLockHandle h);
155 int zebra_unlock (ZebraLockHandle h);
156 int zebra_lock_fd (ZebraLockHandle h);
157 void zebra_lock_prefix (Res res, char *dst);
158 char *zebra_mk_fname (const char *dir, const char *name);
160 int zebra_lock_w (ZebraLockHandle h);
161 int zebra_lock_r (ZebraLockHandle h);
163 void zebra_load_atts (data1_handle dh, Res res);
165 int key_SU_decode (int *ch, const unsigned char *out);
166 int key_SU_encode (int ch, char *out);
168 #define ENCODE_BUFLEN 768
170 int sysno; /* previously written values for delta-compress */
173 int prevsys; /* buffer for skipping insert/delete pairs */
176 int keylen; /* tells if we have an unwritten key in buf, and how long*/
178 char buf[ENCODE_BUFLEN];
181 void encode_key_init (struct encode_info *i);
182 char *encode_key_int (int d, char *bp);
183 void encode_key_write (char *k, struct encode_info *i, FILE *outf);
184 void encode_key_flush (struct encode_info *i, FILE *outf);
186 typedef struct zebra_set *ZebraSet;
188 typedef struct zebra_rank_class {
189 struct rank_control *control;
192 struct zebra_rank_class *next;
212 struct zebra_register {
221 int registerState; /* 0 (no commit pages), 1 (use commit pages) */
222 time_t registerChange;
225 ZebraExplainInfo zei;
227 char *server_path_prefix;
229 ZebraMaps zebra_maps;
230 ZebraRankClass rank_classes;
235 int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
239 struct recKeys sortKeys;
241 struct sortKeys sortKeys;
250 struct zebra_service {
254 struct zebra_session *sessions;
255 struct zebra_register *regs;
256 Zebra_mutex_cond session_lock;
258 const char *path_root;
259 RecTypeClass record_classes;
264 struct zebra_session {
265 struct zebra_session *next;
266 struct zebra_service *service;
267 struct zebra_register *reg;
269 char *xadmin_databaseName;
277 ZebraLockHandle lock_normal;
278 ZebraLockHandle lock_shadow;
296 zint records_inserted;
297 zint records_updated;
298 zint records_deleted;
299 zint records_processed;
300 char *record_encoding;
302 yaz_iconv_t iconv_to_utf8;
303 yaz_iconv_t iconv_from_utf8;
307 const char *m_record_id;
308 const char *m_record_type;
311 int m_explain_database;
313 int m_file_verbose_limit;
315 void *store_data_buf;
316 size_t store_data_size;
319 struct zebra_limit *m_limit;
322 struct rank_control {
324 void *(*create)(ZebraHandle zh);
325 void (*destroy)(struct zebra_register *reg, void *class_handle);
326 void *(*begin)(struct zebra_register *reg,
327 void *class_handle, RSET rset, NMEM nmem,
328 TERMID *terms, int numterms);
329 /* ### Could add parameters to begin:
330 * char *index; // author, title, etc.
331 * int dbsize; // number of records in database
332 * int rssize; // number of records in result set (estimate?)
334 void (*end)(struct zebra_register *reg, void *set_handle);
335 int (*calc)(void *set_handle, zint sysno);
336 void (*add)(void *set_handle, int seqno, TERMID term);
339 struct term_set_entry {
341 struct term_set_entry *next;
344 struct term_set_list {
345 struct term_set_entry *first;
346 struct term_set_entry *last;
350 void zebra_limit_destroy(struct zebra_limit *zl);
351 struct zebra_limit *zebra_limit_create(int exclude_flag, zint *ids);
352 void zebra_limit_for_rset(struct zebra_limit *zl,
353 int (**filter_func)(const void *buf, void *data),
354 void (**filter_destroy)(void *data),
357 struct rset_key_control *zebra_key_control_create(ZebraHandle zh);
359 ZEBRA_RES rpn_search_top(ZebraHandle zh, Z_RPNStructure *zs,
360 oid_value attributeSet,
361 NMEM stream, NMEM rset_nmem,
362 Z_SortKeySpecList *sort_sequence,
363 int num_bases, char **basenames,
366 ZEBRA_RES rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
367 oid_value attributeset,
368 int num_bases, char **basenames,
369 int *position, int *num_entries, ZebraScanEntry **list,
370 int *is_partial, RSET limit_set, int return_zero);
372 RSET rset_trunc(ZebraHandle zh, ISAM_P *isam_p, int no,
373 const char *term, int length_term, const char *flags,
374 int preserve_position, int term_type, NMEM rset_nmem,
375 struct rset_key_control *kctrl, int scope,
376 struct ord_list *ol, int reg_type,
377 zint hits_limit, const char *term_ref_id);
379 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
380 const char *db, int set,
381 int use, const char *term);
382 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
383 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
384 ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
385 int num_bases, char **basenames,
386 const char *setname);
387 RSET resultSetRef (ZebraHandle zh, const char *resultSetId);
388 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
390 ZEBRA_RES resultSetSort (ZebraHandle zh, NMEM nmem,
391 int num_input_setnames, const char **input_setnames,
392 const char *output_setname,
393 Z_SortKeySpecList *sort_sequence, int *sort_status);
394 ZEBRA_RES resultSetSortSingle (ZebraHandle zh, NMEM nmem,
395 ZebraSet sset, RSET rset,
396 Z_SortKeySpecList *sort_sequence,
398 ZEBRA_RES resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset,
400 void resultSetInvalidate (ZebraHandle zh);
402 int zebra_server_lock_init (ZebraService zh);
403 int zebra_server_lock_destroy (ZebraService zh);
404 int zebra_server_lock (ZebraService zh, int lockCommit);
405 void zebra_server_unlock (ZebraService zh, int commitPhase);
406 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
408 typedef struct attent
411 data1_local_attribute *local_attributes;
414 void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl);
415 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
416 void zebraRankDestroy (struct zebra_register *reg);
418 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att,
421 extern struct rank_control *rank1_class;
422 extern struct rank_control *rankzv_class;
423 extern struct rank_control *rankliv_class;
425 int zebra_record_fetch (ZebraHandle zh, SYSNO sysno, int score,
426 zebra_snippets *hit_snippet, ODR stream,
427 oid_value input_format, Z_RecordComposition *comp,
428 oid_value *output_format, char **rec_bufp,
429 int *rec_lenp, char **basenamep,
432 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
434 void zebra_index_merge (ZebraHandle zh);
436 ZEBRA_RES buffer_extract_record (ZebraHandle zh,
437 const char *buf, size_t buf_size,
440 const char *recordType,
442 const char *match_criteria,
448 int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
449 const char *buf, size_t buf_size,
450 const char *databaseName, int delete_flag,
451 int test_mode, int *sysno,
452 int store_keys, int store_data,
453 const char *match_criteria);
455 void extract_flushWriteKeys (ZebraHandle zh, int final);
457 struct zebra_fetch_control {
460 off_t record_int_pos;
461 const char *record_int_buf;
466 int zebra_record_ext_read (void *fh, char *buf, size_t count);
467 off_t zebra_record_ext_seek (void *fh, off_t offset);
468 off_t zebra_record_ext_tell (void *fh);
469 off_t zebra_record_int_seek (void *fh, off_t offset);
470 off_t zebra_record_int_tell (void *fh);
471 int zebra_record_int_read (void *fh, char *buf, size_t count);
472 void zebra_record_int_end (void *fh, off_t offset);
474 void print_rec_keys(ZebraHandle zh, struct recKeys *reckeys);
475 ZEBRA_RES zebra_snippets_rec_keys(ZebraHandle zh, struct recKeys *reckeys,
476 zebra_snippets *snippets);
477 ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
478 zint sysno, zebra_snippets *snippets);
480 void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
481 int cmd, struct recKeys *reckeys);
483 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
484 int cmd, struct recKeys *skp);
486 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
487 int cmd, struct sortKeys *skp);
489 void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
490 void extract_token_add (RecWord *p);
491 int explain_extract (void *handle, Record rec, data1_node *n);
493 int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
496 ZEBRA_RES zebra_begin_read (ZebraHandle zh);
497 ZEBRA_RES zebra_end_read (ZebraHandle zh);
499 int zebra_file_stat (const char *file_name, struct stat *buf,
502 void zebra_livcode_transform(ZebraHandle zh, Z_RPNQuery *query);
504 void *iscz1_start ();
505 void iscz1_reset (void *vp);
506 void iscz1_stop (void *p);
507 void iscz1_decode (void *vp, char **dst, const char **src);
508 void iscz1_encode (void *vp, char **dst, const char **src);
510 Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw,
511 int compact_flag, Res res);
513 void zebra_setError(ZebraHandle zh, int code, const char *addinfo);
514 void zebra_setError_zint(ZebraHandle zh, int code, zint i);
516 void zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream, int reg_type,
517 char **dst, const char *src);
519 ZEBRA_RES zebra_get_hit_vector(ZebraHandle zh, const char *setname, zint sysno);