1 /* $Id: index.h,v 1.91 2002-11-15 21:26:00 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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
35 #include <sys/times.h>
45 #define ISAM_DEFAULT "c"
58 #define IT_MAX_WORD 256
59 #define IT_KEY_HAVE_SEQNO 1
60 #define IT_KEY_HAVE_FIELD 0
69 enum dirsKind { dirs_dir, dirs_file };
84 void getFnameTmp (Res res, char *fname, int no);
86 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
87 struct dirs_info *dirs_fopen (Dict dict, const char *path);
88 struct dirs_entry *dirs_read (struct dirs_info *p);
89 struct dirs_entry *dirs_last (struct dirs_info *p);
90 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
91 void dirs_rmdir (struct dirs_info *p, const char *src);
92 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime);
93 void dirs_del (struct dirs_info *p, const char *src);
94 void dirs_free (struct dirs_info **pp);
96 struct dir_entry *dir_open (const char *rep, const char *base,
98 void dir_sort (struct dir_entry *e);
99 void dir_free (struct dir_entry **e_p);
101 void repositoryUpdate (ZebraHandle zh);
102 void repositoryAdd (ZebraHandle zh);
103 void repositoryDelete (ZebraHandle zh);
104 void repositoryShow (ZebraHandle zh);
106 int key_open (ZebraHandle zh, int mem);
107 int key_close (ZebraHandle zh);
108 int key_compare (const void *p1, const void *p2);
109 char *key_print_it (const void *p, char *buf);
110 int key_get_pos (const void *p);
111 int key_compare_it (const void *p1, const void *p2);
112 int key_qsort_compare (const void *p1, const void *p2);
113 void key_logdump (int mask, const void *p);
114 void inv_prstat (ZebraHandle zh);
115 void inv_compact (BFiles bfs);
116 void key_input (ZebraHandle zh, int nkeys, int cache, Res res);
117 ISAMS_M key_isams_m (Res res, ISAMS_M me);
118 ISAMC_M key_isamc_m (Res res, ISAMC_M me);
119 ISAMD_M key_isamd_m (Res res, ISAMD_M me);
120 int merge_sort (char **buf, int from, int to);
121 int key_SU_code (int ch, char *out);
123 #define FNAME_DICT "dict"
124 #define FNAME_ISAM "isam"
125 #define FNAME_ISAMC "isamc"
126 #define FNAME_ISAMS "isams"
127 #define FNAME_ISAMH "isamh"
128 #define FNAME_ISAMD "isamd"
129 #define FNAME_CONFIG "zebra.cfg"
131 #define GMATCH_DICT "gmatch"
132 #define FMATCH_DICT "fmatch"
134 struct strtab *strtab_mk (void);
135 int strtab_src (struct strtab *t, const char *name, void ***infop);
136 void strtab_del (struct strtab *t,
137 void (*func)(const char *name, void *info, void *data),
139 int index_char_cvt (int c);
140 int index_word_prefix (char *string, int attset_ordinal,
141 int local_attribute, const char *databaseName);
144 void zebraIndexLockMsg (ZebraHandle zh, const char *str);
145 void zebraIndexUnlock (ZebraHandle zh);
146 int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
147 int zebraIndexWait (ZebraHandle zh, int commitPhase);
149 #define FNAME_MAIN_LOCK "zebraidx.LCK"
150 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
151 #define FNAME_ORG_LOCK "zebraorg.LCK"
152 #define FNAME_TOUCH_TIME "zebraidx.time"
154 typedef struct zebra_lock_info *ZebraLockHandle;
155 ZebraLockHandle zebra_lock_create(const char *dir,
156 const char *file, int excl_flag);
157 void zebra_lock_destroy (ZebraLockHandle h);
158 int zebra_lock (ZebraLockHandle h);
159 int zebra_lock_nb (ZebraLockHandle h);
160 int zebra_unlock (ZebraLockHandle h);
161 int zebra_lock_fd (ZebraLockHandle h);
162 void zebra_lock_prefix (Res res, char *dst);
163 char *zebra_mk_fname (const char *dir, const char *name);
165 int zebra_lock_w (ZebraLockHandle h);
166 int zebra_lock_r (ZebraLockHandle h);
168 void zebra_load_atts (data1_handle dh, Res res);
170 int key_SU_decode (int *ch, const unsigned char *out);
171 int key_SU_encode (int ch, char *out);
173 // extern Res common_resource;
175 #define ENCODE_BUFLEN 768
177 int sysno; /* previously written values for delta-compress */
180 int prevsys; /* buffer for skipping insert/delete pairs */
183 int keylen; /* tells if we have an unwritten key in buf, and how long*/
184 char buf[ENCODE_BUFLEN];
187 void encode_key_init (struct encode_info *i);
188 char *encode_key_int (int d, char *bp);
189 void encode_key_write (char *k, struct encode_info *i, FILE *outf);
190 void encode_key_flush (struct encode_info *i, FILE *outf);
199 typedef struct zebra_set *ZebraSet;
201 typedef struct zebra_rank_class {
202 struct rank_control *control;
205 struct zebra_rank_class *next;
229 struct sortKey *next;
233 struct zebra_register {
244 int registerState; /* 0 (no commit pages), 1 (use commit pages) */
245 time_t registerChange;
248 ZebraExplainInfo zei;
250 char *server_path_prefix;
252 ZebraMaps zebra_maps;
253 ZebraRankClass rank_classes;
258 int active; /* 0=shutdown, 1=enabled and inactive, 2=activated */
262 struct sortKeys sortKeys;
264 struct sortKey *sortKeys;
273 struct zebra_service {
277 struct zebra_session *sessions;
278 struct zebra_register *regs;
279 Zebra_mutex_cond session_lock;
285 struct zebra_session {
286 struct zebra_session *next;
287 struct zebra_service *service;
288 struct zebra_register *reg;
290 char *admin_databaseName;
297 ZebraLockHandle lock_normal;
298 ZebraLockHandle lock_shadow;
311 struct recordGroup rGroup;
314 int records_inserted;
317 int records_processed;
318 char *record_encoding;
320 yaz_iconv_t iconv_to_utf8;
321 yaz_iconv_t iconv_from_utf8;
324 struct rank_control {
326 void *(*create)(struct zebra_register *reg);
327 void (*destroy)(struct zebra_register *reg, void *class_handle);
328 void *(*begin)(struct zebra_register *reg, void *class_handle, RSET rset);
329 void (*end)(struct zebra_register *reg, void *set_handle);
330 int (*calc)(void *set_handle, int sysno);
331 void (*add)(void *set_handle, int seqno, int term_index);
334 struct term_set_entry {
336 struct term_set_entry *next;
339 struct term_set_list {
340 struct term_set_entry *first;
341 struct term_set_entry *last;
344 RSET rpn_search (ZebraHandle zh, NMEM mem,
345 Z_RPNQuery *rpn, int num_bases, char **basenames,
346 const char *setname, ZebraSet sset);
349 void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
350 oid_value attributeset,
351 int num_bases, char **basenames,
352 int *position, int *num_entries, ZebraScanEntry **list,
355 RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
356 const char *term, int length_term, const char *flags,
357 int preserve_position, int term_type);
359 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
360 const char *db, int set,
361 int use, const char *term);
362 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
363 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
364 ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode,
365 Z_RPNQuery *rpn, int num_bases,
366 char **basenames, const char *setname);
367 RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
368 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
372 ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
373 int num, int *positions);
374 void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
376 void resultSetSort (ZebraHandle zh, NMEM nmem,
377 int num_input_setnames, const char **input_setnames,
378 const char *output_setname,
379 Z_SortKeySpecList *sort_sequence, int *sort_status);
380 void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
381 ZebraSet sset, RSET rset,
382 Z_SortKeySpecList *sort_sequence, int *sort_status);
383 void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
384 void resultSetInvalidate (ZebraHandle zh);
386 int zebra_server_lock_init (ZebraService zh);
387 int zebra_server_lock_destroy (ZebraService zh);
388 int zebra_server_lock (ZebraService zh, int lockCommit);
389 void zebra_server_unlock (ZebraService zh, int commitPhase);
390 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
392 typedef struct attent
395 data1_local_attribute *local_attributes;
398 void zebraRankInstall (struct zebra_register *reg, struct rank_control *ctrl);
399 ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
400 void zebraRankDestroy (struct zebra_register *reg);
402 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
404 extern struct rank_control *rank1_class;
406 int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
407 oid_value input_format, Z_RecordComposition *comp,
408 oid_value *output_format, char **rec_bufp,
409 int *rec_lenp, char **basenamep);
411 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
412 void zebra_index_merge (ZebraHandle zh);
414 int bufferExtractRecord (ZebraHandle zh,
415 const char *buf, size_t buf_size,
416 struct recordGroup *rGroup,
420 const char *match_criteria,
423 int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
424 const char *buf, size_t buf_size,
425 const char *databaseName, int delete_flag,
426 int test_mode, int *sysno,
427 int store_keys, int store_data,
428 const char *match_criteria);
429 void extract_flushWriteKeys (ZebraHandle zh);
431 struct zebra_fetch_control {
434 off_t record_int_pos;
435 const char *record_int_buf;
440 int zebra_record_ext_read (void *fh, char *buf, size_t count);
441 off_t zebra_record_ext_seek (void *fh, off_t offset);
442 off_t zebra_record_ext_tell (void *fh);
443 off_t zebra_record_int_seek (void *fh, off_t offset);
444 off_t zebra_record_int_tell (void *fh);
445 int zebra_record_int_read (void *fh, char *buf, size_t count);
446 void zebra_record_int_end (void *fh, off_t offset);
448 void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
449 int cmd, struct recKeys *reckeys);
450 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
451 int cmd, struct sortKeys *skp);
452 void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
453 void extract_token_add (RecWord *p);
454 int explain_extract (void *handle, Record rec, data1_node *n);
456 int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
457 const struct recordGroup *rGroup, int deleteFlag);
459 int zebra_begin_read (ZebraHandle zh);
460 void zebra_end_read (ZebraHandle zh);
462 int zebra_file_stat (const char *file_name, struct stat *buf,