X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzrpn.c;h=db339e5569884a884b86ffc6293a1f98c4216a27;hb=ff83da9583191588c5816189b55966a6bb057d71;hp=9927949690ce70432bb8a6d878f98d3c848fab0d;hpb=47eeb5384a8fae8bcac8afb8a84782ca094683f9;p=idzebra-moved-to-github.git diff --git a/index/zrpn.c b/index/zrpn.c index 9927949..db339e5 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,4 +1,4 @@ -/* $Id: zrpn.c,v 1.200 2005-06-14 20:28:54 adam Exp $ +/* $Id: zrpn.c,v 1.206 2005-11-02 11:43:26 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -82,7 +82,7 @@ static void rpn_char_map_prepare(struct zebra_register *reg, int reg_type, } static int attr_find_ex(AttrType *src, oid_value *attributeSetP, - const char **string_value) + const char **string_value) { int num_attributes; @@ -235,13 +235,13 @@ static void add_isam_p(const char *name, const char *info, const char *db; int set, use; char term_tmp[IT_MAX_WORD]; - int su_code = 0; - int len = key_SU_decode (&su_code, name); + int ord = 0; + int len = key_SU_decode (&ord, (const unsigned char *) name); zebra_term_untrans (p->zh, p->reg_type, term_tmp, name+len+1); - yaz_log(log_level_rpn, "grep: %d %c %s", su_code, name[len], term_tmp); + yaz_log(log_level_rpn, "grep: %d %c %s", ord, name[len], term_tmp); zebraExplain_lookup_ord (p->zh->reg->zei, - su_code, &db, &set, &use); + ord, 0 /* index_type */, &db, &set, &use); yaz_log(log_level_rpn, "grep: set=%d use=%d db=%s", set, use, db); resultSetAddTerm(p->zh, p->termset, name[len], db, @@ -990,6 +990,53 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, char *term_dst, int xpath_use, struct ord_list **ol); +static ZEBRA_RES term_limits_APT(ZebraHandle zh, + Z_AttributesPlusTerm *zapt, + zint *hits_limit_value, + const char **term_ref_id_str, + NMEM nmem) +{ + AttrType term_ref_id_attr; + AttrType hits_limit_attr; + int term_ref_id_int; + + attr_init(&hits_limit_attr, zapt, 9); + *hits_limit_value = attr_find(&hits_limit_attr, NULL); + + attr_init(&term_ref_id_attr, zapt, 10); + term_ref_id_int = attr_find_ex(&term_ref_id_attr, NULL, term_ref_id_str); + if (term_ref_id_int != -1) + { + char *res = nmem_malloc(nmem, 20); + sprintf(res, "%d", term_ref_id_int); + *term_ref_id_str = res; + } + + /* no limit given ? */ + if (*hits_limit_value == -1) + { + if (*term_ref_id_str) + { + /* use global if term_ref is present */ + *hits_limit_value = zh->approx_limit; + } + else + { + /* no counting if term_ref is not present */ + *hits_limit_value = 0; + } + } + else if (*hits_limit_value == 0) + { + /* 0 is the same as global limit */ + *hits_limit_value = zh->approx_limit; + } + yaz_log(YLOG_DEBUG, "term_limits_APT ref_id=%s limit=" ZINT_FORMAT, + *term_ref_id_str ? *term_ref_id_str : "none", + *hits_limit_value); + return ZEBRA_OK; +} + static ZEBRA_RES term_trunc(ZebraHandle zh, Z_AttributesPlusTerm *zapt, const char **term_sub, @@ -1005,7 +1052,12 @@ static ZEBRA_RES term_trunc(ZebraHandle zh, { ZEBRA_RES res; struct ord_list *ol; + zint hits_limit_value; + const char *term_ref_id_str = 0; *rset = 0; + + term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str, + stream); grep_info->isam_p_indx = 0; res = string_term(zh, zapt, term_sub, attributeSet, stream, grep_info, reg_type, complete_flag, num_bases, basenames, @@ -1019,19 +1071,13 @@ static ZEBRA_RES term_trunc(ZebraHandle zh, grep_info->isam_p_indx, term_dst, strlen(term_dst), rank_type, 1 /* preserve pos */, zapt->term->which, rset_nmem, - kc, kc->scope, ol, reg_type); + kc, kc->scope, ol, reg_type, hits_limit_value, + term_ref_id_str); if (!*rset) return ZEBRA_FAIL; return ZEBRA_OK; } -static char *nmem_strdup_i(NMEM nmem, int v) -{ - char val_str[64]; - sprintf(val_str, "%d", v); - return nmem_strdup(nmem, val_str); -} - static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, const char **term_sub, oid_value attributeSet, NMEM stream, @@ -1054,9 +1100,6 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, int space_split = complete_flag ? 0 : 1; int bases_ok = 0; /* no of databases with OK attribute */ - int errCode = 0; /* err code (if any is not OK) */ - char *errString = 0; /* addinfo */ - *ol = ord_list_create(stream); @@ -1110,6 +1153,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, } else if (use_string && (ord = zebraExplain_lookup_attr_str(zh->reg->zei, + reg_type, use_string)) >= 0) { /* we have a match for a raw string attribute */ @@ -1141,11 +1185,13 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, if (r == -1) { /* set was found, but value wasn't defined */ - errCode = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE; if (use_string) - errString = nmem_strdup(stream, use_string); + zebra_setError(zh, + YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, + use_string); else - errString = nmem_strdup_i (stream, use_value); + zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, + use_value); } else { @@ -1157,8 +1203,10 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, oident.value = curAttributeSet; oid_ent_to_oid (&oident, oid); - errCode = YAZ_BIB1_UNSUPP_ATTRIBUTE_SET; - errString = nmem_strdup(stream, oident.desc); + zebra_setError(zh, + YAZ_BIB1_UNSUPP_ATTRIBUTE_SET, + oident.desc); + } continue; } @@ -1170,6 +1218,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, int i, ord_len; ord = zebraExplain_lookup_attr_su(zh->reg->zei, + reg_type, attp.attset_ordinal, local_attr->local); if (ord < 0) @@ -1192,9 +1241,11 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, attr_ok = 1; term_dict[prefix_len++] = ')'; +#if REG_TYPE_PREFIX term_dict[prefix_len++] = 1; term_dict[prefix_len++] = reg_type; yaz_log(log_level_rpn, "reg_type = %d", term_dict[prefix_len-1]); +#endif term_dict[prefix_len] = '\0'; j = prefix_len; switch (truncation_value) @@ -1331,10 +1382,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, } } if (!bases_ok) - { - zebra_setError(zh, errCode, errString); return ZEBRA_FAIL; - } *term_sub = termp; yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx); return ZEBRA_OK; @@ -1353,7 +1401,7 @@ static ZEBRA_RES zapt_term_to_utf8(ZebraHandle zh, Z_AttributesPlusTerm *zapt, case Z_Term_general: if (zh->iconv_to_utf8 != 0) { - char *inbuf = term->u.general->buf; + char *inbuf = (char *) term->u.general->buf; size_t inleft = term->u.general->len; char *outbuf = termz; size_t outleft = IT_MAX_WORD-1; @@ -1753,8 +1801,6 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, struct rpn_char_map_info rcmi; int bases_ok = 0; /* no of databases with OK attribute */ - int errCode = 0; /* err code (if any is not OK) */ - char *errString = 0; /* addinfo */ rpn_char_map_prepare (zh->reg, reg_type, &rcmi); attr_init(&use, zapt, 1); @@ -1790,20 +1836,22 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, else { if ((r = att_getentbyatt (zh, &attp, curAttributeSet, use_value, - use_string))) + use_string))) { yaz_log(YLOG_DEBUG, "att_getentbyatt fail. set=%d use=%d r=%d", curAttributeSet, use_value, r); if (r == -1) { - errCode = YAZ_BIB1_UNSUPP_USE_ATTRIBUTE; if (use_string) - errString = nmem_strdup(stream, use_string); + zebra_setError(zh, + YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, + use_string); else - errString = nmem_strdup_i (stream, use_value); + zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, + use_value); } else - errCode = YAZ_BIB1_UNSUPP_ATTRIBUTE_SET; + zebra_setError(zh, YAZ_BIB1_UNSUPP_ATTRIBUTE_SET, 0); continue; } } @@ -1821,6 +1869,7 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, int i, ord_len; ord = zebraExplain_lookup_attr_su(zh->reg->zei, + reg_type, attp.attset_ordinal, local_attr->local); if (ord < 0) @@ -1843,10 +1892,12 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, continue; } bases_ok++; - term_dict[prefix_len++] = ')'; + term_dict[prefix_len++] = ')'; +#if REG_TYPE_PREFIX term_dict[prefix_len++] = 1; term_dict[prefix_len++] = reg_type; yaz_log(YLOG_DEBUG, "reg_type = %d", term_dict[prefix_len-1]); +#endif term_dict[prefix_len] = '\0'; if (!numeric_relation(zh, zapt, &termp, term_dict, attributeSet, grep_info, &max_pos, reg_type, @@ -1862,15 +1913,13 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, } } if (!bases_ok) - { - zebra_setError(zh, errCode, errString); return ZEBRA_FAIL; - } *term_sub = termp; yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx); return ZEBRA_OK; } + static ZEBRA_RES rpn_search_APT_numeric(ZebraHandle zh, Z_AttributesPlusTerm *zapt, const char *termz, @@ -1890,6 +1939,10 @@ static ZEBRA_RES rpn_search_APT_numeric(ZebraHandle zh, ZEBRA_RES res; struct grep_info grep_info; int alloc_sets = 0; + zint hits_limit_value; + const char *term_ref_id_str = 0; + + term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str, stream); yaz_log(log_level_rpn, "APT_numeric t='%s'", termz); if (grep_info_prepare(zh, zapt, &grep_info, reg_type) == ZEBRA_FAIL) @@ -1921,7 +1974,9 @@ static ZEBRA_RES rpn_search_APT_numeric(ZebraHandle zh, strlen(term_dst), rank_type, 0 /* preserve position */, zapt->term->which, rset_nmem, - kc, kc->scope, 0, reg_type); + kc, kc->scope, 0, reg_type, + hits_limit_value, + term_ref_id_str); if (!result_sets[num_result_sets]) break; num_result_sets++; @@ -2080,7 +2135,8 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, char term_dict[2048]; char ord_buf[32]; int prefix_len = 0; - int ord = zebraExplain_lookup_attr_su(zh->reg->zei, curAttributeSet, use); + int ord = zebraExplain_lookup_attr_su(zh->reg->zei, reg_type, + curAttributeSet, use); int ord_len, i, r, max_pos; int term_type = Z_Term_characterString; const char *flags = "void"; @@ -2102,9 +2158,10 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, term_dict[prefix_len++] = ord_buf[i]; } term_dict[prefix_len++] = ')'; +#if REG_TYPE_PREFIX term_dict[prefix_len++] = 1; term_dict[prefix_len++] = reg_type; - +#endif strcpy(term_dict+prefix_len, term); grep_info.isam_p_indx = 0; @@ -2115,7 +2172,8 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, rset = rset_trunc(zh, grep_info.isam_p_buf, grep_info.isam_p_indx, term, strlen(term), flags, 1, term_type,rset_nmem, - kc, kc->scope, 0, reg_type); + kc, kc->scope, 0, reg_type, 0 /* hits_limit */, + 0 /* term_ref_id_str */); grep_info_delete(&grep_info); return rset; } @@ -2776,7 +2834,7 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, } if (use_string && - (ord = zebraExplain_lookup_attr_str(zh->reg->zei, + (ord = zebraExplain_lookup_attr_str(zh->reg->zei, reg_id, use_string)) >= 0) { /* we have a match for a raw string attribute */ @@ -2814,7 +2872,7 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, for (local_attr = attp.local_attributes; local_attr && ord_no < 32; local_attr = local_attr->next) { - ord = zebraExplain_lookup_attr_su(zh->reg->zei, + ord = zebraExplain_lookup_attr_su(zh->reg->zei, reg_id, attp.attset_ordinal, local_attr->local); if (ord > 0) @@ -2868,7 +2926,9 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, scan_info->list[j].term = NULL; prefix_len += key_SU_encode (ords[i], termz + prefix_len); +#if REG_TYPE_PREFIX termz[prefix_len++] = reg_id; +#endif termz[prefix_len] = 0; strcpy(scan_info->prefix, termz); @@ -2920,7 +2980,8 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, rset = rset_trunc(zh, &scan_info_array[j0].list[ptr[j0]].isam_p, 1, glist[lo].term, strlen(glist[lo].term), NULL, 0, zapt->term->which, rset_nmem, - kc, kc->scope, 0, reg_id); + kc, kc->scope, 0, reg_id, 0 /* hits_limit */, + 0 /* term_ref_id_str */); } ptr[j0]++; /* move index for this set .. */ /* get result set for remaining scan terms */ @@ -2941,7 +3002,8 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, glist[lo].term, strlen(glist[lo].term), NULL, 0, zapt->term->which,rset_nmem, - kc, kc->scope, 0, reg_id); + kc, kc->scope, 0, reg_id, 0 /* hits_limit */, + 0 /* term_ref_id_str */ ); rset = rsmulti_or_create(rset_nmem, kc, kc->scope, 0 /* termid */, 2, rsets); @@ -3014,7 +3076,8 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, (zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1, glist[lo].term, strlen(glist[lo].term), NULL, 0, zapt->term->which, rset_nmem, - kc, kc->scope, 0, reg_id); + kc, kc->scope, 0, reg_id, 0 /* hits_limit */, + 0 /* term_ref_id_str */); ptr[j0]++; @@ -3033,7 +3096,8 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, glist[lo].term, strlen(glist[lo].term), NULL, 0, zapt->term->which, rset_nmem, - kc, kc->scope, 0, reg_id); + kc, kc->scope, 0, reg_id, 0 /* hits_limit */, + 0 /* term_ref_id_str */); rset = rsmulti_or_create(rset_nmem, kc, kc->scope, 0 /* termid */, 2, rsets);