2 * Copyright (C) 1995-2002, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
5 * $Id: index.h,v 1.84 2002-07-25 13:06:43 adam Exp $
18 #include <sys/times.h>
31 #define ISAM_DEFAULT "c"
32 #include <yaz/data1.h>
44 #define IT_MAX_WORD 256
45 #define IT_KEY_HAVE_SEQNO 1
46 #define IT_KEY_HAVE_FIELD 0
55 enum dirsKind { dirs_dir, dirs_file };
70 void getFnameTmp (Res res, char *fname, int no);
72 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
73 struct dirs_info *dirs_fopen (Dict dict, const char *path);
74 struct dirs_entry *dirs_read (struct dirs_info *p);
75 struct dirs_entry *dirs_last (struct dirs_info *p);
76 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
77 void dirs_rmdir (struct dirs_info *p, const char *src);
78 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime);
79 void dirs_del (struct dirs_info *p, const char *src);
80 void dirs_free (struct dirs_info **pp);
82 struct dir_entry *dir_open (const char *rep, const char *base);
83 void dir_sort (struct dir_entry *e);
84 void dir_free (struct dir_entry **e_p);
86 void repositoryUpdate (ZebraHandle zh);
87 void repositoryAdd (ZebraHandle zh);
88 void repositoryDelete (ZebraHandle zh);
89 void repositoryShow (ZebraHandle zh);
91 int key_open (ZebraHandle zh, int mem);
92 int key_close (ZebraHandle zh);
93 int key_compare (const void *p1, const void *p2);
94 char *key_print_it (const void *p, char *buf);
95 int key_get_pos (const void *p);
96 int key_compare_it (const void *p1, const void *p2);
97 int key_qsort_compare (const void *p1, const void *p2);
98 void key_logdump (int mask, const void *p);
99 void inv_prstat (ZebraHandle zh);
100 void inv_compact (BFiles bfs);
101 void key_input (ZebraHandle zh, int nkeys, int cache, Res res);
102 ISAMS_M key_isams_m (Res res, ISAMS_M me);
103 ISAMC_M key_isamc_m (Res res, ISAMC_M me);
104 ISAMD_M key_isamd_m (Res res, ISAMD_M me);
105 int merge_sort (char **buf, int from, int to);
106 int key_SU_code (int ch, char *out);
108 #define FNAME_DICT "dict"
109 #define FNAME_ISAM "isam"
110 #define FNAME_ISAMC "isamc"
111 #define FNAME_ISAMS "isams"
112 #define FNAME_ISAMH "isamh"
113 #define FNAME_ISAMD "isamd"
114 #define FNAME_CONFIG "zebra.cfg"
116 #define GMATCH_DICT "gmatch"
117 #define FMATCH_DICT "fmatch"
119 struct strtab *strtab_mk (void);
120 int strtab_src (struct strtab *t, const char *name, void ***infop);
121 void strtab_del (struct strtab *t,
122 void (*func)(const char *name, void *info, void *data),
124 int index_char_cvt (int c);
125 int index_word_prefix (char *string, int attset_ordinal,
126 int local_attribute, const char *databaseName);
129 void zebraIndexLockMsg (ZebraHandle zh, const char *str);
130 void zebraIndexUnlock (ZebraHandle zh);
131 int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
132 int zebraIndexWait (ZebraHandle zh, int commitPhase);
134 #define FNAME_MAIN_LOCK "zebraidx.LCK"
135 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
136 #define FNAME_ORG_LOCK "zebraorg.LCK"
137 #define FNAME_TOUCH_TIME "zebraidx.time"
139 typedef struct zebra_lock_info *ZebraLockHandle;
140 ZebraLockHandle zebra_lock_create(const char *dir,
141 const char *file, int excl_flag);
142 void zebra_lock_destroy (ZebraLockHandle h);
143 int zebra_lock (ZebraLockHandle h);
144 int zebra_lock_nb (ZebraLockHandle h);
145 int zebra_unlock (ZebraLockHandle h);
146 int zebra_lock_fd (ZebraLockHandle h);
147 void zebra_lock_prefix (Res res, char *dst);
148 char *zebra_mk_fname (const char *dir, const char *name);
150 int zebra_lock_w (ZebraLockHandle h);
151 int zebra_lock_r (ZebraLockHandle h);
153 void zebra_load_atts (data1_handle dh, Res res);
155 int key_SU_decode (int *ch, const unsigned char *out);
156 int key_SU_encode (int ch, char *out);
158 // extern Res common_resource;
167 void encode_key_init (struct encode_info *i);
168 char *encode_key_int (int d, char *bp);
169 void encode_key_write (char *k, struct encode_info *i, FILE *outf);
178 typedef struct zebra_set *ZebraSet;
180 typedef struct zebra_rank_class {
181 struct rank_control *control;
184 struct zebra_rank_class *next;
201 struct sortKey *next;
204 struct zebra_register {
215 int registerState; /* 0 (no commit pages), 1 (use commit pages) */
216 time_t registerChange;
219 ZebraExplainInfo zei;
221 char *server_path_prefix;
223 ZebraMaps zebra_maps;
224 ZebraRankClass rank_classes;
229 int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
234 struct sortKey *sortKeys;
243 struct zebra_service {
247 struct zebra_session *sessions;
248 struct zebra_register *regs;
249 Zebra_mutex_cond session_lock;
255 struct zebra_session {
256 struct zebra_session *next;
257 struct zebra_service *service;
258 struct zebra_register *reg;
260 char *admin_databaseName;
267 ZebraLockHandle lock_normal;
268 ZebraLockHandle lock_shadow;
281 struct recordGroup rGroup;
284 int records_inserted;
287 int records_processed;
288 char *record_encoding;
290 iconv_t iconv_to_utf8;
291 iconv_t iconv_from_utf8;
295 struct rank_control {
297 void *(*create)(struct zebra_register *reg);
298 void (*destroy)(struct zebra_register *reg, void *class_handle);
299 void *(*begin)(struct zebra_register *reg, void *class_handle, RSET rset);
300 void (*end)(struct zebra_register *reg, void *set_handle);
301 int (*calc)(void *set_handle, int sysno);
302 void (*add)(void *set_handle, int seqno, int term_index);
305 struct term_set_entry {
307 struct term_set_entry *next;
310 struct term_set_list {
311 struct term_set_entry *first;
312 struct term_set_entry *last;
315 RSET rpn_search (ZebraHandle zh, NMEM mem,
316 Z_RPNQuery *rpn, int num_bases, char **basenames,
317 const char *setname, ZebraSet sset);
320 void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
321 oid_value attributeset,
322 int num_bases, char **basenames,
323 int *position, int *num_entries, ZebraScanEntry **list,
326 RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
327 const char *term, int length_term, const char *flags,
328 int preserve_position, int term_type);
330 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
331 const char *db, int set,
332 int use, const char *term);
333 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
334 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
335 ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode,
336 Z_RPNQuery *rpn, int num_bases,
337 char **basenames, const char *setname);
338 RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
339 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
343 ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
344 int num, int *positions);
345 void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
347 void resultSetSort (ZebraHandle zh, NMEM nmem,
348 int num_input_setnames, const char **input_setnames,
349 const char *output_setname,
350 Z_SortKeySpecList *sort_sequence, int *sort_status);
351 void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
352 ZebraSet sset, RSET rset,
353 Z_SortKeySpecList *sort_sequence, int *sort_status);
354 void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
355 void resultSetInvalidate (ZebraHandle zh);
357 int zebra_server_lock_init (ZebraService zh);
358 int zebra_server_lock_destroy (ZebraService zh);
359 int zebra_server_lock (ZebraService zh, int lockCommit);
360 void zebra_server_unlock (ZebraService zh, int commitPhase);
361 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
363 typedef struct attent
366 data1_local_attribute *local_attributes;
369 void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl);
370 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
371 void zebraRankDestroy (struct zebra_register *reg);
373 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
375 extern struct rank_control *rank1_class;
377 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
378 oid_value input_format, Z_RecordComposition *comp,
379 oid_value *output_format, char **rec_bufp,
380 int *rec_lenp, char **basenamep);
382 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
383 void zebra_index_merge (ZebraHandle zh);
386 int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
387 const char *buf, size_t buf_size,
388 const char *databaseName, int delete_flag,
389 int test_mode, int *sysno,
390 int store_keys, int store_data,
391 const char *match_criteria);
393 void extract_flushWriteKeys (ZebraHandle zh);
395 struct zebra_fetch_control {
398 off_t record_int_pos;
399 const char *record_int_buf;
404 int zebra_record_ext_read (void *fh, char *buf, size_t count);
405 off_t zebra_record_ext_seek (void *fh, off_t offset);
406 off_t zebra_record_ext_tell (void *fh);
407 off_t zebra_record_int_seek (void *fh, off_t offset);
408 off_t zebra_record_int_tell (void *fh);
409 int zebra_record_int_read (void *fh, char *buf, size_t count);
410 void zebra_record_int_end (void *fh, off_t offset);
412 void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
413 int cmd, struct recKeys *reckeys);
414 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
415 int cmd, struct sortKey **skp);
416 void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
417 void extract_token_add (RecWord *p);
418 int explain_extract (void *handle, Record rec, data1_node *n);
420 int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
421 const struct recordGroup *rGroup, int deleteFlag);
423 int zebra_begin_read (ZebraHandle zh);
424 void zebra_end_read (ZebraHandle zh);