-/* $Id: zebramap.h,v 1.24 2007-10-29 22:22:06 adam Exp $
+/* $Id: zebramap.h,v 1.25 2007-10-30 19:17:15 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
YAZ_BEGIN_CDECL
-typedef struct zebra_maps *ZebraMaps;
+typedef struct zebra_maps_s *zebra_maps_t;
+typedef struct zebra_map *zebra_map_t;
YAZ_EXPORT
-ZebraMaps zebra_maps_open(Res res, const char *base_path,
+zebra_maps_t zebra_maps_open(Res res, const char *base_path,
const char *profile_path);
YAZ_EXPORT
-ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname);
+ZEBRA_RES zebra_maps_read_file(zebra_maps_t zms, const char *fname);
YAZ_EXPORT
-void zebra_maps_close(ZebraMaps zm);
+void zebra_maps_close(zebra_maps_t zm);
YAZ_EXPORT
-const char **zebra_maps_input(ZebraMaps zms, unsigned reg_id,
+const char **zebra_maps_input(zebra_map_t zm,
const char **from, int len, int first);
YAZ_EXPORT
-const char **zebra_maps_search(ZebraMaps zms, unsigned reg_id,
+const char **zebra_maps_search(zebra_map_t zm,
const char **from, int len, int *q_map_match);
YAZ_EXPORT
-const char *zebra_maps_output(ZebraMaps, unsigned reg_id, const char **from);
+const char *zebra_maps_output(zebra_map_t zm, const char **from);
YAZ_EXPORT
-int zebra_maps_attr(ZebraMaps zms, Z_AttributesPlusTerm *zapt,
+int zebra_maps_attr(zebra_maps_t zms, Z_AttributesPlusTerm *zapt,
const char **reg_id, char **search_type, char *rank_type,
int *complete_flag, int *sort_flag);
YAZ_EXPORT
-int zebra_maps_sort(ZebraMaps zms, Z_SortAttributes *sortAttributes,
+int zebra_maps_sort(zebra_maps_t zms, Z_SortAttributes *sortAttributes,
int *numerical);
YAZ_EXPORT
-int zebra_maps_is_complete(ZebraMaps zms, unsigned reg_id);
+int zebra_maps_is_complete(zebra_map_t zm);
YAZ_EXPORT
-int zebra_maps_is_sort(ZebraMaps zms, unsigned reg_id);
+int zebra_maps_is_sort(zebra_map_t zm);
YAZ_EXPORT
-int zebra_maps_is_index(ZebraMaps zms, unsigned reg_id);
+int zebra_maps_is_index(zebra_map_t zm);
YAZ_EXPORT
-int zebra_maps_is_staticrank(ZebraMaps zms, unsigned reg_id);
+int zebra_maps_is_staticrank(zebra_map_t zm);
YAZ_EXPORT
-int zebra_maps_is_alwaysmatches(ZebraMaps zms, unsigned reg_id);
+int zebra_maps_is_alwaysmatches(zebra_map_t zm);
YAZ_EXPORT
-int zebra_maps_is_positioned(ZebraMaps zms, unsigned reg_id);
+int zebra_maps_is_positioned(zebra_map_t zm);
YAZ_EXPORT
-int zebra_maps_is_first_in_field(ZebraMaps zms, unsigned reg_id);
+int zebra_maps_is_first_in_field(zebra_map_t zm);
YAZ_EXPORT
-WRBUF zebra_replace(ZebraMaps zms, unsigned reg_id, const char *ex_list,
+WRBUF zebra_replace(zebra_map_t zm, const char *ex_list,
const char *input_str, int input_len);
+YAZ_EXPORT
+zebra_map_t zebra_map_get(zebra_maps_t zms, unsigned reg_id);
+
+YAZ_EXPORT
+zebra_map_t zebra_map_get_or_add(zebra_maps_t zms, unsigned reg_id);
+
YAZ_END_CDECL
#endif
-/* $Id: extract.c,v 1.265 2007-10-29 16:57:52 adam Exp $
+/* $Id: extract.c,v 1.266 2007-10-30 19:17:15 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
int i;
for (i = 0; i<256; i++)
{
- if (zebra_maps_is_positioned(zh->reg->zebra_maps, i))
+ zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, i);
+ if (zebra_maps_is_positioned(zm))
ctrl->seqno[i] = 1;
else
ctrl->seqno[i] = 0;
};
-static void snippet_add_complete_field(RecWord *p, int ord)
+static void snippet_add_complete_field(RecWord *p, int ord,
+ zebra_map_t zm)
{
struct snip_rec_info *h = p->extractCtrl->handle;
- ZebraHandle zh = h->zh;
const char *b = p->term_buf;
char buf[IT_MAX_WORD+1];
const char *last = 0;
if (remain > 0)
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 1);
+ map = zebra_maps_input(zm, &b, remain, 1);
while (remain > 0 && i < IT_MAX_WORD)
{
{
int first = i ? 0 : 1; /* first position */
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type,
- &b, remain, first);
+ map = zebra_maps_input(zm, &b, remain, first);
}
else
map = 0;
remain = p->term_len - (b - p->term_buf);
if (remain > 0)
{
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b,
- remain, 0);
+ map = zebra_maps_input(zm, &b, remain, 0);
}
else
map = 0;
start, last - start);
}
-static void snippet_add_incomplete_field(RecWord *p, int ord)
+static void snippet_add_incomplete_field(RecWord *p, int ord, zebra_map_t zm)
{
struct snip_rec_info *h = p->extractCtrl->handle;
- ZebraHandle zh = h->zh;
const char *b = p->term_buf;
int remain = p->term_len;
int first = 1;
const char *last = b;
if (remain > 0)
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 0);
+ map = zebra_maps_input(zm, &b, remain, 0);
while (map)
{
remain = p->term_len - (b - p->term_buf);
last = b;
if (remain > 0)
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b,
- remain, 0);
+ map = zebra_maps_input(zm, &b, remain, 0);
else
map = 0;
}
remain = p->term_len - (b - p->term_buf);
last = b;
if (remain > 0)
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 0);
+ map = zebra_maps_input(zm, &b, remain, 0);
else
map = 0;
}
if (first)
{
first = 0;
- if (zebra_maps_is_first_in_field(zh->reg->zebra_maps, *p->index_type))
+ if (zebra_maps_is_first_in_field(zm))
{
/* first in field marker */
p->seqno++;
{
struct snip_rec_info *h = p->extractCtrl->handle;
ZebraHandle zh = h->zh;
+ zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *p->index_type);
- if (zebra_maps_is_index(zh->reg->zebra_maps, *p->index_type))
+ if (zm && zebra_maps_is_index(zm))
{
ZebraExplainInfo zei = zh->reg->zei;
int ch = zebraExplain_lookup_attr_str(
zei, zinfo_index_category_index, p->index_type, p->index_name);
- if(zebra_maps_is_complete (h->zh->reg->zebra_maps, *p->index_type))
- snippet_add_complete_field(p, ch);
+ if (zebra_maps_is_complete(zm))
+ snippet_add_complete_field(p, ch, zm);
else
- snippet_add_incomplete_field(p, ch);
+ snippet_add_incomplete_field(p, ch, zm);
}
}
ctrl->staticrank = atozint(valz);
}
-static void extract_add_string(RecWord *p, const char *string, int length)
+static void extract_add_string(RecWord *p, zebra_map_t zm,
+ const char *string, int length)
{
- ZebraHandle zh = p->extractCtrl->handle;
assert(length > 0);
if (!p->index_name)
return;
- if (zebra_maps_is_index(zh->reg->zebra_maps, *p->index_type))
+ if (zebra_maps_is_index(zm))
{
extract_add_index_string(p, zinfo_index_category_index,
string, length);
- if (zebra_maps_is_alwaysmatches(zh->reg->zebra_maps, *p->index_type))
+ if (zebra_maps_is_alwaysmatches(zm))
{
RecWord word;
memcpy(&word, p, sizeof(word));
&word, zinfo_index_category_alwaysmatches, "", 0);
}
}
- else if (zebra_maps_is_sort(zh->reg->zebra_maps, *p->index_type))
+ else if (zebra_maps_is_sort(zm))
{
extract_add_sort_string(p, string, length);
}
- else if (zebra_maps_is_staticrank(zh->reg->zebra_maps, *p->index_type))
+ else if (zebra_maps_is_staticrank(zm))
{
extract_add_staticrank_string(p, string, length);
}
}
-static void extract_add_incomplete_field(RecWord *p)
+static void extract_add_incomplete_field(RecWord *p, zebra_map_t zm)
{
- ZebraHandle zh = p->extractCtrl->handle;
const char *b = p->term_buf;
int remain = p->term_len;
int first = 1;
const char **map = 0;
if (remain > 0)
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 0);
+ map = zebra_maps_input(zm, &b, remain, 0);
while (map)
{
{
remain = p->term_len - (b - p->term_buf);
if (remain > 0)
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b,
- remain, 0);
+ map = zebra_maps_input(zm, &b, remain, 0);
else
map = 0;
}
buf[i++] = *(cp++);
remain = p->term_len - (b - p->term_buf);
if (remain > 0)
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 0);
+ map = zebra_maps_input(zm, &b, remain, 0);
else
map = 0;
}
if (first)
{
first = 0;
- if (zebra_maps_is_first_in_field(zh->reg->zebra_maps, *p->index_type))
+ if (zebra_maps_is_first_in_field(zm))
{
/* first in field marker */
- extract_add_string(p, FIRST_IN_FIELD_STR, FIRST_IN_FIELD_LEN);
+ extract_add_string(p, zm, FIRST_IN_FIELD_STR, FIRST_IN_FIELD_LEN);
p->seqno++;
}
}
- extract_add_string(p, buf, i);
+ extract_add_string(p, zm, buf, i);
p->seqno++;
}
}
-static void extract_add_complete_field(RecWord *p)
+static void extract_add_complete_field(RecWord *p, zebra_map_t zm)
{
- ZebraHandle zh = p->extractCtrl->handle;
const char *b = p->term_buf;
char buf[IT_MAX_WORD+1];
const char **map = 0;
int i = 0, remain = p->term_len;
if (remain > 0)
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, 1);
+ map = zebra_maps_input(zm, &b, remain, 1);
while (remain > 0 && i < IT_MAX_WORD)
{
if (remain > 0)
{
int first = i ? 0 : 1; /* first position */
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b, remain, first);
+ map = zebra_maps_input(zm, &b, remain, first);
}
else
map = 0;
remain = p->term_len - (b - p->term_buf);
if (remain > 0)
{
- map = zebra_maps_input(zh->reg->zebra_maps, *p->index_type, &b,
- remain, 0);
+ map = zebra_maps_input(zm, &b, remain, 0);
}
else
map = 0;
}
if (!i)
return;
- extract_add_string(p, buf, i);
+ extract_add_string(p, zm, buf, i);
}
static void extract_token_add2_index(ZebraHandle zh, zebra_index_type_t type,
static void extract_token_add(RecWord *p)
{
ZebraHandle zh = p->extractCtrl->handle;
+ zebra_map_t zm = zebra_map_get_or_add(zh->reg->zebra_maps, *p->index_type);
WRBUF wrbuf;
if (log_level_details)
p->index_type, p->index_name,
p->seqno, p->term_len, p->term_buf);
}
- if ((wrbuf = zebra_replace(zh->reg->zebra_maps, *p->index_type, 0,
- p->term_buf, p->term_len)))
+ if ((wrbuf = zebra_replace(zm, 0, p->term_buf, p->term_len)))
{
p->term_buf = wrbuf_buf(wrbuf);
p->term_len = wrbuf_len(wrbuf);
}
- if (zebra_maps_is_complete(zh->reg->zebra_maps, *p->index_type))
- extract_add_complete_field(p);
+ if (zebra_maps_is_complete(zm))
+ extract_add_complete_field(p, zm);
else
- extract_add_incomplete_field(p);
+ extract_add_incomplete_field(p, zm);
}
static void extract_set_store_data_cb(struct recExtractCtrl *p,
-/* $Id: index.h,v 1.202 2007-10-29 16:57:52 adam Exp $
+/* $Id: index.h,v 1.203 2007-10-30 19:17:15 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
char *server_path_prefix;
data1_handle dh;
zebra_index_types_t index_types;
- ZebraMaps zebra_maps;
+ zebra_maps_t zebra_maps;
ZebraRankClass rank_classes;
RecTypes recTypes;
int seqno;
struct rpn_char_map_info
{
- ZebraMaps zm;
+ zebra_map_t zm;
int reg_type;
};
-void rpn_char_map_prepare(struct zebra_register *reg, int reg_type,
+void rpn_char_map_prepare(struct zebra_register *reg, zebra_map_t zm,
struct rpn_char_map_info *map_info);
ZEBRA_RES zapt_term_to_utf8(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
-/* $Id: rpnscan.c,v 1.15 2007-10-29 16:57:53 adam Exp $
+/* $Id: rpnscan.c,v 1.16 2007-10-30 19:17:15 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
/* convert APT SCAN term to internal cmap */
static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- char *termz, const char *index_type)
+ char *termz, zebra_map_t zm)
{
char termz0[IT_MAX_WORD];
while ((len = (cp_end - cp)) > 0)
{
- map = zebra_maps_input(zh->reg->zebra_maps, *index_type,
- &cp, len, 0);
+ map = zebra_maps_input(zm, &cp, len, 0);
if (**map == *CHR_SPACE)
space_map = *map;
else
{
struct scan2_info_entry *ar = nmem_malloc(nmem, sizeof(*ar) * ord_no);
struct rpn_char_map_info rcmi;
+ zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *index_type);
int i, dif;
int after_pos;
int pos = 0;
*num_entries = 0;
return ZEBRA_OK;
}
- rpn_char_map_prepare(zh->reg, *index_type, &rcmi);
+ rpn_char_map_prepare(zh->reg, zm, &rcmi);
for (i = 0; i < ord_no; i++)
ar[i].term = wrbuf_alloc();
termz[prefix_len] = 0;
strcpy(ar[i].prefix, termz);
- if (trans_scan_term(zh, zapt, termz+prefix_len, index_type) ==
+ if (trans_scan_term(zh, zapt, termz+prefix_len, zm) ==
ZEBRA_FAIL)
{
for (i = 0; i < ord_no; i++)
termz[prefix_len] = 0;
strcpy(ar[i].prefix, termz);
- if (trans_scan_term(zh, zapt, termz+prefix_len, index_type) ==
+ if (trans_scan_term(zh, zapt, termz+prefix_len, zm) ==
ZEBRA_FAIL)
return ZEBRA_FAIL;
wrbuf_rewind(ar[i].term);
-/* $Id: rpnsearch.c,v 1.17 2007-10-29 20:07:04 adam Exp $
+/* $Id: rpnsearch.c,v 1.18 2007-10-30 19:17:15 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
static const char **rpn_char_map_handler(void *vp, const char **from, int len)
{
struct rpn_char_map_info *p = (struct rpn_char_map_info *) vp;
- const char **out = zebra_maps_input(p->zm, p->reg_type, from, len, 0);
+ const char **out = zebra_maps_input(p->zm, from, len, 0);
#if 0
if (out && *out)
{
return out;
}
-void rpn_char_map_prepare(struct zebra_register *reg, int reg_type,
+void rpn_char_map_prepare(struct zebra_register *reg, zebra_map_t zm,
struct rpn_char_map_info *map_info)
{
- map_info->zm = reg->zebra_maps;
- map_info->reg_type = reg_type;
+ map_info->zm = zm;
dict_grep_cmap(reg->dict, map_info, rpn_char_map_handler);
}
return add_isam_p(name, info, (struct grep_info *) p);
}
-static int term_pre(ZebraMaps zebra_maps, int reg_type, const char **src,
+static int term_pre(zebra_map_t zm, const char **src,
const char *ct1, const char *ct2, int first)
{
const char *s1, *s0 = *src;
if (ct2 && strchr(ct2, *s0))
break;
s1 = s0;
- map = zebra_maps_input(zebra_maps, reg_type, &s1, strlen(s1), first);
+ map = zebra_maps_input(zm, &s1, strlen(s1), first);
if (**map != *CHR_SPACE)
break;
s0 = s1;
}
/* term_100: handle term, where trunc = none(no operators at all) */
-static int term_100(ZebraMaps zebra_maps, const char *index_type,
+static int term_100(zebra_map_t zm,
const char **src, WRBUF term_dict, int space_split,
char *dst_term)
{
const char *space_start = 0;
const char *space_end = 0;
- if (!term_pre(zebra_maps, *index_type, src, NULL, NULL, !space_split))
+ if (!term_pre(zm, src, NULL, NULL, !space_split))
return 0;
s0 = *src;
while (*s0)
{
const char *s1 = s0;
int q_map_match = 0;
- map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0),
- &q_map_match);
+ map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match);
if (space_split)
{
if (**map == *CHR_SPACE)
}
/* term_101: handle term, where trunc = Process # */
-static int term_101(ZebraMaps zebra_maps, const char *index_type,
+static int term_101(zebra_map_t zm,
const char **src, WRBUF term_dict, int space_split,
char *dst_term)
{
int i = 0;
int j = 0;
- if (!term_pre(zebra_maps, *index_type, src, "#", "#", !space_split))
+ if (!term_pre(zm, src, "#", "#", !space_split))
return 0;
s0 = *src;
while (*s0)
{
const char *s1 = s0;
int q_map_match = 0;
- map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0),
- &q_map_match);
+ map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match);
if (space_split && **map == *CHR_SPACE)
break;
}
/* term_103: handle term, where trunc = re-2 (regular expressions) */
-static int term_103(ZebraMaps zebra_maps, const char *index_type,
- const char **src,
+static int term_103(zebra_map_t zm, const char **src,
WRBUF term_dict, int *errors, int space_split,
char *dst_term)
{
const char *s0;
const char **map;
- if (!term_pre(zebra_maps, *index_type, src, "^\\()[].*+?|", "(", !space_split))
+ if (!term_pre(zm, src, "^\\()[].*+?|", "(", !space_split))
return 0;
s0 = *src;
if (errors && *s0 == '+' && s0[1] && s0[2] == '+' && s0[3] &&
{
const char *s1 = s0;
int q_map_match = 0;
- map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0),
- &q_map_match);
+ map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match);
if (space_split && **map == *CHR_SPACE)
break;
}
/* term_103: handle term, where trunc = re-1 (regular expressions) */
-static int term_102(ZebraMaps zebra_maps, const char *index_type,
- const char **src,
+static int term_102(zebra_map_t zm, const char **src,
WRBUF term_dict, int space_split, char *dst_term)
{
- return term_103(zebra_maps, index_type, src, term_dict, NULL, space_split,
- dst_term);
+ return term_103(zm, src, term_dict, NULL, space_split, dst_term);
}
/* term_104: handle term, process # and ! */
-static int term_104(ZebraMaps zebra_maps, const char *index_type,
- const char **src, WRBUF term_dict, int space_split,
- char *dst_term)
+static int term_104(zebra_map_t zm, const char **src,
+ WRBUF term_dict, int space_split, char *dst_term)
{
const char *s0;
const char **map;
int i = 0;
int j = 0;
- if (!term_pre(zebra_maps, *index_type, src, "?*#", "?*#", !space_split))
+ if (!term_pre(zm, src, "?*#", "?*#", !space_split))
return 0;
s0 = *src;
while (*s0)
{
const char *s1 = s0;
int q_map_match = 0;
- map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0),
- &q_map_match);
+ map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match);
if (space_split && **map == *CHR_SPACE)
break;
}
/* term_105/106: handle term, where trunc = Process * and ! and right trunc */
-static int term_105(ZebraMaps zebra_maps, const char *index_type,
- const char **src, WRBUF term_dict, int space_split,
+static int term_105(zebra_map_t zm, const char **src,
+ WRBUF term_dict, int space_split,
char *dst_term, int right_truncate)
{
const char *s0;
int i = 0;
int j = 0;
- if (!term_pre(zebra_maps, *index_type, src, "*!", "*!", !space_split))
+ if (!term_pre(zm, src, "*!", "*!", !space_split))
return 0;
s0 = *src;
while (*s0)
{
const char *s1 = s0;
int q_map_match = 0;
- map = zebra_maps_search(zebra_maps, *index_type, &s0, strlen(s0),
- &q_map_match);
+ map = zebra_maps_search(zm, &s0, strlen(s0), &q_map_match);
if (space_split && **map == *CHR_SPACE)
break;
static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
const char **term_sub, WRBUF term_dict,
const Odr_oid *attributeSet,
- const char *index_type, int space_split, char *term_dst,
+ zebra_map_t zm, int space_split, char *term_dst,
int *error_code)
{
AttrType relation;
switch (relation_value)
{
case 1:
- if (!term_100(zh->reg->zebra_maps, index_type,
- term_sub, term_component,
- space_split, term_dst))
+ if (!term_100(zm, term_sub, term_component, space_split, term_dst))
{
wrbuf_destroy(term_component);
return 0;
wrbuf_putc(term_dict, ')');
break;
case 2:
- if (!term_100(zh->reg->zebra_maps, index_type,
- term_sub, term_component,
- space_split, term_dst))
+ if (!term_100(zm, term_sub, term_component, space_split, term_dst))
{
wrbuf_destroy(term_component);
return 0;
wrbuf_putc(term_dict, ')');
break;
case 5:
- if (!term_100(zh->reg->zebra_maps, index_type,
- term_sub, term_component, space_split, term_dst))
+ if (!term_100(zm, term_sub, term_component, space_split, term_dst))
{
wrbuf_destroy(term_component);
return 0;
wrbuf_putc(term_dict, ')');
break;
case 4:
- if (!term_100(zh->reg->zebra_maps, index_type, term_sub,
- term_component, space_split, term_dst))
+ if (!term_100(zm, term_sub, term_component, space_split, term_dst))
{
wrbuf_destroy(term_component);
return 0;
if (!**term_sub)
return 1;
yaz_log(log_level_rpn, "Relation =");
- if (!term_100(zh->reg->zebra_maps, index_type, term_sub,
- term_component, space_split, term_dst))
+ if (!term_100(zm, term_sub, term_component, space_split, term_dst))
{
wrbuf_destroy(term_component);
return 0;
int relation_error;
char ord_buf[32];
int ord_len, i;
+ zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *index_type);
*ol = ord_list_create(stream);
- rpn_char_map_prepare(zh->reg, *index_type, &rcmi);
+ rpn_char_map_prepare(zh->reg, zm, &rcmi);
attr_init_APT(&truncation, zapt, 5);
truncation_value = attr_find(&truncation, NULL);
yaz_log(log_level_rpn, "truncation value %d", truncation_value);
case 100: /* do not truncate */
if (!string_relation(zh, zapt, &termp, term_dict,
attributeSet,
- index_type, space_split, term_dst,
+ zm, space_split, term_dst,
&relation_error))
{
if (relation_error)
break;
case 1: /* right truncation */
wrbuf_putc(term_dict, '(');
- if (!term_100(zh->reg->zebra_maps, index_type,
- &termp, term_dict, space_split, term_dst))
+ if (!term_100(zm, &termp, term_dict, space_split, term_dst))
{
*term_sub = 0;
return ZEBRA_OK;
break;
case 2: /* keft truncation */
wrbuf_puts(term_dict, "(.*");
- if (!term_100(zh->reg->zebra_maps, index_type,
- &termp, term_dict, space_split, term_dst))
+ if (!term_100(zm, &termp, term_dict, space_split, term_dst))
{
*term_sub = 0;
return ZEBRA_OK;
break;
case 3: /* left&right truncation */
wrbuf_puts(term_dict, "(.*");
- if (!term_100(zh->reg->zebra_maps, index_type,
- &termp, term_dict, space_split, term_dst))
+ if (!term_100(zm, &termp, term_dict, space_split, term_dst))
{
*term_sub = 0;
return ZEBRA_OK;
break;
case 101: /* process # in term */
wrbuf_putc(term_dict, '(');
- if (!term_101(zh->reg->zebra_maps, index_type,
- &termp, term_dict, space_split, term_dst))
+ if (!term_101(zm, &termp, term_dict, space_split, term_dst))
{
*term_sub = 0;
return ZEBRA_OK;
break;
case 102: /* Regexp-1 */
wrbuf_putc(term_dict, '(');
- if (!term_102(zh->reg->zebra_maps, index_type,
- &termp, term_dict, space_split, term_dst))
+ if (!term_102(zm, &termp, term_dict, space_split, term_dst))
{
*term_sub = 0;
return ZEBRA_OK;
case 103: /* Regexp-2 */
regex_range = 1;
wrbuf_putc(term_dict, '(');
- if (!term_103(zh->reg->zebra_maps, index_type,
- &termp, term_dict, ®ex_range,
+ if (!term_103(zm, &termp, term_dict, ®ex_range,
space_split, term_dst))
{
*term_sub = 0;
break;
case 104: /* process # and ! in term */
wrbuf_putc(term_dict, '(');
- if (!term_104(zh->reg->zebra_maps, index_type,
- &termp, term_dict, space_split, term_dst))
+ if (!term_104(zm, &termp, term_dict, space_split, term_dst))
{
*term_sub = 0;
return ZEBRA_OK;
break;
case 105: /* process * and ! in term */
wrbuf_putc(term_dict, '(');
- if (!term_105(zh->reg->zebra_maps, index_type,
- &termp, term_dict, space_split, term_dst, 1))
+ if (!term_105(zm, &termp, term_dict, space_split, term_dst, 1))
{
*term_sub = 0;
return ZEBRA_OK;
break;
case 106: /* process * and ! in term */
wrbuf_putc(term_dict, '(');
- if (!term_105(zh->reg->zebra_maps, index_type,
- &termp, term_dict, space_split, term_dst, 0))
+ if (!term_105(zm, &termp, term_dict, space_split, term_dst, 0))
{
*term_sub = 0;
return ZEBRA_OK;
int ord_len;
char *val;
ISAM_P isam_p;
+ zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *index_type);
attr_init_APT(&position, zapt, 3);
position_value = attr_find(&position, NULL);
return ZEBRA_FAIL;
}
- if (!zebra_maps_is_first_in_field(zh->reg->zebra_maps, *index_type))
+
+ if (!zebra_maps_is_first_in_field(zm))
{
zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_POSITION_ATTRIBUTE,
position_value);
const Odr_oid *attributeSet,
struct grep_info *grep_info,
int *max_pos,
- const char *index_type,
+ zebra_map_t zm,
char *term_dst,
int *error_code)
{
{
case 1:
yaz_log(log_level_rpn, "Relation <");
- if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1,
- term_dst))
+ if (!term_100(zm, term_sub, term_num, 1, term_dst))
{
wrbuf_destroy(term_num);
return 0;
break;
case 2:
yaz_log(log_level_rpn, "Relation <=");
- if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1,
- term_dst))
+ if (!term_100(zm, term_sub, term_num, 1, term_dst))
{
wrbuf_destroy(term_num);
return 0;
break;
case 4:
yaz_log(log_level_rpn, "Relation >=");
- if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1,
- term_dst))
+ if (!term_100(zm, term_sub, term_num, 1, term_dst))
{
wrbuf_destroy(term_num);
return 0;
break;
case 5:
yaz_log(log_level_rpn, "Relation >");
- if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1,
- term_dst))
+ if (!term_100(zm, term_sub, term_num, 1, term_dst))
{
wrbuf_destroy(term_num);
return 0;
case -1:
case 3:
yaz_log(log_level_rpn, "Relation =");
- if (!term_100(zh->reg->zebra_maps, index_type, term_sub, term_num, 1,
- term_dst))
+ if (!term_100(zm, term_sub, term_num, 1, term_dst))
{
wrbuf_destroy(term_num);
return 0;
int relation_error = 0;
int ord, ord_len, i;
char ord_buf[32];
+ zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, *index_type);
*ol = ord_list_create(stream);
- rpn_char_map_prepare(zh->reg, *index_type, &rcmi);
+ rpn_char_map_prepare(zh->reg, zm, &rcmi);
termp = *term_sub;
wrbuf_putc(term_dict, ')');
if (!numeric_relation(zh, zapt, &termp, term_dict,
- attributeSet, grep_info, &max_pos, index_type,
+ attributeSet, grep_info, &max_pos, zm,
term_dst, &relation_error))
{
if (relation_error)
-/* $Id: untrans.c,v 1.3 2007-03-20 22:07:35 adam Exp $
+/* $Id: untrans.c,v 1.4 2007-10-30 19:17:15 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
void zebra_term_untrans(ZebraHandle zh, int reg_type,
char *dst, const char *src)
{
+ zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, reg_type);
int len = 0;
while (*src)
{
- const char *cp = zebra_maps_output(zh->reg->zebra_maps,
- reg_type, &src);
+ const char *cp = zebra_maps_output(zm, &src);
if (!cp)
{
if (len < IT_MAX_WORD-1)
-/* $Id: zebraapi.c,v 1.260 2007-10-29 09:25:41 adam Exp $
+/* $Id: zebraapi.c,v 1.261 2007-10-30 19:17:15 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
char *output_str, int output_len)
{
WRBUF wrbuf;
+ zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, reg_id);
ASSERTZH;
assert(input_str);
assert(output_str);
if (!zh->reg->zebra_maps)
return -1;
- wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "",
- input_str, input_len);
+ wrbuf = zebra_replace(zm, "", input_str, input_len);
if (!wrbuf)
return -2;
if (wrbuf_len(wrbuf) >= output_len)
-/* $Id: zebramap.c,v 1.59 2007-10-29 16:57:54 adam Exp $
+/* $Id: zebramap.c,v 1.60 2007-10-30 19:17:15 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
} u;
chrmaptab maptab;
const char *maptab_name;
+ zebra_maps_t zebra_maps;
struct zebra_map *next;
};
-struct zebra_maps {
+struct zebra_maps_s {
char *tabpath;
char *tabroot;
NMEM nmem;
- struct zebra_map *map_list;
char temp_map_str[2];
const char *temp_map_ptr[2];
struct zebra_map **lookup_array;
WRBUF wrbuf_1;
int no_maps;
+ zebra_map_t map_list;
+ zebra_map_t *last_map;
};
-void zebra_maps_close(ZebraMaps zms)
+void zebra_maps_close(zebra_maps_t zms)
{
struct zebra_map *zm = zms->map_list;
while (zm)
xfree(zms);
}
-ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname)
+zebra_map_t zebra_add_map(zebra_maps_t zms, const char *index_type,
+ int map_type)
+{
+ zebra_map_t zm = (zebra_map_t) nmem_malloc(zms->nmem, sizeof(*zm));
+
+ zm->zebra_maps = zms;
+ zm->reg_id = index_type[0];
+ zm->maptab_name = 0;
+ zm->maptab = 0;
+ zm->type = map_type;
+ zm->completeness = 0;
+ zm->positioned = 0;
+ zm->alwaysmatches = 0;
+ zm->first_in_field = 0;
+
+ zm->next = 0;
+ *zms->last_map = zm;
+ zms->last_map = &zm->next;
+
+ zms->no_maps++;
+
+ return zm;
+}
+
+ZEBRA_RES zebra_maps_read_file(zebra_maps_t zms, const char *fname)
{
FILE *f;
char line[512];
int argc;
int lineno = 0;
int failures = 0;
- struct zebra_map **zm = 0, *zp;
+ zebra_map_t zm = 0;
if (!(f = yaz_fopen(zms->tabpath, fname, "r", zms->tabroot)))
{
}
if (!yaz_matchstr(argv[0], "index"))
{
- if (!zm)
- zm = &zms->map_list;
- else
- zm = &(*zm)->next;
- *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm));
- (*zm)->reg_id = argv[1][0];
- (*zm)->maptab_name = NULL;
- (*zm)->maptab = NULL;
- (*zm)->type = ZEBRA_MAP_TYPE_INDEX;
- (*zm)->completeness = 0;
- (*zm)->positioned = 1;
- (*zm)->alwaysmatches = 0;
- (*zm)->first_in_field = 0;
- zms->no_maps++;
+ zm = zebra_add_map(zms, argv[1], ZEBRA_MAP_TYPE_INDEX);
+ zm->positioned = 1;
}
else if (!yaz_matchstr(argv[0], "sort"))
{
- if (!zm)
- zm = &zms->map_list;
- else
- zm = &(*zm)->next;
- *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm));
- (*zm)->reg_id = argv[1][0];
- (*zm)->maptab_name = NULL;
- (*zm)->type = ZEBRA_MAP_TYPE_SORT;
- (*zm)->u.sort.entry_size = 80;
- (*zm)->maptab = NULL;
- (*zm)->completeness = 0;
- (*zm)->positioned = 0;
- (*zm)->alwaysmatches = 0;
- (*zm)->first_in_field = 0;
- zms->no_maps++;
+ zm = zebra_add_map(zms, argv[1], ZEBRA_MAP_TYPE_SORT);
+ zm->u.sort.entry_size = 80;
}
else if (!yaz_matchstr(argv[0], "staticrank"))
{
- if (!zm)
- zm = &zms->map_list;
- else
- zm = &(*zm)->next;
- *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm));
- (*zm)->reg_id = argv[1][0];
- (*zm)->maptab_name = NULL;
- (*zm)->type = ZEBRA_MAP_TYPE_STATICRANK;
- (*zm)->maptab = NULL;
- (*zm)->completeness = 1;
- (*zm)->positioned = 0;
- (*zm)->alwaysmatches = 0;
- (*zm)->first_in_field = 0;
- zms->no_maps++;
+ zm = zebra_add_map(zms, argv[1], ZEBRA_MAP_TYPE_STATICRANK);
+ zm->completeness = 1;
}
else if (!zm)
{
}
else if (!yaz_matchstr(argv[0], "charmap") && argc == 2)
{
- if ((*zm)->type != ZEBRA_MAP_TYPE_STATICRANK)
- (*zm)->maptab_name = nmem_strdup(zms->nmem, argv[1]);
+ if (zm->type != ZEBRA_MAP_TYPE_STATICRANK)
+ zm->maptab_name = nmem_strdup(zms->nmem, argv[1]);
else
{
yaz_log(YLOG_WARN|YLOG_FATAL, "%s:%d: charmap for "
"staticrank is invalid", fname, lineno);
- yaz_log(YLOG_LOG, "Type is %d", (*zm)->type);
+ yaz_log(YLOG_LOG, "Type is %d", zm->type);
failures++;
}
}
else if (!yaz_matchstr(argv[0], "completeness") && argc == 2)
{
- (*zm)->completeness = atoi(argv[1]);
+ zm->completeness = atoi(argv[1]);
}
else if (!yaz_matchstr(argv[0], "position") && argc == 2)
{
- (*zm)->positioned = atoi(argv[1]);
+ zm->positioned = atoi(argv[1]);
}
else if (!yaz_matchstr(argv[0], "alwaysmatches") && argc == 2)
{
- if ((*zm)->type != ZEBRA_MAP_TYPE_STATICRANK)
- (*zm)->alwaysmatches = atoi(argv[1]);
+ if (zm->type != ZEBRA_MAP_TYPE_STATICRANK)
+ zm->alwaysmatches = atoi(argv[1]);
else
{
yaz_log(YLOG_WARN|YLOG_FATAL, "%s:%d: alwaysmatches for "
}
else if (!yaz_matchstr(argv[0], "firstinfield") && argc == 2)
{
- (*zm)->first_in_field = atoi(argv[1]);
+ zm->first_in_field = atoi(argv[1]);
}
else if (!yaz_matchstr(argv[0], "entrysize") && argc == 2)
{
- if ((*zm)->type == ZEBRA_MAP_TYPE_SORT)
- (*zm)->u.sort.entry_size = atoi(argv[1]);
+ if (zm->type == ZEBRA_MAP_TYPE_SORT)
+ zm->u.sort.entry_size = atoi(argv[1]);
}
else
{
failures++;
}
}
- if (zm)
- (*zm)->next = NULL;
yaz_fclose(f);
- for (zp = zms->map_list; zp; zp = zp->next)
- zms->lookup_array[zp->reg_id] = zp;
+ for (zm = zms->map_list; zm; zm = zm->next)
+ zms->lookup_array[zm->reg_id] = zm;
if (failures)
return ZEBRA_FAIL;
return ZEBRA_OK;
}
-ZebraMaps zebra_maps_open(Res res, const char *base_path,
+zebra_maps_t zebra_maps_open(Res res, const char *base_path,
const char *profile_path)
{
- ZebraMaps zms = (ZebraMaps) xmalloc(sizeof(*zms));
+ zebra_maps_t zms = (zebra_maps_t) xmalloc(sizeof(*zms));
int i;
zms->nmem = nmem_create();
zms->tabroot = 0;
if (base_path)
zms->tabroot = nmem_strdup(zms->nmem, base_path);
- zms->map_list = NULL;
+ zms->map_list = 0;
+ zms->last_map = &zms->map_list;
zms->temp_map_str[0] = '\0';
zms->temp_map_str[1] = '\0';
zms->temp_map_ptr[0] = zms->temp_map_str;
zms->temp_map_ptr[1] = NULL;
- zms->lookup_array = (struct zebra_map**)
+ zms->lookup_array = (zebra_map_t *)
nmem_malloc(zms->nmem, sizeof(*zms->lookup_array)*256);
zms->wrbuf_1 = wrbuf_alloc();
return zms;
}
-struct zebra_map *zebra_map_get(ZebraMaps zms, unsigned reg_id)
+zebra_map_t zebra_map_get(zebra_maps_t zms, unsigned reg_id)
{
assert(reg_id >= 0 && reg_id <= 255);
return zms->lookup_array[reg_id];
}
-chrmaptab zebra_charmap_get(ZebraMaps zms, unsigned reg_id)
+zebra_map_t zebra_map_get_or_add(zebra_maps_t zms, unsigned reg_id)
{
struct zebra_map *zm = zebra_map_get(zms, reg_id);
if (!zm)
{
- zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(*zm));
+ char name[2];
+ name[0] = reg_id;
+ name[1] = '\0';
+
+ zm = zebra_add_map(zms, name, ZEBRA_MAP_TYPE_INDEX);
- /* no reason to warn if no maps are installed at ALL */
- if (zms->no_maps)
+ /* no reason to warn if no maps are installed at ALL
+ Note that zebra_add_maps increments no_maps ..
+ */
+ if (zms->no_maps > 1)
yaz_log(YLOG_WARN, "Unknown register type: %c", reg_id);
+ else
+ zms->no_maps = 0;
- zm->reg_id = reg_id;
zm->maptab_name = nmem_strdup(zms->nmem, "@");
- zm->maptab = NULL;
- zm->type = ZEBRA_MAP_TYPE_INDEX;
zm->completeness = 0;
+ zm->positioned = 1;
zm->next = zms->map_list;
zms->map_list = zm->next;
zms->lookup_array[zm->reg_id & 255] = zm;
}
+ return zm;
+}
+
+chrmaptab zebra_charmap_get(zebra_map_t zm)
+{
if (!zm->maptab)
{
if (!zm->maptab_name || !yaz_matchstr(zm->maptab_name, "@"))
return NULL;
- if (!(zm->maptab = chrmaptab_create(zms->tabpath,
+ if (!(zm->maptab = chrmaptab_create(zm->zebra_maps->tabpath,
zm->maptab_name,
- zms->tabroot)))
+ zm->zebra_maps->tabroot)))
yaz_log(YLOG_WARN, "Failed to read character table %s",
zm->maptab_name);
else
return zm->maptab;
}
-const char **zebra_maps_input(ZebraMaps zms, unsigned reg_id,
+const char **zebra_maps_input(zebra_map_t zm,
const char **from, int len, int first)
{
- chrmaptab maptab;
-
- maptab = zebra_charmap_get(zms, reg_id);
+ chrmaptab maptab = zebra_charmap_get(zm);
if (maptab)
return chr_map_input(maptab, from, len, first);
- zms->temp_map_str[0] = **from;
+ zm->zebra_maps->temp_map_str[0] = **from;
(*from)++;
- return zms->temp_map_ptr;
+ return zm->zebra_maps->temp_map_ptr;
}
-const char **zebra_maps_search(ZebraMaps zms, unsigned reg_id,
+const char **zebra_maps_search(zebra_map_t zm,
const char **from, int len, int *q_map_match)
{
chrmaptab maptab;
*q_map_match = 0;
- maptab = zebra_charmap_get(zms, reg_id);
+ maptab = zebra_charmap_get(zm);
if (maptab)
{
const char **map;
if (map)
return map;
}
- zms->temp_map_str[0] = **from;
+ zm->zebra_maps->temp_map_str[0] = **from;
(*from)++;
- return zms->temp_map_ptr;
+ return zm->zebra_maps->temp_map_ptr;
}
-const char *zebra_maps_output(ZebraMaps zms, unsigned reg_id,
+const char *zebra_maps_output(zebra_map_t zm,
const char **from)
{
- chrmaptab maptab = zebra_charmap_get(zms, reg_id);
+ chrmaptab maptab = zebra_charmap_get(zm);
if (!maptab)
return 0;
return chr_map_output(maptab, from, 1);
/* ------------------------------------ */
-int zebra_maps_is_complete(ZebraMaps zms, unsigned reg_id)
+int zebra_maps_is_complete(zebra_map_t zm)
{
- struct zebra_map *zm = zebra_map_get(zms, reg_id);
if (zm)
return zm->completeness;
return 0;
}
-int zebra_maps_is_positioned(ZebraMaps zms, unsigned reg_id)
+int zebra_maps_is_positioned(zebra_map_t zm)
{
- struct zebra_map *zm = zebra_map_get(zms, reg_id);
if (zm)
return zm->positioned;
return 0;
}
-int zebra_maps_is_index(ZebraMaps zms, unsigned reg_id)
+int zebra_maps_is_index(zebra_map_t zm)
{
- struct zebra_map *zm = zebra_map_get(zms, reg_id);
if (zm)
return zm->type == ZEBRA_MAP_TYPE_INDEX;
return 0;
}
-int zebra_maps_is_staticrank(ZebraMaps zms, unsigned reg_id)
+int zebra_maps_is_staticrank(zebra_map_t zm)
{
- struct zebra_map *zm = zebra_map_get(zms, reg_id);
if (zm)
return zm->type == ZEBRA_MAP_TYPE_STATICRANK;
return 0;
}
-int zebra_maps_is_sort(ZebraMaps zms, unsigned reg_id)
+int zebra_maps_is_sort(zebra_map_t zm)
{
- struct zebra_map *zm = zebra_map_get(zms, reg_id);
if (zm)
return zm->type == ZEBRA_MAP_TYPE_SORT;
return 0;
}
-int zebra_maps_is_alwaysmatches(ZebraMaps zms, unsigned reg_id)
+int zebra_maps_is_alwaysmatches(zebra_map_t zm)
{
- struct zebra_map *zm = zebra_map_get(zms, reg_id);
if (zm)
return zm->alwaysmatches;
return 0;
}
-int zebra_maps_is_first_in_field(ZebraMaps zms, unsigned reg_id)
+int zebra_maps_is_first_in_field(zebra_map_t zm)
{
- struct zebra_map *zm = zebra_map_get(zms, reg_id);
if (zm)
return zm->first_in_field;
return 0;
}
-int zebra_maps_sort(ZebraMaps zms, Z_SortAttributes *sortAttributes,
+int zebra_maps_sort(zebra_maps_t zms, Z_SortAttributes *sortAttributes,
int *numerical)
{
AttrType use;
return attr_find(&use, NULL);
}
-int zebra_maps_attr(ZebraMaps zms, Z_AttributesPlusTerm *zapt,
+int zebra_maps_attr(zebra_maps_t zms, Z_AttributesPlusTerm *zapt,
const char **index_type, char **search_type, char *rank_type,
int *complete_flag, int *sort_flag)
{
return 0;
}
-WRBUF zebra_replace(ZebraMaps zms, unsigned reg_id, const char *ex_list,
+WRBUF zebra_replace(zebra_map_t zm, const char *ex_list,
const char *input_str, int input_len)
{
- wrbuf_rewind(zms->wrbuf_1);
- wrbuf_write(zms->wrbuf_1, input_str, input_len);
- return zms->wrbuf_1;
+ wrbuf_rewind(zm->zebra_maps->wrbuf_1);
+ wrbuf_write(zm->zebra_maps->wrbuf_1, input_str, input_len);
+ return zm->zebra_maps->wrbuf_1;
}
/*