1 /* This file is part of the Zebra server.
2 Copyright (C) 2004-2013 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <idzebra/version.h>
26 #include <idzebra/util.h>
27 #include <idzebra/flock.h>
30 #include <sys/times.h>
34 #include <yaz/timing.h>
35 #include <idzebra/dict.h>
36 #include <idzebra/isams.h>
37 #include <idzebra/isamc.h>
38 #include <idzebra/isamb.h>
40 #include <idzebra/recgrs.h>
42 #include <idzebra/api.h>
53 #define ISAM_DEFAULT "b"
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, int rw);
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, zint 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,
84 void dir_sort(struct dir_entry *e);
85 void dir_free(struct dir_entry **e_p);
87 void repositoryUpdate(ZebraHandle zh, const char *path);
88 void repositoryAdd(ZebraHandle zh, const char *path);
89 void repositoryDelete(ZebraHandle zh, const char *path);
90 void repositoryShow(ZebraHandle zh, const char *path);
92 void inv_prstat(ZebraHandle zh);
93 void inv_compact(BFiles bfs);
94 void key_input(ZebraHandle zh, int nkeys, int cache, Res res);
95 ISAMS_M *key_isams_m(Res res, ISAMS_M *me);
96 ISAMC_M *key_isamc_m(Res res, ISAMC_M *me);
98 #define FNAME_DICT "dict"
99 #define FNAME_ISAM "isam"
100 #define FNAME_ISAMC "isamc"
101 #define FNAME_ISAMS "isams"
102 #define FNAME_CONFIG "zebra.cfg"
104 #define GMATCH_DICT "gmatch"
105 #define FMATCH_DICT "fmatch%d"
107 void zebra_lock_prefix(Res res, char *dst);
109 #define FNAME_MAIN_LOCK "zebraidx.LCK"
110 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
111 #define FNAME_ORG_LOCK "zebraorg.LCK"
112 #define FNAME_TOUCH_TIME "zebraidx.time"
114 typedef struct zebra_set *ZebraSet;
116 typedef struct zebra_rank_class {
117 struct rank_control *control;
120 struct zebra_rank_class *next;
124 #include "key_block.h"
126 struct zebra_register {
134 zebra_sort_index_t sort_index;
135 int registerState; /* 0 (no commit pages), 1 (use commit pages) */
136 time_t registerChange;
139 ZebraExplainInfo zei;
141 char *server_path_prefix;
143 zebra_maps_t zebra_maps;
144 ZebraRankClass rank_classes;
150 zebra_rec_keys_t keys;
151 zebra_rec_keys_t sortKeys;
153 zebra_key_block_t key_block;
156 struct zebra_service {
159 struct zebra_session *sessions;
160 struct zebra_register *regs;
161 Zebra_mutex_cond session_lock;
164 const char *path_root;
165 RecTypeClass record_classes;
171 struct zebra_session {
172 struct zebra_session *next;
173 struct zebra_service *service;
174 struct zebra_register *reg;
176 char *xadmin_databaseName;
184 ZebraLockHandle lock_normal;
185 ZebraLockHandle lock_shadow;
206 int m_segment_indexing;
208 zint records_inserted;
209 zint records_updated;
210 zint records_deleted;
211 zint records_processed;
212 zint records_skipped;
213 char *record_encoding;
215 yaz_iconv_t iconv_to_utf8;
216 yaz_iconv_t iconv_from_utf8;
220 const char *m_record_id;
221 const char *m_record_type;
224 int m_explain_database;
226 int m_file_verbose_limit;
228 void *store_data_buf;
229 size_t store_data_size;
232 struct zebra_limit *m_limit;
234 int (*break_handler_func)(void *client_data);
235 void *break_handler_data;
239 struct term_set_entry {
241 struct term_set_entry *next;
244 struct term_set_list {
245 struct term_set_entry *first;
246 struct term_set_entry *last;
250 void zebra_limit_destroy(struct zebra_limit *zl);
251 struct zebra_limit *zebra_limit_create(int exclude_flag, zint *ids);
252 void zebra_limit_for_rset(struct zebra_limit *zl,
253 int (**filter_func)(const void *buf, void *data),
254 void (**filter_destroy)(void *data),
257 struct rset_key_control *zebra_key_control_create(ZebraHandle zh);
259 ZEBRA_RES rpn_search_top(ZebraHandle zh, Z_RPNStructure *zs,
260 const Odr_oid *attributeSet, zint hits_limit,
261 NMEM stream, NMEM rset_nmem,
262 Z_SortKeySpecList *sort_sequence,
263 int num_bases, const char **basenames,
266 ZEBRA_RES rpn_get_top_approx_limit(ZebraHandle zh, Z_RPNStructure *zs,
269 ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
270 const Odr_oid *attributeset,
271 int num_bases, char **basenames,
272 int *position, int *num_entries, ZebraScanEntry **list,
273 int *is_partial, const char *set_name);
275 RSET rset_trunc(ZebraHandle zh, ISAM_P *isam_p, int no,
276 const char *term, int length_term, const char *flags,
277 int preserve_position, int term_type, NMEM rset_nmem,
278 struct rset_key_control *kctrl, int scope,
279 struct ord_list *ol, const char *index_type,
280 zint hits_limit, const char *term_ref_id);
282 ZEBRA_RES resultSetGetBaseNames(ZebraHandle zh, const char *setname,
283 const char ***basenames, int *num_bases);
285 void resultSetAddTerm(ZebraHandle zh, ZebraSet s, int reg_type,
286 const char *db, const char *index_name,
288 ZebraSet resultSetAdd(ZebraHandle zh, const char *name, int ov);
289 ZebraSet resultSetGet(ZebraHandle zh, const char *name);
290 ZEBRA_RES resultSetAddRPN(ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
291 int num_bases, char **basenames,
293 zint *hits, int *estimated_hit_count);
294 RSET resultSetRef(ZebraHandle zh, const char *resultSetId);
295 void resultSetDestroy(ZebraHandle zh, int num_names, char **names,
297 ZEBRA_RES resultSetSort(ZebraHandle zh, NMEM nmem,
298 int num_input_setnames, const char **input_setnames,
299 const char *output_setname,
300 Z_SortKeySpecList *sort_sequence, int *sort_status);
301 ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem,
302 ZebraSet sset, RSET rset,
303 Z_SortKeySpecList *sort_sequence,
305 ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet, RSET rset,
307 void resultSetInvalidate(ZebraHandle zh);
309 int zebra_record_fetch(ZebraHandle zh, const char *setname,
310 zint sysno, int score,
312 const Odr_oid *input_format, Z_RecordComposition *comp,
313 const Odr_oid **output_format, char **rec_bufp,
314 int *rec_lenp, char **basenamep,
317 void extract_get_fname_tmp(ZebraHandle zh, char *fname, int no);
319 void extract_snippet(ZebraHandle zh, zebra_snippets *sn,
320 struct ZebraRecStream *stream, RecType rt,
321 void *recTypeClientData);
323 int zebra_get_rec_snippets(ZebraHandle zh, zint sysno,
324 zebra_snippets *snippets);
326 void zebra_index_merge(ZebraHandle zh);
328 ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh,
329 const char *buf, size_t buf_size,
330 enum zebra_recctrl_action_t action,
331 const char *recordType,
333 const char *match_criteria,
337 YAZ_EXPORT void zebra_create_stream_mem(struct ZebraRecStream *stream,
338 const char *buf, size_t sz);
339 YAZ_EXPORT void zebra_create_stream_fd(struct ZebraRecStream *stream,
340 int fd, off_t start_offset);
341 void print_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys);
343 ZEBRA_RES zebra_rec_keys_to_snippets(ZebraHandle zh, zebra_rec_keys_t reckeys,
344 zebra_snippets *snippets);
345 ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
346 zint sysno, zebra_snippets *snippets);
348 ZEBRA_RES zebra_extract_explain(void *handle, Record rec, data1_node *n);
350 ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname,
351 enum zebra_recctrl_action_t action);
353 ZEBRA_RES zebra_begin_read(ZebraHandle zh);
354 ZEBRA_RES zebra_end_read(ZebraHandle zh);
356 int zebra_file_stat(const char *file_name, struct stat *buf,
359 Dict dict_open_res(BFiles bfs, const char *name, int cache, int rw,
360 int compact_flag, Res res);
362 void zebra_setError(ZebraHandle zh, int code, const char *addinfo);
363 void zebra_setError_zint(ZebraHandle zh, int code, zint i);
365 int zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream,
366 const char *index_type,
367 char **dst, const char *src);
369 ZEBRA_RES zebra_get_hit_vector(ZebraHandle zh, const char *setname, zint sysno);
371 int zebra_term_untrans(ZebraHandle zh, const char *index_type,
372 char *dst, const char *src);
374 ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh,
375 Z_AttributesPlusTerm *zapt,
376 const char *index_type,
377 const char *xpath_use,
378 const Odr_oid *curAttributeSet,
381 ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh,
382 Z_AttributeList *attr_list,
383 zinfo_index_category_t cat,
384 const char *index_type,
385 const Odr_oid *curAttributeSet,
388 ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh,
389 Z_SortAttributes *sortAttributes,
393 ZEBRA_RES zebra_update_file_match(ZebraHandle zh, const char *path);
394 ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path,
395 enum zebra_recctrl_action_t action);
396 ZEBRA_RES zebra_remove_file_match(ZebraHandle zh);
398 struct rpn_char_map_info
404 void rpn_char_map_prepare(struct zebra_register *reg, zebra_map_t zm,
405 struct rpn_char_map_info *map_info);
407 ZEBRA_RES zapt_term_to_utf8(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
411 void zebra_set_partial_result(ZebraHandle zh);
413 int zebra_check_res(Res res);
415 #define FIRST_IN_FIELD_STR "\001^"
416 #define FIRST_IN_FIELD_CHAR 1
417 #define FIRST_IN_FIELD_LEN 2
419 ZEBRA_RES zebra_term_limits_APT(ZebraHandle zh,
420 Z_AttributesPlusTerm *zapt,
421 zint *hits_limit_value,
422 const char **term_ref_id_str,
425 ZEBRA_RES zebra_result_recid_to_sysno(ZebraHandle zh,
428 zint *sysnos, int *no_sysnos);
430 void zebra_count_set(ZebraHandle zh, RSET rset, zint *count,
433 RSET zebra_create_rset_isam(ZebraHandle zh,
434 NMEM rset_nmem, struct rset_key_control *kctl,
435 int scope, ISAM_P pos, TERMID termid);
437 void zebra_it_key_str_dump(ZebraHandle zh, struct it_key *key,
438 const char *str, size_t slen, NMEM nmem, int level);
446 * c-file-style: "Stroustrup"
447 * indent-tabs-mode: nil
449 * vim: shiftwidth=4 tabstop=8 expandtab