From b09c1d0aa414cb43fb667be54a29b3cc7279ea85 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sat, 5 Mar 2005 09:19:14 +0000 Subject: [PATCH] String attribute support for record filter interface. --- include/idzebra/recctrl.h | 7 +- index/extract.c | 67 ++++++++++-------- index/zinfo.c | 166 ++++++++++++++++++++++++++++++++------------- index/zinfo.h | 8 ++- index/zrpn.c | 96 ++++++++++++++++---------- isamb/isamb.c | 16 ++--- recctrl/recgrs.c | 124 ++++++++++++++++----------------- recctrl/rectext.c | 6 +- recctrl/safari.c | 7 +- test/api/safari1.c | 12 ++-- 10 files changed, 309 insertions(+), 200 deletions(-) diff --git a/include/idzebra/recctrl.h b/include/idzebra/recctrl.h index d06e642..0a1d567 100644 --- a/include/idzebra/recctrl.h +++ b/include/idzebra/recctrl.h @@ -1,4 +1,4 @@ -/* $Id: recctrl.h,v 1.7 2005-01-16 23:13:06 adam Exp $ +/* $Id: recctrl.h,v 1.8 2005-03-05 09:19:14 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -38,8 +38,9 @@ typedef struct { int attrSet; int attrUse; unsigned reg_type; - char *string; - int length; + char *attrStr; + char *term_buf; + int term_len; zint seqno; zint record_id; zint section_id; diff --git a/index/extract.c b/index/extract.c index 4484cdb..84250b5 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.171 2005-01-15 19:38:25 adam Exp $ +/* $Id: extract.c,v 1.172 2005-03-05 09:19:14 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -85,6 +85,7 @@ static void extract_init (struct recExtractCtrl *p, RecWord *w) w->seqno = 1; w->attrSet = VAL_BIB1; w->attrUse = 1016; + w->attrStr = 0; w->reg_type = 'w'; w->extractCtrl = p; w->record_id = 0; @@ -1235,14 +1236,10 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, const char *src = reckeys->buf + off; struct it_key key; char *dst = (char*) &key; - int attrSet, attrUse; iscz1_decode(decode_handle, &dst, &src); assert(key.len == 4); - attrSet = (int) key.mem[0] >> 16; - attrUse = (int) key.mem[0] & 65535; - if (zh->reg->key_buf_used + 1024 > (zh->reg->ptr_top -zh->reg->ptr_i)*sizeof(char*)) extract_flushWriteKeys (zh,0); @@ -1251,11 +1248,8 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, (zh->reg->key_buf)[zh->reg->ptr_top - zh->reg->ptr_i] = (char*)zh->reg->key_buf + zh->reg->key_buf_used; - ch = zebraExplain_lookupSU (zei, attrSet, attrUse); - if (ch < 0) - ch = zebraExplain_addSU (zei, attrSet, attrUse); + ch = key.mem[0]; /* ordinal for field/use/attribute */ - assert (ch > 0); zh->reg->key_buf_used += key_SU_encode (ch,((char*)zh->reg->key_buf) + zh->reg->key_buf_used); @@ -1266,7 +1260,7 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno, ((char*)(zh->reg->key_buf))[(zh->reg->key_buf_used)++] = cmd; key.len = 3; - if (key.mem[1]) /* filter specify record ID */ + if (key.mem[1]) /* filter specified record ID */ key.mem[0] = key.mem[1]; else key.mem[0] = sysno; @@ -1426,9 +1420,7 @@ void extract_add_it_key (ZebraHandle zh, if (keys->buf_used+1024 > keys->buf_max) { - char *b; - - b = (char *) xmalloc (keys->buf_max += 128000); + char *b = (char *) xmalloc (keys->buf_max += 128000); if (keys->buf_used > 0) memcpy (b, keys->buf, keys->buf_used); xfree (keys->buf); @@ -1448,8 +1440,25 @@ void extract_add_it_key (ZebraHandle zh, void extract_add_index_string (RecWord *p, const char *str, int length) { struct it_key key; + + ZebraHandle zh = p->extractCtrl->handle; + ZebraExplainInfo zei = zh->reg->zei; + int ch; + + if (p->attrStr) + { + ch = zebraExplain_lookup_attr_str(zei, p->attrStr); + if (ch < 0) + ch = zebraExplain_add_attr_str(zei, p->attrStr); + } + else + { + ch = zebraExplain_lookup_attr_su(zei, p->attrSet, p->attrUse); + if (ch < 0) + ch = zebraExplain_add_attr_su(zei, p->attrSet, p->attrUse); + } key.len = 4; - key.mem[0] = p->attrSet * 65536 + p->attrUse; + key.mem[0] = ch; key.mem[1] = p->record_id; key.mem[2] = p->section_id; key.mem[3] = p->seqno; @@ -1513,11 +1522,11 @@ void extract_add_string (RecWord *p, const char *string, int length) static void extract_add_incomplete_field (RecWord *p) { - const char *b = p->string; - int remain = p->length; + const char *b = p->term_buf; + int remain = p->term_len; const char **map = 0; - yaz_log(YLOG_DEBUG, "Incomplete field, w='%.*s'", p->length, p->string); + yaz_log(YLOG_DEBUG, "Incomplete field, w='%.*s'", p->term_len, p->term_buf); if (remain > 0) map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain, 0); @@ -1530,7 +1539,7 @@ static void extract_add_incomplete_field (RecWord *p) /* Skip spaces */ while (map && *map && **map == *CHR_SPACE) { - remain = p->length - (b - p->string); + remain = p->term_len - (b - p->term_buf); if (remain > 0) map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain, 0); else @@ -1545,7 +1554,7 @@ static void extract_add_incomplete_field (RecWord *p) while (i < IT_MAX_WORD && *cp) buf[i++] = *(cp++); - remain = p->length - (b - p->string); + remain = p->term_len - (b - p->term_buf); if (remain > 0) map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain, 0); else @@ -1560,13 +1569,13 @@ static void extract_add_incomplete_field (RecWord *p) static void extract_add_complete_field (RecWord *p) { - const char *b = p->string; + const char *b = p->term_buf; char buf[IT_MAX_WORD+1]; const char **map = 0; - int i = 0, remain = p->length; - int first; /* first position */ + int i = 0, remain = p->term_len; - yaz_log(YLOG_DEBUG, "Complete field, w='%.*s'", p->length, p->string); + yaz_log(YLOG_DEBUG, "Complete field, w='%.*s'", + p->term_len, p->term_buf); if (remain > 0) map = zebra_maps_input (p->zebra_maps, p->reg_type, &b, remain, 1); @@ -1575,11 +1584,11 @@ static void extract_add_complete_field (RecWord *p) { while (map && *map && **map == *CHR_SPACE) { - remain = p->length - (b - p->string); + remain = p->term_len - (b - p->term_buf); if (remain > 0) { - first = i ? 0 : 1; + int first = i ? 0 : 1; /* first position */ map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain, first); } else @@ -1606,7 +1615,7 @@ static void extract_add_complete_field (RecWord *p) while (i < IT_MAX_WORD && *cp) buf[i++] = *(cp++); } - remain = p->length - (b - p->string); + remain = p->term_len - (b - p->term_buf); if (remain > 0) { map = zebra_maps_input (p->zebra_maps, p->reg_type, &b, @@ -1631,10 +1640,10 @@ void extract_token_add (RecWord *p) p->string); #endif if ((wrbuf = zebra_replace(p->zebra_maps, p->reg_type, 0, - p->string, p->length))) + p->term_buf, p->term_len))) { - p->string = wrbuf_buf(wrbuf); - p->length = wrbuf_len(wrbuf); + p->term_buf = wrbuf_buf(wrbuf); + p->term_len = wrbuf_len(wrbuf); } if (zebra_maps_is_complete (p->zebra_maps, p->reg_type)) extract_add_complete_field (p); diff --git a/index/zinfo.c b/index/zinfo.c index 3a97df9..788aaaf 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -1,4 +1,4 @@ -/* $Id: zinfo.c,v 1.44 2005-01-16 23:33:31 adam Exp $ +/* $Id: zinfo.c,v 1.45 2005-03-05 09:19:14 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -32,8 +32,16 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define ZINFO_DEBUG 0 struct zebSUInfo { - int set; - int use; +#define ZEB_SU_SET_USE 1 +#define ZEB_SU_STR 2 + int which; + union { + char *str; + struct { + int set; + int use; + } su; + } u; int ordinal; }; @@ -562,6 +570,7 @@ static void zebraExplain_readAttributeDetails (ZebraExplainInfo zei, { data1_node *node_set = NULL; data1_node *node_use = NULL; + data1_node *node_str = NULL; data1_node *node_ordinal = NULL; data1_node *np2; char oid_str[128]; @@ -578,27 +587,48 @@ static void zebraExplain_readAttributeDetails (ZebraExplainInfo zei, node_set = np2->child; else if (!strcmp (np2->u.tag.tag, "use")) node_use = np2->child; + else if (!strcmp (np2->u.tag.tag, "str")) + node_str = np2->child; else if (!strcmp (np2->u.tag.tag, "ordinal")) node_ordinal = np2->child; } - assert (node_set && node_use && node_ordinal); - - oid_str_len = node_set->u.data.len; - if (oid_str_len >= (int) sizeof(oid_str)) - oid_str_len = sizeof(oid_str)-1; - memcpy (oid_str, node_set->u.data.data, oid_str_len); - oid_str[oid_str_len] = '\0'; + assert (node_ordinal); *zsuip = (struct zebSUInfoB *) nmem_malloc (zei->nmem, sizeof(**zsuip)); - (*zsuip)->info.set = oid_getvalbyname (oid_str); + if (node_set && node_use) + { + (*zsuip)->info.which = ZEB_SU_SET_USE; + + oid_str_len = node_set->u.data.len; + if (oid_str_len >= (int) sizeof(oid_str)) + oid_str_len = sizeof(oid_str)-1; + memcpy (oid_str, node_set->u.data.data, oid_str_len); + oid_str[oid_str_len] = '\0'; - (*zsuip)->info.use = atoi_n (node_use->u.data.data, - node_use->u.data.len); + (*zsuip)->info.u.su.set = oid_getvalbyname (oid_str); + + (*zsuip)->info.u.su.use = atoi_n (node_use->u.data.data, + node_use->u.data.len); + yaz_log (YLOG_DEBUG, "set=%d use=%d ordinal=%d", + (*zsuip)->info.u.su.set, (*zsuip)->info.u.su.use, + (*zsuip)->info.ordinal); + } + else if (node_str) + { + (*zsuip)->info.which = ZEB_SU_STR; + + (*zsuip)->info.u.str = nmem_strdupn(zei->nmem, + node_str->u.data.data, + node_str->u.data.len); + } + else + { + yaz_log(YLOG_WARN, "Missng set/use/str in attribute info"); + continue; + } (*zsuip)->info.ordinal = atoi_n (node_ordinal->u.data.data, node_ordinal->u.data.len); - yaz_log (YLOG_DEBUG, "set=%d use=%d ordinal=%d", - (*zsuip)->info.set, (*zsuip)->info.use, (*zsuip)->info.ordinal); zsuip = &(*zsuip)->next; } *zsuip = NULL; @@ -880,15 +910,17 @@ static void writeAttributeValueDetails (ZebraExplainInfo zei, writeAttributeValueDetails (zei, zad, node_atvs, c->child); for (zsui = zad->SUInfo; zsui; zsui = zsui->next) { - data1_node *node_attvalue, *node_value; - if (set_ordinal != zsui->info.set) - continue; - node_attvalue = data1_mk_tag (zei->dh, zei->nmem, "attributeValue", - 0 /* attr */, node_atvs); - node_value = data1_mk_tag (zei->dh, zei->nmem, "value", - 0 /* attr */, node_attvalue); - data1_mk_tag_data_int (zei->dh, node_value, "numeric", - zsui->info.use, zei->nmem); + if (zsui->info.which == ZEB_SU_SET_USE && + set_ordinal == zsui->info.u.su.set) + { + data1_node *node_attvalue, *node_value; + node_attvalue = data1_mk_tag (zei->dh, zei->nmem, "attributeValue", + 0 /* attr */, node_atvs); + node_value = data1_mk_tag (zei->dh, zei->nmem, "value", + 0 /* attr */, node_attvalue); + data1_mk_tag_data_int (zei->dh, node_value, "numeric", + zsui->info.u.su.use, zei->nmem); + } } } @@ -999,9 +1031,10 @@ static void zebraExplain_writeAttributeDetails (ZebraExplainInfo zei, int set_ordinal = -1; for (zsui = zad->SUInfo; zsui; zsui = zsui->next) { - if ((set_ordinal < 0 || set_ordinal > zsui->info.set) - && zsui->info.set > set_min) - set_ordinal = zsui->info.set; + if (zsui->info.which == ZEB_SU_SET_USE && + (set_ordinal < 0 || set_ordinal > zsui->info.u.su.set) + && zsui->info.u.su.set > set_min) + set_ordinal = zsui->info.u.su.set; } if (set_ordinal < 0) break; @@ -1059,16 +1092,23 @@ static void zebraExplain_writeAttributeDetails (ZebraExplainInfo zei, node_attr = data1_mk_tag (zei->dh, zei->nmem, "attr", 0 /* attr */, node_list); - - oident.proto = PROTO_Z3950; - oident.oclass = CLASS_ATTSET; - oident.value = (enum oid_value) zsui->info.set; - oid_ent_to_oid (&oident, oid); - - data1_mk_tag_data_text (zei->dh, node_attr, "set", - oident.desc, zei->nmem); - data1_mk_tag_data_int (zei->dh, node_attr, "use", - zsui->info.use, zei->nmem); + if (zsui->info.which == ZEB_SU_SET_USE) + { + oident.proto = PROTO_Z3950; + oident.oclass = CLASS_ATTSET; + oident.value = (enum oid_value) zsui->info.u.su.set; + oid_ent_to_oid (&oident, oid); + + data1_mk_tag_data_text (zei->dh, node_attr, "set", + oident.desc, zei->nmem); + data1_mk_tag_data_int (zei->dh, node_attr, "use", + zsui->info.u.su.use, zei->nmem); + } + else if (zsui->info.which == ZEB_SU_STR) + { + data1_mk_tag_data_text (zei->dh, node_attr, "str", + zsui->info.u.str, zei->nmem); + } data1_mk_tag_data_int (zei->dh, node_attr, "ordinal", zsui->info.ordinal, zei->nmem); } @@ -1299,14 +1339,28 @@ static void zebraExplain_writeTarget (ZebraExplainInfo zei, int key_flush) rec_put (zei->records, &trec); } -int zebraExplain_lookupSU (ZebraExplainInfo zei, int set, int use) +int zebraExplain_lookup_attr_su(ZebraExplainInfo zei, int set, int use) { struct zebSUInfoB *zsui; assert (zei->curDatabaseInfo); for (zsui = zei->curDatabaseInfo->attributeDetails->SUInfo; zsui; zsui=zsui->next) - if (zsui->info.use == use && zsui->info.set == set) + if (zsui->info.which == ZEB_SU_SET_USE && + zsui->info.u.su.use == use && zsui->info.u.su.set == set) + return zsui->info.ordinal; + return -1; +} + +int zebraExplain_lookup_attr_str(ZebraExplainInfo zei, const char *str) +{ + struct zebSUInfoB *zsui; + + assert (zei->curDatabaseInfo); + for (zsui = zei->curDatabaseInfo->attributeDetails->SUInfo; + zsui; zsui=zsui->next) + if (zsui->info.which == ZEB_SU_STR && + !strcmp(zsui->info.u.str, str)) return zsui->info.ordinal; return -1; } @@ -1332,11 +1386,12 @@ int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord, { struct zebSUInfoB *zsui = zdb->attributeDetails->SUInfo; for ( ;zsui; zsui = zsui->next) - if (zsui->info.ordinal == ord) + if (zsui->info.which == ZEB_SU_SET_USE && + zsui->info.ordinal == ord) { *db = zdb->databaseName; - *set = zsui->info.set; - *use = zsui->info.use; + *set = zsui->info.u.su.set; + *use = zsui->info.u.su.use; return 0; } } @@ -1381,23 +1436,36 @@ void zebraExplain_addAttributeSet (ZebraExplainInfo zei, int set) } } -int zebraExplain_addSU (ZebraExplainInfo zei, int set, int use) +int zebraExplain_add_attr_su(ZebraExplainInfo zei, int set, int use) { struct zebSUInfoB *zsui; assert (zei->curDatabaseInfo); - for (zsui = zei->curDatabaseInfo->attributeDetails->SUInfo; - zsui; zsui=zsui->next) - if (zsui->info.use == use && zsui->info.set == set) - return -1; zebraExplain_addAttributeSet (zei, set); zsui = (struct zebSUInfoB *) nmem_malloc (zei->nmem, sizeof(*zsui)); zsui->next = zei->curDatabaseInfo->attributeDetails->SUInfo; zei->curDatabaseInfo->attributeDetails->SUInfo = zsui; zei->curDatabaseInfo->attributeDetails->dirty = 1; zei->dirty = 1; - zsui->info.set = set; - zsui->info.use = use; + zsui->info.which = ZEB_SU_SET_USE; + zsui->info.u.su.set = set; + zsui->info.u.su.use = use; + zsui->info.ordinal = (zei->ordinalSU)++; + return zsui->info.ordinal; +} + +int zebraExplain_add_attr_str(ZebraExplainInfo zei, const char *str) +{ + struct zebSUInfoB *zsui; + + assert (zei->curDatabaseInfo); + zsui = (struct zebSUInfoB *) nmem_malloc (zei->nmem, sizeof(*zsui)); + zsui->next = zei->curDatabaseInfo->attributeDetails->SUInfo; + zei->curDatabaseInfo->attributeDetails->SUInfo = zsui; + zei->curDatabaseInfo->attributeDetails->dirty = 1; + zei->dirty = 1; + zsui->info.which = ZEB_SU_STR; + zsui->info.u.str = nmem_strdup(zei->nmem, str); zsui->info.ordinal = (zei->ordinalSU)++; return zsui->info.ordinal; } diff --git a/index/zinfo.h b/index/zinfo.h index de8e015..f3cad35 100644 --- a/index/zinfo.h +++ b/index/zinfo.h @@ -1,4 +1,4 @@ -/* $Id: zinfo.h,v 1.21 2005-01-15 21:45:43 adam Exp $ +/* $Id: zinfo.h,v 1.22 2005-03-05 09:19:15 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -50,8 +50,10 @@ void zebraExplain_close (ZebraExplainInfo zei); int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database); int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, int explain_database); -int zebraExplain_lookupSU (ZebraExplainInfo zei, int set, int use); -int zebraExplain_addSU (ZebraExplainInfo zei, int set, int use); +int zebraExplain_lookup_attr_su(ZebraExplainInfo zei, int set, int use); +int zebraExplain_add_attr_su(ZebraExplainInfo zei, int set, int use); +int zebraExplain_lookup_attr_str(ZebraExplainInfo zei, const char *str); +int zebraExplain_add_attr_str(ZebraExplainInfo zei, const char *str); void zebraExplain_addSchema (ZebraExplainInfo zei, Odr_oid *oid); void zebraExplain_recordCountIncrement (ZebraExplainInfo zei, int adjust_num); void zebraExplain_recordBytesIncrement (ZebraExplainInfo zei, int adjust_num); diff --git a/index/zrpn.c b/index/zrpn.c index 476990c..758608b 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,4 +1,4 @@ -/* $Id: zrpn.c,v 1.169 2005-02-25 10:08:44 adam Exp $ +/* $Id: zrpn.c,v 1.170 2005-03-05 09:19:15 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -206,7 +206,7 @@ static void term_untrans(ZebraHandle zh, int reg_type, } static void add_isam_p(const char *name, const char *info, - struct grep_info *p) + struct grep_info *p) { if (!log_level_set) { @@ -958,6 +958,7 @@ static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, use_value = 1016; for (base_no = 0; base_no < num_bases; base_no++) { + int ord = -1; int attr_ok = 0; int regex_range = 0; int init_pos = 0; @@ -976,23 +977,48 @@ static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, } if (xpath_use > 0 && use_value == -2) { - use_value = xpath_use; + /* xpath mode and we have a string attribute */ attp.local_attributes = &id_xpath_attr; attp.attset_ordinal = VAL_IDXPATH; id_xpath_attr.next = 0; + + use_value = xpath_use; /* xpath_use as use-attribute now */ id_xpath_attr.local = use_value; } - else if (curAttributeSet == VAL_IDXPATH) + else if (curAttributeSet == VAL_IDXPATH && use_value >= 0) { + /* X-Path attribute, use numeric value directly */ attp.local_attributes = &id_xpath_attr; attp.attset_ordinal = VAL_IDXPATH; id_xpath_attr.next = 0; id_xpath_attr.local = use_value; } - else + else if (use_string && + (ord = zebraExplain_lookup_attr_str(zh->reg->zei, + use_string)) >= 0) + { + /* we have a match for a raw string attribute */ + char ord_buf[32]; + int i, ord_len; + + if (prefix_len) + term_dict[prefix_len++] = '|'; + else + term_dict[prefix_len++] = '('; + + ord_len = key_SU_encode (ord, ord_buf); + for (i = 0; inext) - { - int ord; - char ord_buf[32]; - int i, ord_len; - - ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal, - local_attr->local); - if (ord < 0) - continue; - if (prefix_len) - term_dict[prefix_len++] = '|'; - else - term_dict[prefix_len++] = '('; - - ord_len = key_SU_encode (ord, ord_buf); - for (i = 0; inext) + { + char ord_buf[32]; + int i, ord_len; + + ord = zebraExplain_lookup_attr_su(zh->reg->zei, + attp.attset_ordinal, + local_attr->local); + if (ord < 0) + continue; + if (prefix_len) + term_dict[prefix_len++] = '|'; + else + term_dict[prefix_len++] = '('; + + ord_len = key_SU_encode (ord, ord_buf); + for (i = 0; ireg->zei, attp.attset_ordinal, - local_attr->local); + ord = zebraExplain_lookup_attr_su(zh->reg->zei, + attp.attset_ordinal, + local_attr->local); if (ord < 0) continue; if (prefix_len) @@ -1858,7 +1885,7 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, char term_dict[2048]; char ord_buf[32]; int prefix_len = 0; - int ord = zebraExplain_lookupSU (zh->reg->zei, curAttributeSet, use); + int ord = zebraExplain_lookup_attr_su(zh->reg->zei, curAttributeSet, use); int ord_len, i, r, max_pos; int term_type = Z_Term_characterString; const char *flags = "void"; @@ -2499,8 +2526,9 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, { int ord; - ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal, - local_attr->local); + ord = zebraExplain_lookup_attr_su(zh->reg->zei, + attp.attset_ordinal, + local_attr->local); if (ord > 0) ords[ord_no++] = ord; } diff --git a/isamb/isamb.c b/isamb/isamb.c index 54181bf..ab657d7 100644 --- a/isamb/isamb.c +++ b/isamb/isamb.c @@ -1,4 +1,4 @@ -/* $Id: isamb.c,v 1.71 2005-01-16 23:14:57 adam Exp $ +/* $Id: isamb.c,v 1.72 2005-03-05 09:19:15 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -299,7 +299,7 @@ static void flush_blocks (ISAMB b, int cat) } } -static int get_block (ISAMB b, ISAMC_P pos, char *userbuf, int wr) +static int cache_block (ISAMB b, ISAMC_P pos, char *userbuf, int wr) { int cat = (int) (pos&CAT_MASK); int off = (int) (((pos/CAT_MAX) & @@ -344,7 +344,7 @@ static int get_block (ISAMB b, ISAMC_P pos, char *userbuf, int wr) *ce_last = 0; /* remove the last entry from list */ if (ce_this->dirty) { - yaz_log(b->log_io, "bf_write: get_block"); + yaz_log(b->log_io, "bf_write: cache_block"); bf_write(b->file[cat].bf, ce_this->pos, 0, 0, ce_this->buf); } xfree(ce_this->buf); @@ -355,7 +355,7 @@ static int get_block (ISAMB b, ISAMC_P pos, char *userbuf, int wr) b->file[cat].cache_entries = ce_this; ce_this->buf = xmalloc(ISAMB_CACHE_ENTRY_SIZE); ce_this->pos = norm; - yaz_log(b->log_io, "bf_read: get_block"); + yaz_log(b->log_io, "bf_read: cache_block"); if (!bf_read(b->file[cat].bf, norm, 0, 0, ce_this->buf)) memset (ce_this->buf, 0, ISAMB_CACHE_ENTRY_SIZE); if (wr) @@ -446,7 +446,7 @@ static struct ISAMB_block *open_block(ISAMB b, ISAMC_P pos) p->buf = xmalloc(b->file[cat].head.block_size); p->cbuf = 0; - if (!get_block (b, pos, p->buf, 0)) + if (!cache_block (b, pos, p->buf, 0)) { yaz_log(b->log_io, "bf_read: open_block"); if (!bf_read(b->file[cat].bf, pos/CAT_MAX, 0, 0, p->buf)) @@ -492,7 +492,7 @@ struct ISAMB_block *new_block (ISAMB b, int leaf, int cat) { p->pos = b->file[cat].head.free_list; assert((p->pos & CAT_MASK) == cat); - if (!get_block (b, p->pos, p->buf, 0)) + if (!cache_block (b, p->pos, p->buf, 0)) { yaz_log(b->log_io, "bf_read: new_block"); if (!bf_read(b->file[cat].bf, p->pos/CAT_MAX, 0, 0, p->buf)) @@ -582,7 +582,7 @@ void close_block(ISAMB b, struct ISAMB_block *p) p->pos, p->cat, p->pos/CAT_MAX); memcpy (p->buf, &b->file[p->cat].head.free_list, sizeof(zint)); b->file[p->cat].head.free_list = p->pos; - if (!get_block (b, p->pos, p->buf, 1)) + if (!cache_block (b, p->pos, p->buf, 1)) { yaz_log(b->log_io, "bf_write: close_block (deleted)"); bf_write(b->file[p->cat].bf, p->pos/CAT_MAX, 0, 0, p->buf); @@ -602,7 +602,7 @@ void close_block(ISAMB b, struct ISAMB_block *p) p->buf[2] = size >> 8; encode_ptr(&dst, p->no_items); check_block(b, p); - if (!get_block (b, p->pos, p->buf, 1)) + if (!cache_block (b, p->pos, p->buf, 1)) { yaz_log(b->log_io, "bf_write: close_block"); bf_write(b->file[p->cat].bf, p->pos/CAT_MAX, 0, 0, p->buf); diff --git a/recctrl/recgrs.c b/recctrl/recgrs.c index 4288698..b6fa493 100644 --- a/recctrl/recgrs.c +++ b/recctrl/recgrs.c @@ -1,4 +1,4 @@ -/* $Id: recgrs.c,v 1.99 2005-01-17 22:32:16 adam Exp $ +/* $Id: recgrs.c,v 1.100 2005-03-05 09:19:15 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -87,7 +87,7 @@ static int sp_range(struct source_parser *sp, data1_node *n, RecWord *wrd) /* 2nd arg: start */ if (!sp_expr(sp, n, &tmp_w)) return 0; - start = atoi_n(tmp_w.string, tmp_w.length); + start = atoi_n(tmp_w.term_buf, tmp_w.term_len); if (sp->lookahead == ',') { @@ -96,22 +96,22 @@ static int sp_range(struct source_parser *sp, data1_node *n, RecWord *wrd) /* 3rd arg: length */ if (!sp_expr(sp, n, &tmp_w)) return 0; - len = atoi_n(tmp_w.string, tmp_w.length); + len = atoi_n(tmp_w.term_buf, tmp_w.term_len); } else - len = wrd->length; + len = wrd->term_len; /* ) */ if (sp->lookahead != ')') return 0; sp_lex(sp); - if (wrd->string && wrd->length) + if (wrd->term_buf && wrd->term_len) { - wrd->string += start; - wrd->length -= start; - if (wrd->length > len) - wrd->length = len; + wrd->term_buf += start; + wrd->term_len -= start; + if (wrd->term_len > len) + wrd->term_len = len; } return 1; } @@ -134,13 +134,13 @@ static int sp_first(struct source_parser *sp, data1_node *n, RecWord *wrd) if (!sp_expr(sp, n, &search_w)) return 0; - for (i = 0; ilength; i++) + for (i = 0; iterm_len; i++) { int j; - for (j = 0; jlength; j++) - if (wrd->string[i+j] != search_w.string[j]) + for (j = 0; jterm_len; j++) + if (wrd->term_buf[i+j] != search_w.term_buf[j]) break; - if (j == search_w.length) /* match ? */ + if (j == search_w.term_len) /* match ? */ { if (min_pos == -1 || i < min_pos) min_pos = i; @@ -154,8 +154,8 @@ static int sp_first(struct source_parser *sp, data1_node *n, RecWord *wrd) if (min_pos == -1) min_pos = 0; /* the default if not found */ sprintf(num_str, "%d", min_pos); - wrd->string = nmem_strdup(sp->nmem, num_str); - wrd->length = strlen(wrd->string); + wrd->term_buf = nmem_strdup(sp->nmem, num_str); + wrd->term_len = strlen(wrd->term_buf); return 1; } @@ -167,8 +167,8 @@ static int sp_expr(struct source_parser *sp, data1_node *n, RecWord *wrd) { if (n->which == DATA1N_data) { - wrd->string = n->u.data.data; - wrd->length = n->u.data.len; + wrd->term_buf = n->u.data.data; + wrd->term_len = n->u.data.len; } sp_lex(sp); } @@ -176,8 +176,8 @@ static int sp_expr(struct source_parser *sp, data1_node *n, RecWord *wrd) { if (n->which == DATA1N_tag) { - wrd->string = n->u.tag.tag; - wrd->length = strlen(n->u.tag.tag); + wrd->term_buf = n->u.tag.tag; + wrd->term_len = strlen(n->u.tag.tag); } sp_lex(sp); } @@ -192,18 +192,18 @@ static int sp_expr(struct source_parser *sp, data1_node *n, RecWord *wrd) if (!sp_expr(sp, n, &tmp_w)) return 0; - wrd->string = ""; - wrd->length = 0; + wrd->term_buf = ""; + wrd->term_len = 0; if (n->which == DATA1N_tag) { data1_xattr *p = n->u.tag.attributes; - while (p && strlen(p->name) != tmp_w.length && - memcmp (p->name, tmp_w.string, tmp_w.length)) + while (p && strlen(p->name) != tmp_w.term_len && + memcmp (p->name, tmp_w.term_buf, tmp_w.term_len)) p = p->next; if (p) { - wrd->string = p->value; - wrd->length = strlen(p->value); + wrd->term_buf = p->value; + wrd->term_len = strlen(p->value); } } if (sp->lookahead != ')') @@ -220,22 +220,22 @@ static int sp_expr(struct source_parser *sp, data1_node *n, RecWord *wrd) } else if (sp->len > 0 && isdigit(*(unsigned char *)sp->tok)) { - wrd->string = nmem_malloc(sp->nmem, sp->len); - memcpy(wrd->string, sp->tok, sp->len); - wrd->length = sp->len; + wrd->term_buf = nmem_malloc(sp->nmem, sp->len); + memcpy(wrd->term_buf, sp->tok, sp->len); + wrd->term_len = sp->len; sp_lex(sp); } else if (sp->len > 2 && sp->tok[0] == '\'' && sp->tok[sp->len-1] == '\'') { - wrd->length = sp->len - 2; - wrd->string = nmem_malloc(sp->nmem, wrd->length); - memcpy(wrd->string, sp->tok+1, wrd->length); + wrd->term_len = sp->len - 2; + wrd->term_buf = nmem_malloc(sp->nmem, wrd->term_len); + memcpy(wrd->term_buf, sp->tok+1, wrd->term_len); sp_lex(sp); } else { - wrd->string = ""; - wrd->length = 0; + wrd->term_buf = ""; + wrd->term_len = 0; sp_lex(sp); } return 1; @@ -471,22 +471,22 @@ static void index_xpath_attr (char *tag_path, char *name, char *value, wrd->attrSet = VAL_IDXPATH; wrd->attrUse = 1; wrd->reg_type = '0'; - wrd->string = tag_path; - wrd->length = strlen(tag_path); + wrd->term_buf = tag_path; + wrd->term_len = strlen(tag_path); (*p->tokenAdd)(wrd); if (value) { wrd->attrUse = 1015; wrd->reg_type = 'w'; - wrd->string = value; - wrd->length = strlen(value); + wrd->term_buf = value; + wrd->term_len = strlen(value); (*p->tokenAdd)(wrd); } wrd->attrUse = 2; wrd->reg_type = '0'; - wrd->string = tag_path; - wrd->length = strlen(tag_path); + wrd->term_buf = tag_path; + wrd->term_len = strlen(tag_path); (*p->tokenAdd)(wrd); } @@ -512,8 +512,8 @@ static void index_xpath (struct source_parser *sp, data1_node *n, switch (n->which) { case DATA1N_data: - wrd->string = n->u.data.data; - wrd->length = n->u.data.len; + wrd->term_buf = n->u.data.data; + wrd->term_len = n->u.data.len; xpdone = 0; flen = 0; @@ -557,10 +557,10 @@ static void index_xpath (struct source_parser *sp, data1_node *n, int i; printf("%*sXPath index", (level + 1) * 4, ""); printf (" XData:\""); - for (i = 0; i 40) + if (wrd_tl.term_len > 40) printf (" ..."); fputc ('\n', stdout); } @@ -581,10 +581,10 @@ static void index_xpath (struct source_parser *sp, data1_node *n, tl->att->name, tl->att->value, tl->source); printf (" XData:\""); - for (i = 0; i 40) + if (wrd_tl.term_len > 40) printf (" ..."); fputc ('\n', stdout); } @@ -622,15 +622,15 @@ static void index_xpath (struct source_parser *sp, data1_node *n, wrd->reg_type = '0'; - wrd->string = tag_path_full; - wrd->length = flen; + wrd->term_buf = tag_path_full; + wrd->term_len = flen; wrd->attrSet = VAL_IDXPATH; wrd->attrUse = use; if (p->flagShowRecords) { printf("%*s tag=", (level + 1) * 4, ""); - for (i = 0; ilength && i < 40; i++) - fputc (wrd->string[i], stdout); + for (i = 0; iterm_len && i < 40; i++) + fputc (wrd->term_buf[i], stdout); if (i == 40) printf (" .."); printf("\n"); @@ -696,8 +696,8 @@ static void index_xpath (struct source_parser *sp, data1_node *n, /* attribute (no value) */ wrd->reg_type = '0'; wrd->attrUse = 3; - wrd->string = xp->name; - wrd->length = strlen(xp->name); + wrd->term_buf = xp->name; + wrd->term_len = strlen(xp->name); wrd->seqno--; (*p->tokenAdd)(wrd); @@ -712,8 +712,8 @@ static void index_xpath (struct source_parser *sp, data1_node *n, wrd->attrUse = 3; wrd->reg_type = '0'; - wrd->string = comb; - wrd->length = strlen(comb); + wrd->term_buf = comb; + wrd->term_len = strlen(comb); wrd->seqno--; (*p->tokenAdd)(wrd); @@ -750,8 +750,8 @@ static void index_xpath (struct source_parser *sp, data1_node *n, (tl->att->parent->reference); wrd->attrUse = tl->att->locals->local; wrd->reg_type = *tl->structure; - wrd->string = xp->value; - wrd->length = strlen(xp->value); + wrd->term_buf = xp->value; + wrd->term_len = strlen(xp->value); (*p->tokenAdd)(wrd); } } @@ -796,11 +796,11 @@ static void index_termlist (struct source_parser *sp, data1_node *par, for (; tlist; tlist = tlist->next) { /* consider source */ - wrd->string = 0; + wrd->term_buf = 0; assert(tlist->source); sp_parse(sp, n, wrd, tlist->source); - if (wrd->string && wrd->length) + if (wrd->term_buf && wrd->term_len) { if (p->flagShowRecords) { @@ -812,10 +812,10 @@ static void index_termlist (struct source_parser *sp, data1_node *par, tlist->att->name, tlist->att->value, tlist->source); printf (" XData:\""); - for (i = 0; ilength && i < 40; i++) - fputc (wrd->string[i], stdout); + for (i = 0; iterm_len && i < 40; i++) + fputc (wrd->term_buf[i], stdout); fputc ('"', stdout); - if (wrd->length > 40) + if (wrd->term_len > 40) printf (" ..."); fputc ('\n', stdout); } diff --git a/recctrl/rectext.c b/recctrl/rectext.c index be72590..3b14203 100644 --- a/recctrl/rectext.c +++ b/recctrl/rectext.c @@ -1,4 +1,4 @@ -/* $Id: rectext.c,v 1.23 2005-01-15 19:38:32 adam Exp $ +/* $Id: rectext.c,v 1.24 2005-03-05 09:19:16 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -124,8 +124,8 @@ static int text_extract (void *clientData, struct recExtractCtrl *p) } if (i) { - recWord.string = w; - recWord.length = i; + recWord.term_buf = w; + recWord.term_len = i; (*p->tokenAdd)(&recWord); } } while (r > 0); diff --git a/recctrl/safari.c b/recctrl/safari.c index 7c3582d..b3b7d6e 100644 --- a/recctrl/safari.c +++ b/recctrl/safari.c @@ -1,4 +1,4 @@ -/* $Id: safari.c,v 1.3 2005-01-15 19:38:32 adam Exp $ +/* $Id: safari.c,v 1.4 2005-03-05 09:19:16 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -139,8 +139,9 @@ static int safari_extract(void *clientData, struct recExtractCtrl *p) } for (cp = line + nor; *cp == ' '; cp++) ; - recWord.string = cp; - recWord.length = strlen(cp); + recWord.attrStr = field; + recWord.term_buf = cp; + recWord.term_len = strlen(cp); (*p->tokenAdd)(&recWord); } fi_close(fi); diff --git a/test/api/safari1.c b/test/api/safari1.c index 47c3a72..1121061 100644 --- a/test/api/safari1.c +++ b/test/api/safari1.c @@ -1,4 +1,4 @@ -/* $Id: safari1.c,v 1.3 2005-01-15 19:38:35 adam Exp $ +/* $Id: safari1.c,v 1.4 2005-03-05 09:19:16 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -50,13 +50,13 @@ int main(int argc, char **argv) ZebraHandle zh = zebra_open(zs); init_data(zh, myrec); - do_query(__LINE__, zh, "@attr 1=1016 the", 1); - do_query(__LINE__, zh, "@attr 1=1016 {the art}", 1); - do_query(__LINE__, zh, "@attr 1=1016 {den gamle}", 1); - do_query(__LINE__, zh, "@attr 1=1016 {the of}", 0); + do_query(__LINE__, zh, "@attr 1=any the", 1); + do_query(__LINE__, zh, "@attr 1=any {the art}", 1); + do_query(__LINE__, zh, "@attr 1=any {den gamle}", 1); + do_query(__LINE__, zh, "@attr 1=any {the of}", 0); ids[0] = 24338; - meta_query(__LINE__, zh, "@attr 1=1016 the", 1, ids); + meta_query(__LINE__, zh, "@attr 1=any the", 1, ids); return close_down(zh, zs, 0); } -- 1.7.10.4