1 /* $Id: index.h,v 1.160 2006-05-10 08:13:21 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>
30 #include <idzebra/flock.h>
34 #include <sys/times.h>
38 #include <idzebra/dict.h>
39 #include <idzebra/isams.h>
40 #include <idzebra/isamc.h>
41 #include <idzebra/isamb.h>
43 #include <idzebra/recgrs.h>
45 #include <idzebra/api.h>
52 #define ISAM_DEFAULT "b"
56 #define IT_MAX_WORD 256
58 #define IT_KEY_LEVEL_MAX 5
61 zint mem[IT_KEY_LEVEL_MAX];
64 enum dirsKind { dirs_dir, dirs_file };
79 void getFnameTmp (Res res, char *fname, int no);
81 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
82 struct dirs_info *dirs_fopen (Dict dict, const char *path, int rw);
83 struct dirs_entry *dirs_read (struct dirs_info *p);
84 struct dirs_entry *dirs_last (struct dirs_info *p);
85 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
86 void dirs_rmdir (struct dirs_info *p, const char *src);
87 void dirs_add (struct dirs_info *p, const char *src, SYSNO sysno, time_t mtime);
88 void dirs_del (struct dirs_info *p, const char *src);
89 void dirs_free (struct dirs_info **pp);
91 struct dir_entry *dir_open (const char *rep, const char *base,
93 void dir_sort (struct dir_entry *e);
94 void dir_free (struct dir_entry **e_p);
96 void repositoryUpdate (ZebraHandle zh, const char *path);
97 void repositoryAdd (ZebraHandle zh, const char *path);
98 void repositoryDelete (ZebraHandle zh, const char *path);
99 void repositoryShow (ZebraHandle zh, const char *path);
101 int key_open (ZebraHandle zh, int mem);
102 int key_close (ZebraHandle zh);
103 int key_compare (const void *p1, const void *p2);
104 void key_init(struct it_key *k);
105 char *key_print_it (const void *p, char *buf);
106 zint key_get_seq (const void *p);
107 int key_compare_it (const void *p1, const void *p2);
108 int key_qsort_compare (const void *p1, const void *p2);
109 void key_logdump (int mask, const void *p);
110 void key_logdump_txt (int logmask, const void *p, const char *txt);
111 void inv_prstat (ZebraHandle zh);
112 void inv_compact (BFiles bfs);
113 void key_input (ZebraHandle zh, int nkeys, int cache, Res res);
114 ISAMS_M *key_isams_m (Res res, ISAMS_M *me);
115 ISAMC_M *key_isamc_m (Res res, ISAMC_M *me);
116 int merge_sort (char **buf, int from, int to);
117 int key_SU_code (int ch, char *out);
119 #define FNAME_DICT "dict"
120 #define FNAME_ISAM "isam"
121 #define FNAME_ISAMC "isamc"
122 #define FNAME_ISAMS "isams"
123 #define FNAME_ISAMH "isamh"
124 #define FNAME_ISAMD "isamd"
125 #define FNAME_CONFIG "zebra.cfg"
127 #define GMATCH_DICT "gmatch"
128 #define FMATCH_DICT "fmatch"
130 struct strtab *strtab_mk (void);
131 int strtab_src (struct strtab *t, const char *name, void ***infop);
132 void strtab_del (struct strtab *t,
133 void (*func)(const char *name, void *info, void *data),
135 int index_char_cvt (int c);
136 int index_word_prefix (char *string, int attset_ordinal,
137 int local_attribute, const char *databaseName);
140 void zebraIndexLockMsg (ZebraHandle zh, const char *str);
141 void zebraIndexUnlock (ZebraHandle zh);
142 int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
143 int zebraIndexWait (ZebraHandle zh, int commitPhase);
145 void zebra_lock_prefix (Res res, char *dst);
147 #define FNAME_MAIN_LOCK "zebraidx.LCK"
148 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
149 #define FNAME_ORG_LOCK "zebraorg.LCK"
150 #define FNAME_TOUCH_TIME "zebraidx.time"
152 void zebra_load_atts (data1_handle dh, Res res);
154 int key_SU_decode (int *ch, const unsigned char *out);
155 int key_SU_encode (int ch, char *out);
157 #define ENCODE_BUFLEN 768
159 int sysno; /* previously written values for delta-compress */
162 int prevsys; /* buffer for skipping insert/delete pairs */
165 int keylen; /* tells if we have an unwritten key in buf, and how long*/
168 char buf[ENCODE_BUFLEN];
171 void encode_key_init (struct encode_info *i);
172 char *encode_key_int (int d, char *bp);
173 void encode_key_write (char *k, struct encode_info *i, FILE *outf);
174 void encode_key_flush (struct encode_info *i, FILE *outf);
176 typedef struct zebra_set *ZebraSet;
178 typedef struct zebra_rank_class {
179 struct rank_control *control;
182 struct zebra_rank_class *next;
197 struct zebra_register {
206 int registerState; /* 0 (no commit pages), 1 (use commit pages) */
207 time_t registerChange;
210 ZebraExplainInfo zei;
212 char *server_path_prefix;
214 ZebraMaps zebra_maps;
215 ZebraRankClass rank_classes;
221 zebra_rec_keys_t keys;
224 zebra_rec_keys_t sortKeys;
226 struct sortKeys sortKeys;
235 struct zebra_service {
238 struct zebra_session *sessions;
239 struct zebra_register *regs;
240 Zebra_mutex_cond session_lock;
243 const char *path_root;
244 RecTypeClass record_classes;
249 struct zebra_session {
250 struct zebra_session *next;
251 struct zebra_service *service;
252 struct zebra_register *reg;
254 char *xadmin_databaseName;
262 ZebraLockHandle lock_normal;
263 ZebraLockHandle lock_shadow;
285 zint records_inserted;
286 zint records_updated;
287 zint records_deleted;
288 zint records_processed;
289 char *record_encoding;
291 yaz_iconv_t iconv_to_utf8;
292 yaz_iconv_t iconv_from_utf8;
296 const char *m_record_id;
297 const char *m_record_type;
300 int m_explain_database;
302 int m_file_verbose_limit;
304 void *store_data_buf;
305 size_t store_data_size;
308 struct zebra_limit *m_limit;
312 struct term_set_entry {
314 struct term_set_entry *next;
317 struct term_set_list {
318 struct term_set_entry *first;
319 struct term_set_entry *last;
323 void zebra_limit_destroy(struct zebra_limit *zl);
324 struct zebra_limit *zebra_limit_create(int exclude_flag, zint *ids);
325 void zebra_limit_for_rset(struct zebra_limit *zl,
326 int (**filter_func)(const void *buf, void *data),
327 void (**filter_destroy)(void *data),
330 struct rset_key_control *zebra_key_control_create(ZebraHandle zh);
332 ZEBRA_RES rpn_search_top(ZebraHandle zh, Z_RPNStructure *zs,
333 oid_value attributeSet,
334 NMEM stream, NMEM rset_nmem,
335 Z_SortKeySpecList *sort_sequence,
336 int num_bases, char **basenames,
339 ZEBRA_RES rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
340 oid_value attributeset,
341 int num_bases, char **basenames,
342 int *position, int *num_entries, ZebraScanEntry **list,
343 int *is_partial, RSET limit_set, int return_zero);
345 RSET rset_trunc(ZebraHandle zh, ISAM_P *isam_p, int no,
346 const char *term, int length_term, const char *flags,
347 int preserve_position, int term_type, NMEM rset_nmem,
348 struct rset_key_control *kctrl, int scope,
349 struct ord_list *ol, int reg_type,
350 zint hits_limit, const char *term_ref_id);
352 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
353 const char *db, int set,
354 int use, const char *term);
355 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
356 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
357 ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
358 int num_bases, char **basenames,
359 const char *setname);
360 RSET resultSetRef (ZebraHandle zh, const char *resultSetId);
361 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
363 ZEBRA_RES resultSetSort (ZebraHandle zh, NMEM nmem,
364 int num_input_setnames, const char **input_setnames,
365 const char *output_setname,
366 Z_SortKeySpecList *sort_sequence, int *sort_status);
367 ZEBRA_RES resultSetSortSingle (ZebraHandle zh, NMEM nmem,
368 ZebraSet sset, RSET rset,
369 Z_SortKeySpecList *sort_sequence,
371 ZEBRA_RES resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset,
373 void resultSetInvalidate (ZebraHandle zh);
375 int zebra_server_lock_init (ZebraService zh);
376 int zebra_server_lock_destroy (ZebraService zh);
377 int zebra_server_lock (ZebraService zh, int lockCommit);
378 void zebra_server_unlock (ZebraService zh, int commitPhase);
379 int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
381 typedef struct attent
384 data1_local_attribute *local_attributes;
387 int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att,
390 int zebra_record_fetch (ZebraHandle zh, SYSNO sysno, int score,
391 zebra_snippets *hit_snippet, ODR stream,
392 oid_value input_format, Z_RecordComposition *comp,
393 oid_value *output_format, char **rec_bufp,
394 int *rec_lenp, char **basenamep,
397 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
399 void zebra_index_merge (ZebraHandle zh);
401 ZEBRA_RES buffer_extract_record (ZebraHandle zh,
402 const char *buf, size_t buf_size,
405 const char *recordType,
407 const char *match_criteria,
413 int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
414 const char *buf, size_t buf_size,
415 const char *databaseName, int delete_flag,
416 int test_mode, int *sysno,
417 int store_keys, int store_data,
418 const char *match_criteria);
420 void extract_flushWriteKeys (ZebraHandle zh, int final);
422 struct zebra_fetch_control {
425 off_t record_int_pos;
426 const char *record_int_buf;
431 int zebra_record_ext_read (void *fh, char *buf, size_t count);
432 off_t zebra_record_ext_seek (void *fh, off_t offset);
433 off_t zebra_record_ext_tell (void *fh);
434 off_t zebra_record_int_seek (void *fh, off_t offset);
435 off_t zebra_record_int_tell (void *fh);
436 int zebra_record_int_read (void *fh, char *buf, size_t count);
437 void zebra_record_int_end (void *fh, off_t offset);
439 void print_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys);
441 ZEBRA_RES zebra_snippets_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys,
442 zebra_snippets *snippets);
443 ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
444 zint sysno, zebra_snippets *snippets);
446 void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
447 int cmd, zebra_rec_keys_t reckeys,
450 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
451 int cmd, zebra_rec_keys_t skp);
453 void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
454 int cmd, struct sortKeys *skp);
456 void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid);
457 void extract_token_add (RecWord *p);
458 int explain_extract (void *handle, Record rec, data1_node *n);
460 ZEBRA_RES zebra_extract_file(ZebraHandle zh, SYSNO *sysno, const char *fname,
463 ZEBRA_RES zebra_begin_read (ZebraHandle zh);
464 ZEBRA_RES zebra_end_read (ZebraHandle zh);
466 int zebra_file_stat (const char *file_name, struct stat *buf,
469 void zebra_livcode_transform(ZebraHandle zh, Z_RPNQuery *query);
471 void *iscz1_start ();
472 void iscz1_reset (void *vp);
473 void iscz1_stop (void *p);
474 void iscz1_decode (void *vp, char **dst, const char **src);
475 void iscz1_encode (void *vp, char **dst, const char **src);
477 Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw,
478 int compact_flag, Res res);
480 void zebra_setError(ZebraHandle zh, int code, const char *addinfo);
481 void zebra_setError_zint(ZebraHandle zh, int code, zint i);
483 void zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream, int reg_type,
484 char **dst, const char *src);
486 ZEBRA_RES zebra_get_hit_vector(ZebraHandle zh, const char *setname, zint sysno);
488 void zebra_term_untrans(ZebraHandle zh, int reg_type,
489 char *dst, const char *src);
497 * indent-tabs-mode: nil
499 * vim: shiftwidth=4 tabstop=8 expandtab