35 #include <yaz/diagbib1.h>
36 #include <yaz/snprintf.h>
37 #include <yaz/pquery.h>
38 #include <yaz/sortspec.h>
44 #include <yaz/oid_db.h>
46 #define DEFAULT_APPROX_LIMIT 2000000000
49 #define ASSERTZH assert(zh && zh->service)
50 #define ASSERTZHRES assert(zh && zh->service && zh->res)
51 #define ASSERTZS assert(zs)
66 #define ZEBRA_CHECK_HANDLE(zh) if (zebra_check_handle(zh) != ZEBRA_OK) return ZEBRA_FAIL
77 yaz_log(YLOG_DEBUG,
"chdir %s", dir);
84 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"chdir %s", dir);
102 int rw,
int useshadow,
104 const char *reg_path);
116 const char *default_encoding;
119 log_level = yaz_log_module_level(
"zebraapi");
129 yaz_log(YLOG_DEBUG,
"zebra_open zs=%p returns %p", zs, zh);
164 yaz_iconv_open(
"UTF-8", default_encoding);
166 yaz_log(YLOG_WARN,
"iconv: %s to UTF-8 unsupported",
169 yaz_iconv_open(default_encoding,
"UTF-8");
171 yaz_log(YLOG_WARN,
"iconv: UTF-8 to %s unsupported",
200 char version_str[16];
207 log_level = yaz_log_module_level(
"zebraapi");
215 yaz_log(YLOG_LOG,
"zebra_start %s %s", version_str, system_str);
217 yaz_log(YLOG_LOG,
"config %s", configName);
219 yaz_log_xml_errors(0, YLOG_LOG);
221 if ((res =
res_open(def_res, over_res)))
223 const char *passwd_plain = 0;
224 const char *passwd_encrypt = 0;
225 const char *dbaccess = 0;
238 yaz_log(YLOG_FATAL,
"Configuration error(s) for %s",
248 zh = xmalloc(
sizeof(*zh));
263 if (!passwd_plain && !passwd_encrypt)
269 yaz_log(YLOG_WARN|YLOG_ERRNO,
"passwd_db_open failed");
284 yaz_log(YLOG_FATAL,
"Failed to read %s", dbaccess);
289 zh->
timing = yaz_timing_create();
291 zh->
nmem = nmem_create();
296 const char *module_path =
res_get(res,
"modulePath");
307 void(*cb)(
void *cd,
const char *
name))
318 strcat(path,
"zebrasrv.pid");
322 int compact_flag,
Res res)
324 int page_size = 4096;
326 yaz_snprintf(res_str,
sizeof(res_str),
"dict.%s.pagesize",
name);
331 yaz_log(YLOG_LOG,
"Using custom dictionary page size %d for %s",
338 int rw,
int useshadow,
Res res,
339 const char *reg_path)
343 const char *compression_str = 0;
344 const char *profilePath;
350 reg = xmalloc(
sizeof(*reg));
360 yaz_log(YLOG_DEBUG,
"zebra_register_open rw=%d useshadow=%d p=%p n=%s rp=%s",
361 rw, useshadow, reg,
name, reg_path ? reg_path :
"(none)");
429 compression_str =
res_get_def(res,
"recordCompression",
"none");
430 if (!strcmp(compression_str,
"none"))
432 else if (!strcmp(compression_str,
"bzip2"))
434 else if (!strcmp(compression_str,
"zlib"))
438 yaz_log(YLOG_FATAL,
"invalid recordCompression: %s", compression_str);
444 yaz_log(YLOG_FATAL,
"unsupported recordCompression: %s",
450 const char *index_fname =
res_get_def(res,
"index",
"default.idx");
451 if (index_fname && *index_fname && strcmp(index_fname,
"none"))
464 yaz_log(YLOG_WARN,
"rec_open failed");
473 yaz_log(YLOG_WARN,
"dict_open failed");
486 yaz_log(YLOG_WARN,
"bad_value for 'sortindex'");
493 yaz_log(YLOG_WARN,
"zebra_sort_open failed");
502 yaz_log(YLOG_WARN,
"isams_open failed");
512 yaz_log(YLOG_WARN,
"isamc_open failed");
523 yaz_log(YLOG_WARN,
"isamb_open failed");
534 yaz_log(YLOG_WARN,
"isamb_open failed");
545 yaz_log(YLOG_WARN,
"isamb_open failed");
556 yaz_log(YLOG_WARN,
"Cannot obtain EXPLAIN information");
566 yaz_log(YLOG_DEBUG,
"zebra_register_open ok p=%p", reg);
573 yaz_log(
log_level,
"zebra_admin_shutdown");
596 yaz_log(YLOG_DEBUG,
"zebra_register_close p=%p", reg);
642 nmem_destroy(zs->
nmem);
645 yaz_timing_stop(zs->
timing);
646 yaz_log(YLOG_LOG,
"zebra_stop: %4.2f %4.2f %4.2f",
647 yaz_timing_get_real(zs->
timing),
648 yaz_timing_get_user(zs->
timing),
649 yaz_timing_get_sys(zs->
timing));
652 yaz_timing_destroy(&zs->
timing);
669 yaz_log(YLOG_DEBUG,
"zebra_close zh=%p", zh);
736 yaz_snprintf(fname,
sizeof(fname),
"%s/zebra.cfg", zh->
path_reg);
746 yaz_log(YLOG_WARN,
"no register root specified");
767 assert(zh->
reg == 0);
809 const char *lock_area =
res_get(zh->
res,
"lockDir");
813 yaz_snprintf(fname,
sizeof(fname),
"norm.%s.LCK", zh->
reg_name);
817 yaz_snprintf(fname,
sizeof(fname),
"shadow.%s.LCK", zh->
reg_name);
845 yaz_log(YLOG_LOG,
"static rank set and is %d", zh->
m_staticrank);
852 yaz_log(YLOG_DEBUG,
"segment indexing set and is %d",
862 char fromdb[128], todb[8][128];
869 sscanf(value,
"%127s %127s %127s %127s %127s %127s %127s %127s %127s",
870 fromdb, todb[0], todb[1], todb[2], todb[3], todb[4],
871 todb[5], todb[6], todb[7]);
879 for (i = 0; i < no; i++)
884 nmem_strdup(p->
mem, todb[i]);
899 "database", group,
"Default");
923 info.
mem = stream->mem;
936 yaz_log(YLOG_DEBUG,
"base %s", (*
basenames)[i]);
943 yaz_log(
log_level,
"zebra_select_database %s",basename);
959 yaz_log(
log_level,
"zebra_select_databases n=%d [0]=%s",
965 zh->
errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
978 if ((pp = strchr(p,
'+'))) {
984 if (len == strlen(db) && !strncmp(db, p, len))
988 zh->
errCode = YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED;
1007 new_reg = xmalloc(len + 1);
1009 new_reg[len] =
'\0';
1012 new_reg = xstrdup(
"");
1022 zh->
errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
1028 zh->
errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
1036 zh->
errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
1045 zh->
errCode = YAZ_BIB1_DATABASE_UNAVAILABLE;
1050 zh->
errCode = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
1058 if (approx_limit == 0)
1071 int (*f)(
void *client_data),
1080 const char *setname,
zint *hits,
1081 int *estimated_hit_count,
1082 int *partial_resultset)
1101 hits, estimated_hit_count);
1109 const char *setname,
zint *hits)
1111 int estimated_hit_count;
1112 int partial_resultset;
1114 &estimated_hit_count,
1115 &partial_resultset);
1119 const char *setname,
1120 Z_RecordComposition *comp,
1121 const Odr_oid *input_format,
int num_recs,
1135 yaz_log(
log_level,
"zebra_records_retrieve n=%d", num_recs);
1147 pos_array = (
zint *) xmalloc(num_recs *
sizeof(*pos_array));
1148 for (i = 0; i<num_recs; i++)
1149 pos_array[i] = recs[i].position;
1153 yaz_log(YLOG_DEBUG,
"zebraPosSetCreate error");
1160 WRBUF addinfo_w = wrbuf_alloc();
1161 for (i = 0; i < num_recs; i++)
1172 recs[i].
format = yaz_oid_recsyn_sutrs;
1173 recs[i].
len = strlen(poset[i].term);
1175 recs[i].
base = poset[i].
db;
1177 else if (poset[i].sysno)
1189 wrbuf_rewind(addinfo_w);
1192 poset[i].sysno, poset[i].score,
1193 stream, input_format, comp,
1194 &recs[i].format, &buf, &len,
1195 &recs[i].base, addinfo_w);
1197 if (wrbuf_len(addinfo_w))
1199 odr_strdup(stream, wrbuf_cstr(addinfo_w));
1203 recs[i].
buf = (
char*) odr_malloc(stream, len);
1204 memcpy(recs[i].buf, buf, len);
1217 YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE,
1225 wrbuf_destroy(addinfo_w);
1236 const char *setname)
1238 YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
1239 Z_AttributesPlusTerm *zapt;
1240 Odr_oid *attributeSet;
1243 if (!(zapt = yaz_pqf_scan(pqf_parser, stream, &attributeSet, query)))
1246 zh->
errCode = YAZ_BIB1_SCAN_MALFORMED_SCAN;
1250 res =
zebra_scan(
zh, stream, zapt, yaz_oid_attset_bib_1,
1251 position, num_entries, entries, is_partial,
1254 yaz_pqf_destroy(pqf_parser);
1259 const Odr_oid *attributeset,
1263 const char *setname)
1272 assert(num_entries);
1284 res =
rpn_scan(
zh, stream, zapt, attributeset,
1286 num_entries, entries, is_partial, setname);
1292 int num_input_setnames,
const char **input_setnames,
1293 const char *output_setname,
1294 Z_SortKeySpecList *sort_sequence,
1300 assert(num_input_setnames>0);
1301 assert(input_setnames);
1302 assert(sort_sequence);
1303 assert(sort_status);
1308 res =
resultSetSort(
zh, stream->mem, num_input_setnames, input_setnames,
1309 output_setname, sort_sequence, sort_status);
1315 int num_setnames,
char **setnames,
1320 yaz_log(
log_level,
"zebra_deleteResultSet n=%d", num_setnames);
1323 return Z_DeleteStatus_systemProblemAtTarget;
1326 case Z_DeleteResultSetRequest_list:
1327 assert(num_setnames>0);
1331 case Z_DeleteResultSetRequest_all:
1336 status = Z_DeleteStatus_success;
1337 for (i = 0; i<num_setnames; i++)
1338 if (statuses[i] == Z_DeleteStatus_resultSetDidNotExist)
1339 status = statuses[i];
1359 yaz_log(
log_level,
"zebra_errString: %s",e);
1368 yaz_log(
log_level,
"zebra_errAdd: %s",a);
1375 const char *astring;
1383 yaz_snprintf(u,
sizeof(u),
"perm.%s", user ? user :
"anonymous");
1405 const char *record_type)
1407 yaz_log(
log_level,
"zebra_admin_import_begin db=%s rt=%s",
1408 database, record_type);
1417 yaz_log(
log_level,
"zebra_admin_import_end");
1427 yaz_log(
log_level,
"zebra_admin_import_segment");
1429 for (i = 0; i<segment->num_segmentRecords; i++)
1431 Z_NamePlusRecord *npr = segment->segmentRecords[i];
1433 if (npr->which == Z_NamePlusRecord_intermediateFragment)
1435 Z_FragmentSyntax *fragment = npr->u.intermediateFragment;
1436 if (fragment->which == Z_FragmentSyntax_notExternallyTagged)
1438 Odr_oct *oct = fragment->u.notExternallyTagged;
1448 (
const char *) oct->buf, oct->len) ==
ZEBRA_FAIL)
1461 if (*info ==
sizeof(pos))
1463 memcpy(&pos, info+1,
sizeof(pos));
1474 if (*info ==
sizeof(pos))
1477 memcpy(&pos, info+1,
sizeof(pos));
1496 const char *index_type,
const char *string_index,
1503 yaz_log(YLOG_LOG,
"ord=%d index_type=%s index=%s cat=%d", ord,
1504 index_type, string_index, (
int) cat);
1507 ord_buf[ord_len] =
'\0';
1513 !strcmp(string_index,
"_ALLRECORDS") ?
1522 yaz_log(
log_level,
"zebra_drop_database %s", db);
1549 yaz_log(YLOG_WARN,
"drop database only supported for isam:b");
1551 "drop database only supported for isam:b");
1556 yaz_log(YLOG_WARN,
"zebra_end_trans failed");
1564 yaz_log(
log_level,
"zebra_create_database %s", db);
1579 yaz_log(YLOG_WARN,
"zebra_end_trans failed");
1588 const char *input_str,
int input_len,
1589 char *output_str,
int output_len)
1596 yaz_log(
log_level,
"zebra_string_norm ");
1603 if (wrbuf_len(wrbuf) >= output_len)
1605 if (wrbuf_len(wrbuf))
1606 memcpy(output_str, wrbuf_buf(wrbuf), wrbuf_len(wrbuf));
1607 output_str[wrbuf_len(wrbuf)] =
'\0';
1608 return wrbuf_len(wrbuf);
1623 char state_fname[256];
1628 yaz_log(
log_level,
"zebra_set_state v=%c seq=%d", val, seqno);
1630 yaz_snprintf(state_fname,
sizeof(state_fname),
"state.%s.LCK", zh->
reg_name);
1632 f = fopen(fname,
"w");
1635 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"open %s w", state_fname);
1638 yaz_log(YLOG_DEBUG,
"zebra_set_state: %c %d %ld", val, seqno, p);
1639 fprintf(f,
"%c %d %ld\n", val, seqno, p);
1646 char state_fname[256];
1653 yaz_snprintf(state_fname,
sizeof(state_fname),
"state.%s.LCK", zh->
reg_name);
1655 f = fopen(fname,
"r");
1661 if (fscanf(f,
"%c %d", val, seqno) != 2)
1663 yaz_log(YLOG_ERRNO|YLOG_WARN,
"fscan fail %s",
1683 const char *group =
res_get(zh->
res,
"group");
1717 "zebra_begin_trans: no database selected");
1721 yaz_log(
log_level,
"zebra_begin_trans rw=%d",rw);
1729 YAZ_BIB1_ES_PERMISSION_DENIED_ON_ES_CANNOT_MODIFY_OR_DELETE,
1740 const char *rval = 0;
1751 "zebra_begin_trans: no write trans within read");
1767 #if HAVE_SYS_TIMES_H
1790 yaz_log(YLOG_WARN,
"previous transaction did not finish "
1791 "(shadow disabled)");
1816 1, rval ? 1 : 0, zh->
res,
1827 "zebra_begin_trans: cannot open register");
1828 yaz_log(YLOG_FATAL,
"%s", zh->
errString);
1846 #if HAVE_SYS_TIMES_H
1852 zh->
errCode = YAZ_BIB1_DATABASE_UNAVAILABLE;
1858 zh->
errCode = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
1869 yaz_log(YLOG_DEBUG,
"reopen seqno cur/old %d/%d",
1875 yaz_log(YLOG_DEBUG,
"reopen last cur/old %d/%d",
1893 0, val ==
'c' ? 1 : 0,
1900 zh->
errCode = YAZ_BIB1_DATABASE_UNAVAILABLE;
1928 yaz_log(
log_level,
"zebra_end_transaction");
1937 if (!zh->
res || !zh->
reg)
1940 "zebra_end_trans: no open transaction");
1959 yaz_log(YLOG_DEBUG,
"zebra_end_trans");
1995 #if HAVE_SYS_TIMES_H
1997 yaz_log(
log_level,
"user/system: %ld/%ld",
1998 (
long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
1999 (
long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
2001 status->
utime = (long) (zh->tms2.tms_utime - zh->tms1.tms_utime);
2002 status->
stime = (long) (zh->tms2.tms_stime - zh->tms1.tms_stime);
2024 yaz_log(
log_level,
"updating %s", path);
2026 yaz_log(
log_level,
"deleting %s", path);
2028 yaz_log(
log_level,
"attempt deleting %s", path);
2030 yaz_log(
log_level,
"update action=%d", (
int) action);
2042 yaz_log(
log_level,
"zebra_repository_show");
2057 yaz_log(
log_level,
"zebra_commit_ex clean_only=%d", clean_only);
2061 zh->
errCode = YAZ_BIB1_DATABASE_UNAVAILABLE;
2067 yaz_log(YLOG_WARN,
"Cannot perform commit - No shadow area defined");
2086 yaz_log(YLOG_WARN,
"previous transaction didn't reach commit");
2089 else if (val ==
'c')
2125 yaz_log(YLOG_WARN,
"zebra_commit: failed");
2132 yaz_log(
log_level,
"nothing to commit");
2167 "cannot select default database");
2175 zebra_setError(zh, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR,
"bfs_create");
2195 zh->
errCode = YAZ_BIB1_DATABASE_UNAVAILABLE;
2204 #define ZEBRA_CHECK_DICT 1
2205 #define ZEBRA_CHECK_ISAM 2
2208 zint *no_keys,
int message_limit,
2210 zint *no_long_dict_entries,
2211 zint *no_failed_dict_lookups,
2212 zint *no_invalid_keys,
2213 zint *no_invalid_dict_infos,
2214 zint *no_invalid_isam_entries)
2231 NMEM nmem = nmem_create();
2246 (*no_invalid_keys)++;
2247 if (*no_invalid_keys <= message_limit)
2251 ": unexpected key length %d",
2255 if (ord_len + slen >=
sizeof(ord_buf)-1)
2258 (*no_long_dict_entries)++;
2259 if (*no_long_dict_entries <= message_limit)
2264 ": long dictionary entry %d + %d",
2265 rec->
sysno, ord_len, (
int) slen);
2269 memcpy(ord_buf + ord_len, str, slen);
2270 ord_buf[ord_len + slen] =
'\0';
2274 (*no_long_dict_entries)++;
2275 if (*no_long_dict_entries <= message_limit)
2279 ": long dictionary entry %d + %d",
2280 rec->
sysno, (
int) ord_len, (
int) slen);
2289 (*no_failed_dict_lookups)++;
2290 if (*no_failed_dict_lookups <= message_limit)
2294 ": term do not exist in dictionary", rec->
sysno);
2301 if (*info !=
sizeof(pos))
2304 (*no_invalid_dict_infos)++;
2305 if (*no_invalid_dict_infos <= message_limit)
2309 ": long dictionary entry %d + %d",
2310 rec->
sysno, (
int) ord_len, (
int) slen);
2316 memcpy(&pos, info+1,
sizeof(pos));
2324 (*no_invalid_isam_entries)++;
2325 if (*no_invalid_isam_entries <= message_limit)
2345 until_key.
len = key_in.
len - 1;
2346 for (i = 0; i < until_key.
len; i++)
2347 until_key.
mem[i] = key_in.
mem[i+1];
2349 if (until_key.
mem[0] == 0)
2355 (*no_invalid_isam_entries)++;
2356 if (*no_invalid_isam_entries <= message_limit)
2361 " returned no entry",
2371 (*no_invalid_isam_entries)++;
2372 if (*no_invalid_isam_entries
2376 yaz_log(YLOG_WARN,
"Record "
2378 ": isamb_pp_forward "
2380 " returned different entry",
2403 slen, nmem, YLOG_LOG);
2418 if (!spec || *spec ==
'\0'
2419 || !strcmp(spec,
"dict") || !strcmp(spec,
"default"))
2421 else if (!strcmp(spec,
"isam") || !strcmp(spec,
"full"))
2423 else if (!strcmp(spec,
"quick"))
2427 yaz_log(YLOG_WARN,
"Unknown check spec: %s", spec);
2431 yaz_log(YLOG_LOG,
"zebra_register_check begin flags=%u", flags);
2434 zint no_records_total = 0;
2435 zint no_records_fail = 0;
2436 zint total_keys = 0;
2443 zint no_long_dict_entries = 0;
2444 zint no_failed_dict_lookups = 0;
2445 zint no_invalid_keys = 0;
2446 zint no_invalid_dict_infos = 0;
2447 zint no_invalid_isam_entries = 0;
2457 &no_long_dict_entries,
2458 &no_failed_dict_lookups,
2460 &no_invalid_dict_infos,
2461 &no_invalid_isam_entries
2473 total_keys += no_keys;
2481 yaz_log(YLOG_LOG,
"long dict entries: " ZINT_FORMAT,
2482 no_long_dict_entries);
2485 yaz_log(YLOG_LOG,
"failed dict lookups: " ZINT_FORMAT,
2486 no_failed_dict_lookups);
2487 yaz_log(YLOG_LOG,
"invalid dict infos: " ZINT_FORMAT,
2488 no_invalid_dict_infos);
2491 yaz_log(YLOG_LOG,
"invalid isam entries: " ZINT_FORMAT,
2492 no_invalid_isam_entries);
2496 yaz_log(YLOG_LOG,
"zebra_register_check end ret=%d", res);
2510 *code = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
2511 *addinfo =
"ZebraHandle is NULL";
2518 yaz_log(
log_level,
"zebra_shadow_enable");
2524 yaz_log(
log_level,
"zebra_octet_term_encoding %s", encoding);
2534 yaz_iconv_open(
"UTF-8", encoding);
2536 yaz_log(YLOG_WARN,
"iconv: %s to UTF-8 unsupported", encoding);
2538 yaz_iconv_open(encoding,
"UTF-8");
2540 yaz_log(YLOG_WARN,
"iconv: UTF-8 to %s unsupported", encoding);
2547 yaz_log(
log_level,
"zebra_record_encoding");
2560 yaz_log(
log_level,
"zebra_set_resource %s:%s", name, value);
2566 const char *name,
const char *defaultvalue)
2572 yaz_log(
log_level,
"zebra_get_resource %s:%s", name, v);
2588 yaz_log(
log_level,
"zebra_get_shadow_enable");
2595 yaz_log(
log_level,
"zebra_set_shadow_enable %d",value);
2601 const char *buf,
int buf_size)
2613 const char *recordType,
2614 zint *sysno,
const char *match,
2616 const char *buf,
int buf_size)
2624 yaz_log(
log_level,
"zebra_update_record");
2629 buf_size = strlen(buf);
2641 yaz_log(YLOG_WARN,
"zebra_end_trans failed");
2652 const char *setname,
zint *hits)
2662 odr = odr_createmem(ODR_ENCODE);
2667 yaz_log(
log_level,
"zebra_search_PQF s=%s q=%s", setname, pqf_query);
2669 query = p_query_rpn(odr, pqf_query);
2673 yaz_log(YLOG_WARN,
"bad query %s\n", pqf_query);
2674 zh->
errCode = YAZ_BIB1_MALFORMED_QUERY;
2694 const char *sort_spec,
2695 const char *output_setname,
2696 const char **input_setnames)
2698 int num_input_setnames = 0;
2699 int sort_status = 0;
2700 Z_SortKeySpecList *sort_sequence;
2705 assert(output_setname);
2706 assert(input_setnames);
2707 sort_sequence = yaz_sort_spec(stream, sort_spec);
2711 yaz_log(YLOG_WARN,
"invalid sort specs '%s'", sort_spec);
2712 zh->
errCode = YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE;
2718 while (input_setnames[num_input_setnames]) num_input_setnames++;
2723 resultSetSort(zh, stream->mem, num_input_setnames, input_setnames,
2724 output_setname, sort_sequence, &sort_status);
2776 const char *lock_dir =
res_get_def(res,
"lockDir",
"");
2778 strcpy(path, lock_dir);
2779 if (*path && path[strlen(path)-1] !=
'/')
struct zebra_session * ZebraHandle
a Zebra Handle - (session)
ZebraMetaRecord * zebra_meta_records_create(ZebraHandle zh, const char *name, int num, zint *positions)
void zebra_meta_records_destroy(ZebraHandle zh, ZebraMetaRecord *records, int num)
ZEBRA_RES bf_cache(BFiles bfs, const char *spec)
enables or disables shadow for block files
int bf_commitExec(BFiles bfs) ZEBRA_GCC_ATTR((warn_unused_result))
Executes commit operation.
void bf_reset(BFiles bfs)
Removes register and shadow completely.
void bf_commitClean(BFiles bfs, const char *spec)
Cleans shadow files (remove them)
BFiles bfs_create(const char *spec, const char *base)
creates a Block files collection
void bfs_destroy(BFiles bfiles)
destroys a block files handle
int bf_commitExists(BFiles bfs)
Check if there is content in shadow area (to be committed).
int zebra_check_res(Res res)
void inv_compact(BFiles bfs)
void data1_set_tabroot(data1_handle dp, const char *p)
data1_handle data1_create(void)
void data1_set_tabpath(data1_handle dh, const char *path)
void data1_destroy(data1_handle dh)
char * dict_lookup(Dict dict, const char *p)
lookup item in dictionary
Dict dict_open(BFiles bfs, const char *name, int cache, int rw, int compact_flag, int page_size)
open dictionary
int dict_delete_subtree(Dict dict, const char *p, void *client, int(*f)(const char *info, void *client))
delete items with a given prefix from dictionary
int dict_close(Dict dict)
closes dictionary
ZebraLockHandle zebra_lock_create(const char *dir, const char *file)
void zebra_flock_init(void)
int zebra_lock_r(ZebraLockHandle h)
int zebra_lock_w(ZebraLockHandle h)
void zebra_lock_destroy(ZebraLockHandle h)
char * zebra_mk_fname(const char *dir, const char *name)
int zebra_unlock(ZebraLockHandle h)
int zebra_record_fetch(ZebraHandle zh, const char *setname, zint sysno, int score, ODR stream, const Odr_oid *input_format, Z_RecordComposition *comp, const Odr_oid **output_format, char **rec_bufp, int *rec_lenp, char **basenamep, WRBUF addinfo_w)
ISAMS_M * key_isams_m(Res res, ISAMS_M *me)
void resultSetDestroy(ZebraHandle zh, int num_names, char **names, int *statuses)
ZEBRA_RES zebra_remove_file_match(ZebraHandle zh)
ZEBRA_RES zebra_update_file_match(ZebraHandle zh, const char *path)
ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path, enum zebra_recctrl_action_t action)
ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, const Odr_oid *attributeset, int num_bases, char **basenames, int *position, int *num_entries, ZebraScanEntry **list, int *is_partial, const char *set_name)
ZEBRA_RES resultSetSort(ZebraHandle zh, NMEM nmem, int num_input_setnames, const char **input_setnames, const char *output_setname, Z_SortKeySpecList *sort_sequence, int *sort_status)
ISAMC_M * key_isamc_m(Res res, ISAMC_M *me)
void zebra_index_merge(ZebraHandle zh)
ZEBRA_RES resultSetAddRPN(ZebraHandle zh, NMEM m, Z_RPNQuery *rpn, int num_bases, char **basenames, const char *setname, zint *hits, int *estimated_hit_count)
void resultSetInvalidate(ZebraHandle zh)
void zebra_limit_destroy(struct zebra_limit *zl)
void repositoryShow(ZebraHandle zh, const char *path)
ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname, zint sysno, zebra_snippets *snippets)
struct zebra_limit * zebra_limit_create(int exclude_flag, zint *ids)
ISAMB_PP isamb_pp_open(ISAMB isamb, ISAM_P pos, int scope)
ISAMB isamb_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method, int cache)
void isamb_close(ISAMB isamb)
int isamb_pp_forward(ISAMB_PP pp, void *buf, const void *untilbuf)
void isamb_pp_close(ISAMB_PP pp)
int isamb_unlink(ISAMB b, ISAM_P pos)
int isamb_pp_read(ISAMB_PP pp, void *buf)
ISAMC isamc_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method)
int isamc_close(ISAMC is)
int isams_close(ISAMS is)
ISAMS isams_open(BFiles bfs, const char *name, int writeflag, ISAMS_M *method)
int key_compare(const void *p1, const void *p2)
void key_logdump_txt(int logmask, const void *p, const char *txt)
int key_SU_encode(int ch, char *out)
void key_block_flush(zebra_key_block_t p, int is_final)
void key_block_destroy(zebra_key_block_t *pp)
int dict_delete_subtree_ord(Dict d, int ord, void *client, int(*f)(const char *info, void *client))
void passwd_db_close(Passwd_db db)
Passwd_db passwd_db_open(void)
int passwd_db_auth(Passwd_db db, const char *user, const char *pass)
int passwd_db_file_plain(Passwd_db db, const char *fname)
int passwd_db_file_crypt(Passwd_db db, const char *fname)
void zebraRankInstall(struct zebra_register *reg, struct rank_control *ctrl)
void zebraRankDestroy(struct zebra_register *reg)
struct rank_control * rank_static_class
struct rank_control * rank_similarity_class
struct rank_control * rank_2_class
struct rank_control * rank_1_class
void recTypeClass_load_modules(RecTypeClass *rts, NMEM nmem, const char *module_path)
void recTypeClass_destroy(RecTypeClass rtc)
RecTypeClass recTypeClass_create(Res res, NMEM nmem)
void recTypes_destroy(RecTypes recTypes)
void recTypeClass_info(RecTypeClass rtc, void *cd, void(*cb)(void *cd, const char *s))
RecTypes recTypes_init(RecTypeClass rtc, data1_handle dh)
ZEBRA_RES rec_close(Records *p)
Records rec_open(BFiles bfs, int rw, int compression_method)
opens records system
Record rec_get(Records p, zint sysno)
gets record - with given system number
#define REC_COMPRESS_BZIP2
BZIP2 compression (slow and requires big chunks)
#define REC_COMPRESS_ZLIB
zlib compression (faster and works off small chunks)
void rec_free(Record *recpp)
frees record (from memory)
Record rec_get_next(Records p, Record rec)
gets next record - with given records
#define REC_COMPRESS_NONE
No compression ("none")
ZEBRA_RES rec_del(Records p, Record *recpp)
marks record for deletion (on file storage)
int rec_check_compression_method(int compression_method)
check whether a compression method is supported
Record rec_get_root(Records p)
gets root record
int zebra_rec_keys_read(zebra_rec_keys_t keys, const char **str, size_t *slen, struct it_key *key)
int zebra_rec_keys_rewind(zebra_rec_keys_t keys)
zebra_rec_keys_t zebra_rec_keys_open(void)
void zebra_rec_keys_set_buf(zebra_rec_keys_t p, char *buf, size_t sz, int copy_buf)
void zebra_rec_keys_close(zebra_rec_keys_t p)
void res_set(Res r, const char *name, const char *value)
ZEBRA_RES res_read_file(Res r, const char *fname)
Res res_open(Res res_def, Res over_res)
int res_get_match(Res r, const char *name, const char *value, const char *s)
const char * res_get_prefix(Res r, const char *name, const char *prefix, const char *def)
const char * res_get(Res r, const char *name)
const char * res_get_def(Res r, const char *name, const char *def)
ZEBRA_RES res_get_int(Res r, const char *name, int *val)
int res_trav(Res r, const char *prefix, void *p, void(*f)(void *p, const char *name, const char *value))
void zebra_snippets_destroy(zebra_snippets *l)
zebra_snippets * zebra_snippets_create(void)
void zebra_sort_close(zebra_sort_index_t si)
frees sort handle
#define ZEBRA_SORT_TYPE_ISAMB
zebra_sort_index_t zebra_sort_open(BFiles bfs, int write_flag, int sort_type)
creates sort handle
#define ZEBRA_SORT_TYPE_FLAT
#define ZEBRA_SORT_TYPE_MULTI
zint mem[IT_KEY_LEVEL_MAX]
zebra_rec_keys_t sortKeys
zebra_key_block_t key_block
ZebraRankClass rank_classes
zebra_sort_index_t sort_index
Zebra_mutex_cond session_lock
struct zebra_session * sessions
RecTypeClass record_classes
struct zebra_session * next
struct zebra_register * reg
struct zebra_service * service
const char * m_record_type
ZebraLockHandle lock_shadow
void * break_handler_data
ZebraLockHandle lock_normal
struct zebra_limit * m_limit
int(* break_handler_func)(void *client_data)
yaz_iconv_t iconv_from_utf8
yaz_iconv_t iconv_to_utf8
#define CAST_ZINT_TO_INT(x)
short ZEBRA_RES
Common return type for Zebra API.
void zebra_get_version(char *version_str, char *sha1_str)
Returns Zebra version and SHA1 ID as generated by Git.
int zebra_mutex_cond_init(Zebra_mutex_cond *p)
int zebra_mutex_cond_lock(Zebra_mutex_cond *p)
int zebra_mutex_cond_unlock(Zebra_mutex_cond *p)
int zebra_mutex_cond_destroy(Zebra_mutex_cond *p)
ZEBRA_RES zebra_compact(ZebraHandle zh)
ZEBRA_RES zebra_init(ZebraHandle zh)
ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query, int *position, int *num_entries, ZebraScanEntry **entries, int *is_partial, const char *setname)
performs Scan (taking PQF string)
ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh)
int zebra_get_shadow_enable(ZebraHandle zh)
#define ZEBRA_CHECK_HANDLE(zh)
ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query, const char *setname, zint *hits)
Search using PQF Query String.
ZEBRA_RES zebra_close(ZebraHandle zh)
Destroys Zebra session handle.
Dict dict_open_res(BFiles bfs, const char *name, int cache, int rw, int compact_flag, Res res)
static void zebra_get_state(ZebraHandle zh, char *val, int *seqno)
ZEBRA_RES zebra_repository_delete(ZebraHandle zh, const char *path)
void map_basenames_func(void *vp, const char *name, const char *value)
ZEBRA_RES zebra_admin_start(ZebraHandle zh)
struct BFiles_struct * zebra_get_bfs(ZebraHandle zh)
ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh, Z_Segment *segment)
int delete_w_all_handle(const char *info, void *handle)
ZEBRA_RES zebra_end_read(ZebraHandle zh)
ZEBRA_RES zebra_register_check(ZebraHandle zh, const char *spec)
const char * zebra_get_resource(ZebraHandle zh, const char *name, const char *defaultvalue)
ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db)
Deletes a database (drop)
ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding)
ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream, const char *setname, Z_RecordComposition *comp, const Odr_oid *input_format, int num_recs, ZebraRetrievalRecord *recs)
Retrieve records from result set (after search)
static ZEBRA_RES zebra_commit_ex(ZebraHandle zh, int clean_only)
void zebra_set_partial_result(ZebraHandle zh)
ZebraService zebra_start_res(const char *configName, Res def_res, Res over_res)
Creates a Zebra service with resources.
void zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream, int num_input_setnames, const char **input_setnames, const char *output_setname, Z_SortKeySpecList *sort_sequence, int *sort_status)
static void zebra_register_close(ZebraService zs, struct zebra_register *reg)
ZEBRA_RES zebra_add_record(ZebraHandle zh, const char *buf, int buf_size)
Simple update record.
ZebraService zebra_start(const char *configName)
Creates a Zebra Service.
ZEBRA_RES zebra_clean(ZebraHandle zh)
static void zebra_close_res(ZebraHandle zh)
ZEBRA_RES zebra_update_record(ZebraHandle zh, enum zebra_recctrl_action_t action, const char *recordType, zint *sysno, const char *match, const char *fname, const char *buf, int buf_size)
Updates record.
static int delete_SU_handle(void *handle, int ord, const char *index_type, const char *string_index, zinfo_index_category_t cat)
static struct zebra_register * zebra_register_open(ZebraService zs, const char *name, int rw, int useshadow, Res res, const char *reg_path)
ZEBRA_RES zebra_end_trans(ZebraHandle zh)
ZEBRA_RES zebra_commit(ZebraHandle zh)
ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename)
ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db)
Creates a database.
ZEBRA_RES zebra_repository_update(ZebraHandle zh, const char *path)
static ZEBRA_RES zebra_flush_reg(ZebraHandle zh)
void zebra_setError(ZebraHandle zh, int code, const char *addinfo)
void zebra_setError_zint(ZebraHandle zh, int code, zint i)
int zebra_string_norm(ZebraHandle zh, const char *index_type, const char *input_str, int input_len, char *output_str, int output_len)
Normalize zebra term for register (subject to change!)
ZEBRA_RES zebra_begin_read(ZebraHandle zh)
ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding)
int zebra_errCode(ZebraHandle zh)
Returns error code for last error.
void zebra_result(ZebraHandle zh, int *code, char **addinfo)
Returns error code and additional info for last error.
int zebra_deleteResultSet(ZebraHandle zh, int function, int num_setnames, char **setnames, int *statuses)
Deletes one or more resultsets.
const char * zebra_errString(ZebraHandle zh)
Returns error string for last error.
static int zebra_chdir(ZebraService zs)
static void zebra_select_register(ZebraHandle zh, const char *new_reg)
ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass)
authenticate user. Returns 0 if OK, != 0 on failure
ZEBRA_RES zebra_set_break_handler(ZebraHandle zh, int(*f)(void *client_data), void *client_data)
int delete_w_handle(const char *info, void *handle)
ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit)
Set limit before Zebra does approx hit count.
void zebra_lock_prefix(Res res, char *path)
static ZEBRA_RES zebra_record_check(ZebraHandle zh, Record rec, zint *no_keys, int message_limit, unsigned flags, zint *no_long_dict_entries, zint *no_failed_dict_lookups, zint *no_invalid_keys, zint *no_invalid_dict_infos, zint *no_invalid_isam_entries)
ZEBRA_RES zebra_repository_index(ZebraHandle zh, const char *path, enum zebra_recctrl_action_t action)
ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw)
ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query, const char *setname, zint *hits)
Search using RPN Query structure (from ASN.1)
ZEBRA_RES zebra_stop(ZebraService zs)
stops a Zebra service.
#define DEFAULT_APPROX_LIMIT
ZEBRA_RES zebra_admin_import_end(ZebraHandle zh)
ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database, const char *record_type)
ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases, const char **basenames)
const char * zebra_get_encoding(ZebraHandle zh)
Returns character set encoding for session.
static void zebra_open_res(ZebraHandle zh)
int zebra_select_default_database(ZebraHandle zh)
static void read_res_for_transaction(ZebraHandle zh)
ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, const Odr_oid *attributeset, int *position, int *num_entries, ZebraScanEntry **entries, int *is_partial, const char *setname)
performs Scan (Z39.50 style)
static void zebra_set_state(ZebraHandle zh, int val, int seqno)
set register state (state*.LCK)
ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids)
ZebraHandle zebra_open(ZebraService zs, Res res)
Creates a Zebra session handle within service.
void zebra_filter_info(ZebraService zs, void *cd, void(*cb)(void *cd, const char *name))
Lists enabled Zebra filters.
static int log_level_initialized
static ZEBRA_RES zebra_check_handle(ZebraHandle zh)
ZEBRA_RES zebra_search_RPN_x(ZebraHandle zh, ODR o, Z_RPNQuery *query, const char *setname, zint *hits, int *estimated_hit_count, int *partial_resultset)
Search using RPN Query structure (from ASN.1)
char * zebra_errAdd(ZebraHandle zh)
Returns additional info for last error.
int zebra_sort_by_specstr(ZebraHandle zh, ODR stream, const char *sort_spec, const char *output_setname, const char **input_setnames)
void zebra_set_shadow_enable(ZebraHandle zh, int value)
void map_basenames(ZebraHandle zh, ODR stream, int *num_bases, char ***basenames)
int zebra_trans_no(ZebraHandle zh)
ZEBRA_RES zebra_end_transaction(ZebraHandle zh, ZebraTransactionStatus *status)
void zebra_shadow_enable(ZebraHandle zh, int value)
ZEBRA_RES zebra_repository_show(ZebraHandle zh, const char *path)
void zebra_pidfname(ZebraService zs, char *path)
zebra_map_t zebra_map_get(zebra_maps_t zms, const char *id)
void zebra_maps_define_default_sort(zebra_maps_t zms)
void zebra_maps_close(zebra_maps_t zm)
ZEBRA_RES zebra_maps_read_file(zebra_maps_t zms, const char *fname)
WRBUF zebra_replace(zebra_map_t zm, const char *ex_list, const char *input_str, int input_len)
zebra_maps_t zebra_maps_open(Res res, const char *base_path, const char *profile_path)
int zebraExplain_curDatabase(ZebraExplainInfo zei, const char *database)
ZebraExplainInfo zebraExplain_open(Records records, data1_handle dh, Res res, int writeFlag, void *updateHandle, ZebraExplainUpdateFunc *updateFunc)
int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle, int(*f)(void *handle, int ord, const char *index_type, const char *string_index, zinfo_index_category_t cat))
zint zebraExplain_runNumberIncrement(ZebraExplainInfo zei, int adjust_num)
int zebraExplain_get_database_ord(ZebraExplainInfo zei)
void zebraExplain_close(ZebraExplainInfo zei)
int zebraExplain_removeDatabase(ZebraExplainInfo zei, void *update_handle)
int zebraExplain_newDatabase(ZebraExplainInfo zei, const char *database, int explain_database)
void zebraExplain_flush(ZebraExplainInfo zei, void *handle)