43 #include <yaz/snprintf.h>
69 WRBUF w = wrbuf_alloc();
70 for (i = 0; cstr[i]; i++)
72 if (cstr[i] <
' ' || cstr[i] > 126)
73 wrbuf_printf(w,
"\\%02X", cstr[i] & 0xff);
75 wrbuf_putc(w, cstr[i]);
90 yaz_log(YLOG_LOG,
"More than %d file log entries. Omitting rest (-fn to see more)",
116 const char *str,
int length);
140 const char **map = 0;
147 while (map && *map && **map == *
CHR_SPACE)
153 int first = i ? 0 : 1;
164 while (map && *map && **map != *
CHR_SPACE)
166 const char *cp = *map;
213 const char **map = 0;
214 const char *start = b;
215 const char *last = b;
225 while (map && *map && **map == *
CHR_SPACE)
239 start, last - start);
242 while (map && *map && **map != *
CHR_SPACE)
265 start, last - start);
276 const char *res_buf = 0;
279 const char *display_buf = 0;
280 size_t display_len = 0;
284 &display_buf, &display_len))
288 display_buf, display_len);
325 RecType rt,
void *recTypeClientData)
330 extractCtrl.
stream = stream;
342 extractCtrl.
handle = &info;
351 (*rt->
extract)(recTypeClientData, &extractCtrl);
356 const char *index_name,
357 const char **ws,
int ws_length)
363 for (i = 0; i<ws_length; i++)
387 seqno = key.
mem[key.
len-1];
389 if (key.
mem[0] == ch)
395 woff = seqno - startSeq;
396 if (woff >= 0 && woff < ws_length)
403 #define FILE_MATCH_BLANK "\t "
407 const char *fname,
const char *spec)
409 static char dstBuf[2048];
411 const char *s = spec;
422 char attset_str[64], attname_str[64];
428 for (i = 0; *s && *s !=
',' && *s !=
')' &&
430 if (i+1 <
sizeof(attset_str))
431 attset_str[i++] = *s;
432 attset_str[i] =
'\0';
437 strcpy(attname_str, attset_str);
442 for (i = 0; *s && *s !=
')' &&
444 if (i+1 <
sizeof(attname_str))
445 attname_str[i++] = *s;
446 attname_str[i] =
'\0';
450 yaz_log(YLOG_WARN,
"Missing ) in match criteria %s in group %s",
459 for (i = 0; i<32; i++)
464 yaz_log(YLOG_LOG,
"ws[%d] = %s", i, wrbuf_cstr(w));
470 for (i = 0; i<32; i++)
479 dst += strlen(ws[i]);
483 yaz_log(YLOG_WARN,
"Record didn't contain match"
484 " fields in (%s,%s)", attset_str, attname_str);
492 const char *spec_src = NULL;
493 const char *s1 = ++s;
498 if (spec_len >
sizeof(special)-1)
499 spec_len =
sizeof(special)-1;
500 memcpy(special, s, spec_len);
501 special[spec_len] =
'\0';
504 if (!strcmp(special,
"group"))
506 else if (!strcmp(special,
"database"))
508 else if (!strcmp(special,
"filename")) {
511 else if (!strcmp(special,
"type"))
517 strcpy(dst, spec_src);
518 dst += strlen(spec_src);
521 else if (*s ==
'\"' || *s ==
'\'')
523 int stopMarker = *s++;
527 while (*s && *s != stopMarker)
529 if (i+1 <
sizeof(tmpString))
530 tmpString[i++] = *s++;
535 strcpy(dst, tmpString);
536 dst += strlen(tmpString);
540 yaz_log(YLOG_WARN,
"Syntax error in match criteria %s in group %s",
548 yaz_log(YLOG_WARN,
"No match criteria for record %s in group %s",
557 yaz_log(YLOG_LOG,
"get_match_from_spec %s", wrbuf_cstr(w));
601 const char *recordType,
603 const char *match_criteria,
606 void *recTypeClientData);
617 const char *original_record_type = 0;
619 void *recTypeClientData;
627 yaz_snprintf(gprefix,
sizeof(gprefix),
"%s.", zh->
m_group);
633 for (i = strlen(fname); --i >= 0; )
636 else if (fname[i] ==
'.')
638 strcpy(ext, fname+i+1);
645 yaz_snprintf(ext_res,
sizeof(ext_res),
"%srecordType.%s", gprefix, ext);
653 yaz_log(YLOG_LOG,
"? %s", fname);
660 yaz_snprintf(ext_res,
sizeof(ext_res),
"%srecordId.%s", gprefix, ext);
666 &recTypeClientData)))
668 yaz_log(YLOG_WARN,
"No such record type: %s", zh->
m_record_type);
677 yaz_log(YLOG_WARN,
"Bad filter version: %s", zh->
m_record_type);
687 if (zh->
path_reg && !yaz_is_abspath(fname))
690 strcat(full_rep,
"/");
691 strcat(full_rep, fname);
694 strcpy(full_rep, fname);
696 if ((
fd = open(full_rep,
O_BINARY|O_RDONLY)) == -1)
698 yaz_log(YLOG_WARN|YLOG_ERRNO,
"open %s", full_rep);
726 const char *buf,
size_t buf_size,
728 const char *recordType,
730 const char *match_criteria,
738 if (recordType && *recordType)
741 "Record type explicitly specified: %s", recordType);
749 yaz_log(YLOG_WARN,
"No such record type defined");
761 yaz_log(YLOG_WARN,
"No such record type: %s", recordType);
781 const char *recordType,
783 const char *match_criteria,
786 void *recTypeClientData,
794 const char *matchStr = 0;
796 off_t start_offset = 0, end_offset = 0;
797 const char *pr_fname = fname;
804 pr_fname =
"<no file>";
818 off_t null_offset = 0;
853 yaz_log(YLOG_WARN,
"extract error: generic");
857 yaz_log(YLOG_WARN,
"extract error: no such filter");
862 recordType, pr_fname, (
zint) start_offset);
873 yaz_log(YLOG_WARN,
"extract error: unknown error: %d", r);
890 yaz_log(YLOG_LOG,
"test %s %s " ZINT_FORMAT, recordType,
891 pr_fname, (
zint) start_offset);
910 yaz_log(YLOG_LOG,
"error %s %s " ZINT_FORMAT, recordType,
911 pr_fname, (
zint) start_offset);
916 WRBUF w = wrbuf_alloc();
918 for (i = 0; i < strlen(matchStr); i++)
920 wrbuf_printf(w,
"%02X", matchStr[i] & 0xff);
922 yaz_log(YLOG_LOG,
"Got match %s", wrbuf_cstr(w));
942 assert(*rinfo ==
sizeof(*sysno));
943 memcpy(sysno, rinfo+1,
sizeof(*sysno));
953 yaz_log(YLOG_LOG,
"delete %s %s " ZINT_FORMAT, recordType,
954 pr_fname, (
zint) start_offset);
955 yaz_log(YLOG_WARN,
"cannot delete record above (seems new)");
961 yaz_log(YLOG_LOG,
"adelete %s %s " ZINT_FORMAT, recordType,
962 pr_fname, (
zint) start_offset);
967 yaz_log(YLOG_LOG,
"update %s %s " ZINT_FORMAT, recordType,
968 pr_fname, (
zint) start_offset);
969 yaz_log(YLOG_WARN,
"cannot update record above (seems new)");
973 yaz_log(YLOG_LOG,
"add %s %s " ZINT_FORMAT, recordType, pr_fname,
974 (
zint) start_offset);
991 yaz_log(YLOG_WARN,
"Negative staticrank for record. Set to 0");
999 sizeof(*sysno), sysno);
1017 recordType, pr_fname, (
zint) start_offset);
1055 yaz_log(YLOG_LOG,
"delete %s %s " ZINT_FORMAT, recordType,
1056 pr_fname, (
zint) start_offset);
1057 yaz_log(YLOG_WARN,
"cannot delete file above, "
1058 "storeKeys false (3)");
1063 yaz_log(YLOG_LOG,
"delete %s %s " ZINT_FORMAT, recordType,
1064 pr_fname, (
zint) start_offset);
1082 yaz_log(YLOG_LOG,
"update %s %s " ZINT_FORMAT, recordType,
1083 pr_fname, (
zint) start_offset);
1127 recordAttr->
recordSize = end_offset - start_offset;
1193 const char *recordType,
1198 void *recTypeClientData)
1210 recType, recTypeClientData, &more);
1271 zh->
reg->
keys, 0, delkeys, 0);
1300 const char *str,
size_t slen, NMEM nmem,
int level)
1302 WRBUF w = wrbuf_alloc();
1304 const char *index_type;
1306 const char *string_index;
1311 for (i = 0; i < key->
len; i++)
1319 WRBUF w1 = wrbuf_alloc();
1321 if (!strcmp(str,
""))
1322 wrbuf_puts(w1,
"alwaysmatches");
1324 wrbuf_puts(w1,
"firstinfield");
1326 wrbuf_puts(w1,
"unknown");
1328 wrbuf_puts(w1,
"space");
1330 wrbuf_puts(w1,
"?");
1332 for (i = 0; i<slen; i++)
1334 wrbuf_printf(w1,
" %d", str[i] & 0xff);
1336 yaz_log(level,
"%s%s %s %s", wrbuf_cstr(w), index_type,
1337 string_index, wrbuf_cstr(w1));
1345 yaz_log(level,
"%s%s %s \"%s\"", wrbuf_cstr(w), index_type,
1346 string_index, dst_term);
1349 WRBUF w1 = wrbuf_alloc();
1350 wrbuf_write_escaped(w1, str, strlen(str));
1351 yaz_log(level,
"%s%s %s %s", wrbuf_cstr(w), index_type,
1352 string_index, wrbuf_cstr(w1));
1368 NMEM nmem = nmem_create();
1386 struct ord_stat *next;
1408 p = xmalloc(
sizeof(*p));
1419 struct ord_stat *p1 = p;
1442 size_t mem = 1024*1024 * atol(
res_get_def(zh->
res,
"memmax",
"8"));
1443 const char *key_tmp_dir =
res_get_def(zh->
res,
"keyTmpDir",
".");
1466 const char *del_str;
1467 struct it_key del_key_in;
1471 const char *ins_str;
1472 struct it_key ins_key_in;
1482 if (del && ins && ins_rank == del_rank
1484 && ins_slen == del_slen && !memcmp(del_str, ins_str, del_slen))
1495 &del_key_in, 0, del_str, del_slen,
1499 &ins_key_in, 1, ins_str, ins_slen,
1509 NMEM nmem = nmem_create();
1520 const char *index_type;
1523 seqno = key.
mem[key.
len-1];
1541 yaz_log(YLOG_LOG,
"print_rec_keys");
1551 const char *index_type;
1558 seqno = key.
mem[key.
len-1];
1563 " term=%s", ord, seqno, dst_buf);
1569 const char *str,
int length)
1585 if (zh->m_segment_indexing)
1613 const char *str,
int length)
1618 if (length >
sizeof(valz)-1)
1619 length =
sizeof(valz)-1;
1621 memcpy(valz, str, length);
1622 valz[length] =
'\0';
1627 const char *
string,
int length)
1636 WRBUF w = wrbuf_alloc();
1638 wrbuf_write_escaped(w,
string, length);
1649 memcpy(&word, p,
sizeof(word));
1671 const char **map = 0;
1682 while (map && *map && **map == *
CHR_SPACE)
1693 while (map && *map && **map != *
CHR_SPACE)
1695 const char *cp = *map;
1735 const char *res_buf = 0;
1743 yaz_log(YLOG_LOG,
"Truncating long term %ld", (
long) res_len);
1793 void *buf,
size_t sz)
1827 yaz_log(YLOG_LOG,
"extract_flush_sort_keys cmd=%d sysno=" ZINT_FORMAT,
1839 NMEM nmem = nmem_create();
1840 struct sort_add_ent {
1843 struct sort_add_ent *next;
1848 struct sort_add_ent *sort_ent_list = 0;
1853 zint filter_sysno = key_in.
mem[1];
1854 zint section_id = key_in.
mem[2];
1856 struct sort_add_ent **e = &sort_ent_list;
1857 for (; *e; e = &(*e)->next)
1858 if ((*e)->ord == ord && section_id == (*e)->section_id)
1862 *e = nmem_malloc(nmem,
sizeof(**e));
1864 (*e)->wrbuf = wrbuf_alloc();
1867 (*e)->sysno = filter_sysno ? filter_sysno : sysno;
1868 (*e)->section_id = section_id;
1871 wrbuf_write((*e)->wrbuf, str, slen);
1872 wrbuf_putc((*e)->wrbuf,
'\0');
1876 zint last_sysno = 0;
1877 struct sort_add_ent *e = sort_ent_list;
1878 for (; e; e = e->next)
1880 if (last_sysno != e->sysno)
1883 last_sysno = e->sysno;
1890 wrbuf_destroy(e->wrbuf);
struct zebra_session * ZebraHandle
a Zebra Handle - (session)
int zebra_term_untrans(ZebraHandle zh, const char *index_type, char *dst, const char *src)
void zebra_create_stream_fd(struct ZebraRecStream *stream, int fd, off_t start_offset)
#define FIRST_IN_FIELD_STR
void zebra_create_stream_mem(struct ZebraRecStream *stream, const char *buf, size_t sz)
#define FIRST_IN_FIELD_LEN
int zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream, const char *index_type, char **dst, const char *src)
int key_compare(const void *p1, const void *p2)
zebra_key_block_t key_block_create(size_t mem, const char *key_tmp_dir, int use_threads)
void key_block_write(zebra_key_block_t p, zint sysno, struct it_key *key_in, int cmd, const char *str_buf, size_t str_len, zint staticrank, int static_rank_enable)
char * dict_lookup_ord(Dict d, int ord, const char *str)
int dict_insert_ord(Dict d, int ord, const char *p, int userlen, void *userinfo)
int dict_delete_ord(Dict d, int ord, const char *p)
#define RECCTRL_EXTRACT_EOF
#define RECCTRL_EXTRACT_ERROR_GENERIC
#define RECCTRL_EXTRACT_OK
RecType recType_byName(RecTypes rts, Res res, const char *name, void **clientDataP)
#define RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER
#define RECCTRL_EXTRACT_SKIP
int grs_extract_tree(struct recExtractCtrl *p, data1_node *n)
Record rec_new(Records p)
creates new record (to be written to file storage)
Record rec_get(Records p, zint sysno)
gets record - with given system number
ZEBRA_RES rec_put(Records p, Record *recpp)
puts record (writes into file storage)
char * rec_strdup(const char *s, size_t *len)
void rec_free(Record *recpp)
frees record (from memory)
ZEBRA_RES rec_del(Records p, Record *recpp)
marks record for deletion (on file storage)
int zebra_rec_keys_empty(zebra_rec_keys_t keys)
int zebra_rec_keys_read(zebra_rec_keys_t keys, const char **str, size_t *slen, struct it_key *key)
void zebra_rec_keys_reset(zebra_rec_keys_t keys)
void zebra_rec_keys_get_buf(zebra_rec_keys_t p, char **buf, size_t *sz)
int zebra_rec_keys_rewind(zebra_rec_keys_t keys)
zint zebra_rec_keys_get_custom_record_id(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_write(zebra_rec_keys_t keys, const char *str, size_t slen, const struct it_key *key)
void zebra_rec_keys_close(zebra_rec_keys_t p)
const char * res_get(Res r, const char *name)
const char * res_get_def(Res r, const char *name, const char *def)
void zebra_snippets_appendn(zebra_snippets *l, zint seqno, int ws, int ord, const char *term, size_t term_len)
void zebra_snippets_append(zebra_snippets *l, zint seqno, int ws, int ord, const char *term)
int zebra_sort_type(zebra_sort_index_t si, int type)
sets type for sort usage
void zebra_sort_add(zebra_sort_index_t si, zint section_id, WRBUF w)
adds multi-map content to sort file
void zebra_sort_sysno(zebra_sort_index_t si, zint sysno)
sets sort system number for read / add / delete
void zebra_sort_delete(zebra_sort_index_t si, zint section_id)
delete sort entry
struct recExtractCtrl * extractCtrl
void(* destroy)(struct ZebraRecStream *s)
close and destroy stream
off_t(* seekf)(struct ZebraRecStream *s, off_t offset)
seek function
off_t(* endf)(struct ZebraRecStream *s, off_t *offset)
set and get of record position
int(* readf)(struct ZebraRecStream *s, char *buf, size_t count)
read function
off_t(* tellf)(struct ZebraRecStream *s)
tell function
zint mem[IT_KEY_LEVEL_MAX]
int(* extract)(void *clientData, struct recExtractCtrl *ctrl)
struct recordGroup * rGroup
zebra_snippets * snippets
zebra_rec_keys_t sortKeys
zebra_key_block_t key_block
zebra_sort_index_t sort_index
struct zebra_register * reg
const char * m_record_type
#define CAST_ZINT_TO_INT(x)
zint atozint(const char *src)
short ZEBRA_RES
Common return type for Zebra API.
int zebra_maps_is_index(zebra_map_t zm)
int zebra_maps_is_alwaysmatches(zebra_map_t zm)
int zebra_maps_is_first_in_field(zebra_map_t zm)
int zebra_map_tokenize_next(zebra_map_t zm, const char **result_buf, size_t *result_len, const char **display_buf, size_t *display_len)
int zebra_maps_is_sort(zebra_map_t zm)
int zebra_maps_is_staticrank(zebra_map_t zm)
int zebra_maps_is_icu(zebra_map_t zm)
int zebra_map_tokenize_start(zebra_map_t zm, const char *buf, size_t len)
int zebra_maps_is_complete(zebra_map_t zm)
zebra_map_t zebra_map_get_or_add(zebra_maps_t zms, const char *id)
const char ** zebra_maps_input(zebra_map_t zm, const char **from, int len, int first)
int zebraExplain_curDatabase(ZebraExplainInfo zei, const char *database)
RecordAttr * rec_init_attr(ZebraExplainInfo zei, Record rec)
void zebraExplain_recordBytesIncrement(ZebraExplainInfo zei, int adjust_num)
int zebraExplain_lookup_attr_str(ZebraExplainInfo zei, zinfo_index_category_t cat, const char *index_type, const char *str)
lookup ordinal from string index + index type
void zebraExplain_addSchema(ZebraExplainInfo zei, Odr_oid *oid)
void zebraExplain_recordCountIncrement(ZebraExplainInfo zei, int adjust_num)
int zebraExplain_add_attr_str(ZebraExplainInfo zei, zinfo_index_category_t cat, const char *index_type, const char *index_name)
zint zebraExplain_runNumberIncrement(ZebraExplainInfo zei, int adjust_num)
int zebraExplain_get_database_ord(ZebraExplainInfo zei)
int zebraExplain_ord_adjust_occurrences(ZebraExplainInfo zei, int ord, int term_delta, int doc_delta)
int zebraExplain_lookup_ord(ZebraExplainInfo zei, int ord, const char **index_type, const char **db, const char **string_index)
int zebraExplain_newDatabase(ZebraExplainInfo zei, const char *database, int explain_database)
@ zinfo_index_category_index
@ zinfo_index_category_alwaysmatches
@ zinfo_index_category_sort