2 * Copyright (C) 1995-2002, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
5 * $Id: index.h,v 1.80 2002-04-15 13:48:10 adam Exp $
18 #include <sys/times.h>
26 #define ISAM_DEFAULT "c"
27 #include <yaz/data1.h>
39 #define IT_MAX_WORD 256
40 #define IT_KEY_HAVE_SEQNO 1
41 #define IT_KEY_HAVE_FIELD 0
50 enum dirsKind { dirs_dir, dirs_file };
65 void getFnameTmp (Res res, char *fname, int no);
67 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
68 struct dirs_info *dirs_fopen (Dict dict, const char *path);
69 struct dirs_entry *dirs_read (struct dirs_info *p);
70 struct dirs_entry *dirs_last (struct dirs_info *p);
71 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
72 void dirs_rmdir (struct dirs_info *p, const char *src);
73 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime);
74 void dirs_del (struct dirs_info *p, const char *src);
75 void dirs_free (struct dirs_info **pp);
77 struct dir_entry *dir_open (const char *rep, const char *base);
78 void dir_sort (struct dir_entry *e);
79 void dir_free (struct dir_entry **e_p);
81 void repositoryUpdate (ZebraHandle zh);
82 void repositoryAdd (ZebraHandle zh);
83 void repositoryDelete (ZebraHandle zh);
84 void repositoryShow (ZebraHandle zh);
86 int key_open (ZebraHandle zh, int mem);
87 int key_close (ZebraHandle zh);
88 int key_compare (const void *p1, const void *p2);
89 char *key_print_it (const void *p, char *buf);
90 int key_get_pos (const void *p);
91 int key_compare_it (const void *p1, const void *p2);
92 int key_qsort_compare (const void *p1, const void *p2);
93 void key_logdump (int mask, const void *p);
94 void inv_prstat (ZebraHandle zh);
95 void inv_compact (BFiles bfs);
96 void key_input (ZebraHandle zh, int nkeys, int cache, Res res);
97 ISAMS_M key_isams_m (Res res, ISAMS_M me);
98 ISAMC_M key_isamc_m (Res res, ISAMC_M me);
99 ISAMD_M key_isamd_m (Res res, ISAMD_M me);
100 int merge_sort (char **buf, int from, int to);
101 int key_SU_code (int ch, char *out);
103 #define FNAME_DICT "dict"
104 #define FNAME_ISAM "isam"
105 #define FNAME_ISAMC "isamc"
106 #define FNAME_ISAMS "isams"
107 #define FNAME_ISAMH "isamh"
108 #define FNAME_ISAMD "isamd"
109 #define FNAME_CONFIG "zebra.cfg"
111 #define GMATCH_DICT "gmatch"
112 #define FMATCH_DICT "fmatch"
114 struct strtab *strtab_mk (void);
115 int strtab_src (struct strtab *t, const char *name, void ***infop);
116 void strtab_del (struct strtab *t,
117 void (*func)(const char *name, void *info, void *data),
119 int index_char_cvt (int c);
120 int index_word_prefix (char *string, int attset_ordinal,
121 int local_attribute, const char *databaseName);
124 void zebraIndexLockMsg (ZebraHandle zh, const char *str);
125 void zebraIndexUnlock (ZebraHandle zh);
126 int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
127 int zebraIndexWait (ZebraHandle zh, int commitPhase);
129 #define FNAME_MAIN_LOCK "zebraidx.LCK"
130 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
131 #define FNAME_ORG_LOCK "zebraorg.LCK"
132 #define FNAME_TOUCH_TIME "zebraidx.time"
134 typedef struct zebra_lock_info *ZebraLockHandle;
135 ZebraLockHandle zebra_lock_create(const char *dir,
136 const char *file, int excl_flag);
137 void zebra_lock_destroy (ZebraLockHandle h);
138 int zebra_lock (ZebraLockHandle h);
139 int zebra_lock_nb (ZebraLockHandle h);
140 int zebra_unlock (ZebraLockHandle h);
141 int zebra_lock_fd (ZebraLockHandle h);
142 void zebra_lock_prefix (Res res, char *dst);
143 char *zebra_mk_fname (const char *dir, const char *name);
145 int zebra_lock_w (ZebraLockHandle h);
146 int zebra_lock_r (ZebraLockHandle h);
148 void zebra_load_atts (data1_handle dh, Res res);
150 int key_SU_decode (int *ch, const unsigned char *out);
151 int key_SU_encode (int ch, char *out);
153 // extern Res common_resource;
162 void encode_key_init (struct encode_info *i);
163 char *encode_key_int (int d, char *bp);
164 void encode_key_write (char *k, struct encode_info *i, FILE *outf);
173 typedef struct zebra_set *ZebraSet;
175 typedef struct zebra_rank_class {
176 struct rank_control *control;
179 struct zebra_rank_class *next;
196 struct sortKey *next;
199 struct zebra_register {
209 int registerState; /* 0 (no commit pages), 1 (use commit pages) */
210 time_t registerChange;
213 ZebraExplainInfo zei;
215 char *server_path_prefix;
217 ZebraMaps zebra_maps;
218 ZebraRankClass rank_classes;
223 int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
228 struct sortKey *sortKeys;
237 struct zebra_service {
241 struct zebra_session *sessions;
242 struct zebra_register *regs;
243 Zebra_mutex_cond session_lock;
249 struct zebra_session {
250 struct zebra_session *next;
251 struct zebra_service *service;
252 struct zebra_register *reg;
254 char *admin_databaseName;
261 ZebraLockHandle lock_normal;
262 ZebraLockHandle lock_shadow;
275 struct recordGroup rGroup;
279 struct rank_control {
281 void *(*create)(struct zebra_register *reg);
282 void (*destroy)(struct zebra_register *reg, void *class_handle);
283 void *(*begin)(struct zebra_register *reg, void *class_handle, RSET rset);
284 void (*end)(struct zebra_register *reg, void *set_handle);
285 int (*calc)(void *set_handle, int sysno);
286 void (*add)(void *set_handle, int seqno, int term_index);
289 struct term_set_entry {
291 struct term_set_entry *next;
294 struct term_set_list {
295 struct term_set_entry *first;
296 struct term_set_entry *last;
299 RSET rpn_search (ZebraHandle zh, NMEM mem,
300 Z_RPNQuery *rpn, int num_bases, char **basenames,
301 const char *setname, ZebraSet sset);
304 void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
305 oid_value attributeset,
306 int num_bases, char **basenames,
307 int *position, int *num_entries, ZebraScanEntry **list,
310 RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
311 const char *term, int length_term, const char *flags,
312 int preserve_position);
314 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
315 const char *db, int set,
316 int use, const char *term);
317 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
318 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
319 ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode,
320 Z_RPNQuery *rpn, int num_bases,
321 char **basenames, const char *setname);
322 RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
323 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
327 ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
328 int num, int *positions);
329 void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
331 void resultSetSort (ZebraHandle zh, NMEM nmem,
332 int num_input_setnames, const char **input_setnames,
333 const char *output_setname,
334 Z_SortKeySpecList *sort_sequence, int *sort_status);
335 void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
336 ZebraSet sset, RSET rset,
337 Z_SortKeySpecList *sort_sequence, int *sort_status);
338 void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
339 void resultSetInvalidate (ZebraHandle zh);
341 int zebra_server_lock_init (ZebraService zh);
342 int zebra_server_lock_destroy (ZebraService zh);
343 int zebra_server_lock (ZebraService zh, int lockCommit);
344 void zebra_server_unlock (ZebraService zh, int commitPhase);
345 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
347 typedef struct attent
350 data1_local_attribute *local_attributes;
353 void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl);
354 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
355 void zebraRankDestroy (struct zebra_register *reg);
357 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
359 extern struct rank_control *rank1_class;
361 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
362 oid_value input_format, Z_RecordComposition *comp,
363 oid_value *output_format, char **rec_bufp,
364 int *rec_lenp, char **basenamep);
366 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
367 void zebra_index_merge (ZebraHandle zh);
370 int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
371 const char *buf, size_t buf_size,
372 const char *databaseName, int delete_flag,
373 int test_mode, int *sysno,
374 int store_keys, int store_data,
375 const char *match_criteria);
377 void extract_flushWriteKeys (ZebraHandle zh);
379 struct zebra_fetch_control {
382 off_t record_int_pos;
383 const char *record_int_buf;
388 int zebra_record_ext_read (void *fh, char *buf, size_t count);
389 off_t zebra_record_ext_seek (void *fh, off_t offset);
390 off_t zebra_record_ext_tell (void *fh);
391 off_t zebra_record_int_seek (void *fh, off_t offset);
392 off_t zebra_record_int_tell (void *fh);
393 int zebra_record_int_read (void *fh, char *buf, size_t count);
394 void zebra_record_int_end (void *fh, off_t offset);
396 void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
397 int cmd, struct recKeys *reckeys);
398 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
399 int cmd, struct sortKey **skp);
400 void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
401 void extract_token_add (RecWord *p);
402 int explain_extract (void *handle, Record rec, data1_node *n);
404 int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
405 const struct recordGroup *rGroup, int deleteFlag);