Split it_key stuff into it_key.c. For indexing, sort key chunks in a separate
[idzebra-moved-to-github.git] / index / index.h
1 /* $Id: index.h,v 1.182 2006-11-21 14:32:38 adam Exp $
2    Copyright (C) 1995-2006
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 #ifndef ZEBRA_INDEX_H
24 #define ZEBRA_INDEX_H
25
26 #include <time.h>
27 #include <stdlib.h>
28 #include <idzebra/version.h>
29 #include <idzebra/util.h>
30 #include <idzebra/flock.h>
31 #include <sortidx.h>
32
33 #if HAVE_SYS_TIMES_H
34 #include <sys/times.h>
35 #endif
36 #include <sys/stat.h>
37
38 #include <idzebra/dict.h>
39 #include <idzebra/isams.h>
40 #include <idzebra/isamc.h>
41 #include <idzebra/isamb.h>
42 #include <d1_absyn.h>
43 #include <idzebra/recgrs.h>
44 #include "recindex.h"
45 #include <idzebra/api.h>
46 #include "zinfo.h"
47 #include <passwddb.h>
48 #include <rset.h>
49 #include <zebramap.h>
50
51 #include <it_key.h>
52 #include <su_codec.h>
53
54 YAZ_BEGIN_CDECL
55
56 #define ISAM_DEFAULT "b"
57
58 enum dirsKind { dirs_dir, dirs_file };
59
60 struct dir_entry {
61     enum dirsKind kind;
62     char *name;
63     time_t mtime;
64 };
65
66 struct dirs_entry {
67     enum dirsKind kind;
68     char path[256];
69     SYSNO sysno;
70     time_t mtime;
71 };
72
73 void getFnameTmp(Res res, char *fname, int no);
74         
75 struct dirs_info *dirs_open(Dict dict, const char *rep, int rw);
76 struct dirs_info *dirs_fopen(Dict dict, const char *path, int rw);
77 struct dirs_entry *dirs_read(struct dirs_info *p);
78 struct dirs_entry *dirs_last(struct dirs_info *p);
79 void dirs_mkdir(struct dirs_info *p, const char *src, time_t mtime);
80 void dirs_rmdir(struct dirs_info *p, const char *src);
81 void dirs_add(struct dirs_info *p, const char *src, SYSNO sysno, time_t mtime);
82 void dirs_del(struct dirs_info *p, const char *src);
83 void dirs_free(struct dirs_info **pp);
84
85 struct dir_entry *dir_open(const char *rep, const char *base,
86                             int follow_links);
87 void dir_sort(struct dir_entry *e);
88 void dir_free(struct dir_entry **e_p);
89
90 void repositoryUpdate(ZebraHandle zh, const char *path);
91 void repositoryAdd(ZebraHandle zh, const char *path);
92 void repositoryDelete(ZebraHandle zh, const char *path);
93 void repositoryShow(ZebraHandle zh, const char *path);
94
95 void inv_prstat(ZebraHandle zh);
96 void inv_compact(BFiles bfs);
97 void key_input(ZebraHandle zh, int nkeys, int cache, Res res);
98 ISAMS_M *key_isams_m(Res res, ISAMS_M *me);
99 ISAMC_M *key_isamc_m(Res res, ISAMC_M *me);
100
101 #define FNAME_DICT "dict"
102 #define FNAME_ISAM "isam"
103 #define FNAME_ISAMC "isamc"
104 #define FNAME_ISAMS "isams"
105 #define FNAME_CONFIG "zebra.cfg"
106
107 #define GMATCH_DICT "gmatch"
108 #define FMATCH_DICT "fmatch%d"
109
110 struct strtab *strtab_mk(void);
111 int strtab_src(struct strtab *t, const char *name, void ***infop);
112 void strtab_del(struct strtab *t,
113                 void (*func)(const char *name, void *info, void *data),
114                 void *data);
115
116 void zebraIndexLockMsg(ZebraHandle zh, const char *str);
117 void zebraIndexUnlock(ZebraHandle zh);
118 int zebraIndexLock(BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
119 int zebraIndexWait(ZebraHandle zh, int commitPhase);
120
121 void zebra_lock_prefix(Res res, char *dst);
122
123 #define FNAME_MAIN_LOCK   "zebraidx.LCK"
124 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
125 #define FNAME_ORG_LOCK    "zebraorg.LCK"
126 #define FNAME_TOUCH_TIME  "zebraidx.time"
127
128 typedef struct zebra_set *ZebraSet;
129
130 typedef struct zebra_rank_class {
131     struct rank_control *control;
132     int init_flag;
133     void *class_handle;
134     struct zebra_rank_class *next;
135 } *ZebraRankClass;
136
137 #include "reckeys.h"
138 #include "key_block.h"
139
140 struct zebra_register {
141     char *name;
142     
143     ISAMS isams;
144     ISAMC isamc;
145     ISAMB isamb;
146     Dict dict;
147     Dict matchDict;
148     SortIdx sortIdx;
149     int registerState; /* 0 (no commit pages), 1 (use commit pages) */
150     time_t registerChange;
151     BFiles bfs;
152     Records records;
153     ZebraExplainInfo zei;
154
155     char *server_path_prefix;
156     data1_handle dh;
157     ZebraMaps zebra_maps;
158     ZebraRankClass rank_classes;
159     RecTypes recTypes;
160     int seqno;
161     int last_val;
162     int stop_flag;
163
164     zebra_rec_keys_t keys;
165     zebra_rec_keys_t sortKeys;
166
167     zebra_key_block_t key_block;
168 };
169
170 struct zebra_service {
171     int stop_flag;
172     Res global_res;
173     struct zebra_session *sessions;
174     struct zebra_register *regs;
175     Zebra_mutex_cond session_lock;
176     Passwd_db passwd_db;
177     Res dbaccess;
178     const char *path_root;
179     RecTypeClass record_classes;
180     NMEM nmem;
181 };
182
183
184 struct zebra_session {
185     struct zebra_session *next;
186     struct zebra_service *service;
187     struct zebra_register *reg;
188
189     char *xadmin_databaseName;
190
191     char **basenames;
192     int num_basenames;
193     zint approx_limit;
194     char *reg_name;
195     char *path_reg;
196
197     ZebraLockHandle lock_normal;
198     ZebraLockHandle lock_shadow;
199
200     int trans_no;
201     int trans_w_no;
202
203     int destroyed;
204     ZebraSet sets;
205     Res res;
206     Res session_res;
207     char *user_perm;
208     char *dbaccesslist;
209     int errCode;
210     zint hits;
211     char *errString;
212 #if HAVE_SYS_TIMES_H
213     struct tms tms1;
214     struct tms tms2;    
215 #endif
216     int  shadow_enable;
217
218     int m_staticrank;
219     int m_segment_indexing;
220
221     zint records_inserted;
222     zint records_updated;
223     zint records_deleted;
224     zint records_processed;
225     char *record_encoding;
226
227     yaz_iconv_t iconv_to_utf8;
228     yaz_iconv_t iconv_from_utf8;
229
230     int m_follow_links;
231     const char *m_group;
232     const char *m_record_id;
233     const char *m_record_type;
234     int m_store_data;
235     int m_store_keys;
236     int m_explain_database;
237     int m_flag_rw;
238     int m_file_verbose_limit;
239
240     void *store_data_buf;
241     size_t store_data_size;
242     NMEM nmem_error;
243
244     struct zebra_limit *m_limit;
245 };
246
247
248 struct term_set_entry {
249     char *term;
250     struct term_set_entry *next;
251 };
252
253 struct term_set_list {
254     struct term_set_entry *first;
255     struct term_set_entry *last;
256 };
257
258
259 void zebra_limit_destroy(struct zebra_limit *zl);
260 struct zebra_limit *zebra_limit_create(int exclude_flag, zint *ids);
261 void zebra_limit_for_rset(struct zebra_limit *zl,
262                           int (**filter_func)(const void *buf, void *data),
263                           void (**filter_destroy)(void *data),
264                           void **filter_data);
265
266 struct rset_key_control *zebra_key_control_create(ZebraHandle zh);
267
268 ZEBRA_RES rpn_search_top(ZebraHandle zh, Z_RPNStructure *zs,
269                          oid_value attributeSet, 
270                          NMEM stream, NMEM rset_nmem,
271                          Z_SortKeySpecList *sort_sequence,
272                          int num_bases, char **basenames,
273                          RSET *result_set);
274
275 ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
276                    oid_value attributeset,
277                    int num_bases, char **basenames,
278                    int *position, int *num_entries, ZebraScanEntry **list,
279                    int *is_partial, RSET limit_set);
280
281 RSET rset_trunc(ZebraHandle zh, ISAM_P *isam_p, int no,
282                 const char *term, int length_term, const char *flags,
283                 int preserve_position, int term_type, NMEM rset_nmem,
284                 struct rset_key_control *kctrl, int scope,
285                 struct ord_list *ol, int reg_type,
286                 zint hits_limit, const char *term_ref_id);
287
288 void resultSetAddTerm(ZebraHandle zh, ZebraSet s, int reg_type,
289                       const char *db, const char *index_name,
290                       const char *term);
291 ZebraSet resultSetAdd(ZebraHandle zh, const char *name, int ov);
292 ZebraSet resultSetGet(ZebraHandle zh, const char *name);
293 ZEBRA_RES resultSetAddRPN(ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
294                      int num_bases, char **basenames,
295                      const char *setname);
296 RSET resultSetRef(ZebraHandle zh, const char *resultSetId);
297 void resultSetDestroy(ZebraHandle zh, int num_names, char **names,
298                        int *statuses);
299 ZEBRA_RES resultSetSort(ZebraHandle zh, NMEM nmem,
300                          int num_input_setnames, const char **input_setnames,
301                          const char *output_setname,
302                          Z_SortKeySpecList *sort_sequence, int *sort_status);
303 ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem,
304                                ZebraSet sset, RSET rset,
305                                Z_SortKeySpecList *sort_sequence,
306                                int *sort_status);
307 ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet, RSET rset,
308                          NMEM nmem);
309 void resultSetInvalidate(ZebraHandle zh);
310
311 int zebra_record_fetch(ZebraHandle zh, SYSNO sysno, int score, 
312                         zebra_snippets *hit_snippet, ODR stream,
313                         oid_value input_format, Z_RecordComposition *comp,
314                         oid_value *output_format, char **rec_bufp,
315                         int *rec_lenp, char **basenamep,
316                         char **addinfo);
317
318 void extract_get_fname_tmp(ZebraHandle zh, char *fname, int no);
319
320 void zebra_index_merge(ZebraHandle zh);
321
322 ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh, 
323                                       const char *buf, size_t buf_size,
324                                       int delete_flag,
325                                       int test_mode, 
326                                       const char *recordType,
327                                       SYSNO *sysno,
328                                       const char *match_criteria,
329                                       const char *fname,
330                                       int force_update,
331                                       int allow_update);
332
333 ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, 
334                                       struct ZebraRecStream *stream,
335                                       int delete_flag,
336                                       int test_mode, 
337                                       const char *recordType,
338                                       SYSNO *sysno,
339                                       const char *match_criteria,
340                                       const char *fname,
341                                       int force_update,
342                                       int allow_update,
343                                       RecType recType,
344                                       void *recTypeClientData);
345
346 YAZ_EXPORT void zebra_create_stream_mem(struct ZebraRecStream *stream,
347                                         const char *buf, size_t sz);
348 YAZ_EXPORT void zebra_create_stream_fd(struct ZebraRecStream *stream,
349                                        int fd, off_t start_offset);
350 void print_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys);
351
352 ZEBRA_RES zebra_rec_keys_to_snippets(ZebraHandle zh, zebra_rec_keys_t reckeys,
353                                      zebra_snippets *snippets);
354 ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
355                                     zint sysno, zebra_snippets *snippets);
356
357 ZEBRA_RES zebra_extract_explain(void *handle, Record rec, data1_node *n);
358
359 ZEBRA_RES zebra_extract_file(ZebraHandle zh, SYSNO *sysno, const char *fname,
360                              int deleteFlag);
361
362 ZEBRA_RES zebra_begin_read(ZebraHandle zh);
363 ZEBRA_RES zebra_end_read(ZebraHandle zh);
364
365 int zebra_file_stat(const char *file_name, struct stat *buf,
366                      int follow_links);
367
368 Dict dict_open_res(BFiles bfs, const char *name, int cache, int rw,
369                    int compact_flag, Res res);
370
371 void zebra_setError(ZebraHandle zh, int code, const char *addinfo);
372 void zebra_setError_zint(ZebraHandle zh, int code, zint i);
373
374 void zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream, int reg_type,
375                               char **dst, const char *src);
376
377 ZEBRA_RES zebra_get_hit_vector(ZebraHandle zh, const char *setname, zint sysno);
378
379 void zebra_term_untrans(ZebraHandle zh, int reg_type,
380                         char *dst, const char *src);
381
382 ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh,
383                             Z_AttributesPlusTerm *zapt,
384                             int index_type,
385                             const char *xpath_use,
386                             oid_value curAttributeSet,
387                             int *ord);
388
389 ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh,
390                                   Z_AttributeList *attr_list,
391                                   zinfo_index_category_t cat,
392                                   int index_type,
393                                   oid_value curAttributeSet,
394                                   int *ord);
395
396 ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh,
397                              Z_SortAttributes *sortAttributes,
398                              int *ord,
399                              int *numerical);
400
401 ZEBRA_RES zebra_update_file_match(ZebraHandle zh, const char *path);
402 ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path);
403 ZEBRA_RES zebra_delete_from_path(ZebraHandle zh, const char *path);
404 ZEBRA_RES zebra_remove_file_match(ZebraHandle zh);
405
406 struct rpn_char_map_info
407 {
408     ZebraMaps zm;
409     int reg_type;
410 };
411
412 void rpn_char_map_prepare(struct zebra_register *reg, int reg_type,
413                           struct rpn_char_map_info *map_info);
414
415 ZEBRA_RES zapt_term_to_utf8(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
416                             char *termz);
417
418
419 #define FIRST_IN_FIELD_STR "\001^"
420 #define FIRST_IN_FIELD_CHAR 1
421 #define FIRST_IN_FIELD_LEN 2
422
423 YAZ_END_CDECL
424
425 #endif
426 /*
427  * Local variables:
428  * c-basic-offset: 4
429  * indent-tabs-mode: nil
430  * End:
431  * vim: shiftwidth=4 tabstop=8 expandtab
432  */
433