1 /* $Id: index.h,v 1.114 2004-08-25 09:23:36 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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
27 #include <idzebra/version.h>
33 #include <sys/times.h>
44 #include <idzebra/api.h>
51 #define ISAM_DEFAULT "b"
55 #define IT_MAX_WORD 256
64 #define IT_KEY_LEVEL_MAX 4
67 zint mem[IT_KEY_LEVEL_MAX];
76 enum dirsKind { dirs_dir, dirs_file };
91 void getFnameTmp (Res res, char *fname, int no);
93 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
94 struct dirs_info *dirs_fopen (Dict dict, const char *path);
95 struct dirs_entry *dirs_read (struct dirs_info *p);
96 struct dirs_entry *dirs_last (struct dirs_info *p);
97 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
98 void dirs_rmdir (struct dirs_info *p, const char *src);
99 void dirs_add (struct dirs_info *p, const char *src, SYSNO sysno, time_t mtime);
100 void dirs_del (struct dirs_info *p, const char *src);
101 void dirs_free (struct dirs_info **pp);
103 struct dir_entry *dir_open (const char *rep, const char *base,
105 void dir_sort (struct dir_entry *e);
106 void dir_free (struct dir_entry **e_p);
108 void repositoryUpdate (ZebraHandle zh, const char *path);
109 void repositoryAdd (ZebraHandle zh, const char *path);
110 void repositoryDelete (ZebraHandle zh, const char *path);
111 void repositoryShow (ZebraHandle zh, const char *path);
113 int key_open (ZebraHandle zh, int mem);
114 int key_close (ZebraHandle zh);
115 int key_compare (const void *p1, const void *p2);
116 void key_init(struct it_key *k);
117 char *key_print_it (const void *p, char *buf);
118 int key_get_seq (const void *p);
119 int key_compare_it (const void *p1, const void *p2);
120 int key_qsort_compare (const void *p1, const void *p2);
121 void key_logdump (int mask, const void *p);
122 void key_logdump_txt (int logmask, const void *p, const char *txt);
123 void inv_prstat (ZebraHandle zh);
124 void inv_compact (BFiles bfs);
125 void key_input (ZebraHandle zh, int nkeys, int cache, Res res);
126 ISAMS_M *key_isams_m (Res res, ISAMS_M *me);
127 ISAMC_M *key_isamc_m (Res res, ISAMC_M *me);
128 int merge_sort (char **buf, int from, int to);
129 int key_SU_code (int ch, char *out);
131 #define FNAME_DICT "dict"
132 #define FNAME_ISAM "isam"
133 #define FNAME_ISAMC "isamc"
134 #define FNAME_ISAMS "isams"
135 #define FNAME_ISAMH "isamh"
136 #define FNAME_ISAMD "isamd"
137 #define FNAME_CONFIG "zebra.cfg"
139 #define GMATCH_DICT "gmatch"
140 #define FMATCH_DICT "fmatch"
142 struct strtab *strtab_mk (void);
143 int strtab_src (struct strtab *t, const char *name, void ***infop);
144 void strtab_del (struct strtab *t,
145 void (*func)(const char *name, void *info, void *data),
147 int index_char_cvt (int c);
148 int index_word_prefix (char *string, int attset_ordinal,
149 int local_attribute, const char *databaseName);
152 void zebraIndexLockMsg (ZebraHandle zh, const char *str);
153 void zebraIndexUnlock (ZebraHandle zh);
154 int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
155 int zebraIndexWait (ZebraHandle zh, int commitPhase);
157 #define FNAME_MAIN_LOCK "zebraidx.LCK"
158 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
159 #define FNAME_ORG_LOCK "zebraorg.LCK"
160 #define FNAME_TOUCH_TIME "zebraidx.time"
162 typedef struct zebra_lock_info *ZebraLockHandle;
163 ZebraLockHandle zebra_lock_create(const char *dir,
164 const char *file, int excl_flag);
165 void zebra_lock_destroy (ZebraLockHandle h);
166 int zebra_lock (ZebraLockHandle h);
167 int zebra_lock_nb (ZebraLockHandle h);
168 int zebra_unlock (ZebraLockHandle h);
169 int zebra_lock_fd (ZebraLockHandle h);
170 void zebra_lock_prefix (Res res, char *dst);
171 char *zebra_mk_fname (const char *dir, const char *name);
173 int zebra_lock_w (ZebraLockHandle h);
174 int zebra_lock_r (ZebraLockHandle h);
176 void zebra_load_atts (data1_handle dh, Res res);
178 int key_SU_decode (int *ch, const unsigned char *out);
179 int key_SU_encode (int ch, char *out);
181 #define ENCODE_BUFLEN 768
183 int sysno; /* previously written values for delta-compress */
186 int prevsys; /* buffer for skipping insert/delete pairs */
189 int keylen; /* tells if we have an unwritten key in buf, and how long*/
193 char buf[ENCODE_BUFLEN];
196 void encode_key_init (struct encode_info *i);
197 char *encode_key_int (int d, char *bp);
198 void encode_key_write (char *k, struct encode_info *i, FILE *outf);
199 void encode_key_flush (struct encode_info *i, FILE *outf);
208 typedef struct zebra_set *ZebraSet;
210 typedef struct zebra_rank_class {
211 struct rank_control *control;
214 struct zebra_rank_class *next;
236 struct zebra_register {
245 int registerState; /* 0 (no commit pages), 1 (use commit pages) */
246 time_t registerChange;
249 ZebraExplainInfo zei;
251 char *server_path_prefix;
253 ZebraMaps zebra_maps;
254 ZebraRankClass rank_classes;
259 int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
263 struct sortKeys sortKeys;
265 struct sortKey *sortKeys;
274 struct zebra_service {
278 struct zebra_session *sessions;
279 struct zebra_register *regs;
280 Zebra_mutex_cond session_lock;
282 const char *path_root;
286 struct zebra_session {
287 struct zebra_session *next;
288 struct zebra_service *service;
289 struct zebra_register *reg;
291 char *xadmin_databaseName;
298 ZebraLockHandle lock_normal;
299 ZebraLockHandle lock_shadow;
317 zint records_inserted;
318 zint records_updated;
319 zint records_deleted;
320 zint records_processed;
321 char *record_encoding;
323 yaz_iconv_t iconv_to_utf8;
324 yaz_iconv_t iconv_from_utf8;
328 const char *m_record_id;
329 const char *m_record_type;
332 int m_explain_database;
334 int m_file_verbose_limit;
337 struct rank_control {
339 void *(*create)(ZebraHandle zh);
340 void (*destroy)(struct zebra_register *reg, void *class_handle);
341 void *(*begin)(struct zebra_register *reg, void *class_handle, RSET rset);
342 /* ### Could add parameters to begin:
343 * char *index; // author, title, etc.
344 * int dbsize; // number of records in database
345 * int rssize; // number of records in result set (estimate?)
347 void (*end)(struct zebra_register *reg, void *set_handle);
348 int (*calc)(void *set_handle, zint sysno);
349 void (*add)(void *set_handle, int seqno, int term_index);
352 struct term_set_entry {
354 struct term_set_entry *next;
357 struct term_set_list {
358 struct term_set_entry *first;
359 struct term_set_entry *last;
362 RSET rpn_search (ZebraHandle zh, NMEM mem,
363 Z_RPNQuery *rpn, int num_bases, char **basenames,
364 const char *setname, ZebraSet sset);
367 void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
368 oid_value attributeset,
369 int num_bases, char **basenames,
370 int *position, int *num_entries, ZebraScanEntry **list,
371 int *is_partial, RSET limit_set, int return_zero);
373 RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
374 const char *term, int length_term, const char *flags,
375 int preserve_position, int term_type);
377 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
378 const char *db, int set,
379 int use, const char *term);
380 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
381 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
382 ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
383 int num_bases, char **basenames,
384 const char *setname);
385 RSET resultSetRef (ZebraHandle zh, const char *resultSetId);
386 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
390 ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
391 int num, int *positions);
392 void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
394 void resultSetSort (ZebraHandle zh, NMEM nmem,
395 int num_input_setnames, const char **input_setnames,
396 const char *output_setname,
397 Z_SortKeySpecList *sort_sequence, int *sort_status);
398 void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
399 ZebraSet sset, RSET rset,
400 Z_SortKeySpecList *sort_sequence, int *sort_status);
401 void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
402 void resultSetInvalidate (ZebraHandle zh);
404 int zebra_server_lock_init (ZebraService zh);
405 int zebra_server_lock_destroy (ZebraService zh);
406 int zebra_server_lock (ZebraService zh, int lockCommit);
407 void zebra_server_unlock (ZebraService zh, int commitPhase);
408 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
410 typedef struct attent
413 data1_local_attribute *local_attributes;
416 void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl);
417 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
418 void zebraRankDestroy (struct zebra_register *reg);
420 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att,
423 extern struct rank_control *rank1_class;
424 extern struct rank_control *rankzv_class;
425 extern struct rank_control *rankliv_class;
427 int zebra_record_fetch (ZebraHandle zh, SYSNO sysno, int score, ODR stream,
428 oid_value input_format, Z_RecordComposition *comp,
429 oid_value *output_format, char **rec_bufp,
430 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 int 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 extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
475 int cmd, struct recKeys *reckeys);
476 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
477 int cmd, struct sortKeys *skp);
478 void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
479 void extract_token_add (RecWord *p);
480 int explain_extract (void *handle, Record rec, data1_node *n);
482 int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
485 int zebra_begin_read (ZebraHandle zh);
486 int zebra_end_read (ZebraHandle zh);
488 int zebra_file_stat (const char *file_name, struct stat *buf,
491 void zebra_livcode_transform(ZebraHandle zh, Z_RPNQuery *query);
493 void *iscz1_start ();
494 void iscz1_reset (void *vp);
495 void iscz1_stop (void *p);
496 void iscz1_decode (void *vp, char **dst, const char **src);
497 void iscz1_encode (void *vp, char **dst, const char **src);