X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Fzrpn.c;h=09f2d34c9aac2550527449468e3f4c1cf90d522c;hp=f3ef7a8afade7b2e8209bf42883a170efa8a2c7c;hb=53e80efb6110282ca208b459e7d947e4157f9569;hpb=6cb032fd2ece4742e3516e0941507143f677e5cd diff --git a/index/zrpn.c b/index/zrpn.c index f3ef7a8..09f2d34 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,4 +1,4 @@ -/* $Id: zrpn.c,v 1.191 2005-05-11 12:39:37 adam Exp $ +/* $Id: zrpn.c,v 1.208 2005-11-29 11:38:34 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -24,7 +24,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #ifdef WIN32 #include -#else +#endif +#if HAVE_UNISTD_H #include #endif #include @@ -50,7 +51,6 @@ typedef struct Z_AttributesPlusTerm *zapt; } AttrType; - static int log_level_set = 0; static int log_level_rpn = 0; @@ -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; @@ -173,8 +173,8 @@ struct grep_info { ZebraSet termset; }; -static void term_untrans(ZebraHandle zh, int reg_type, - char *dst, const char *src) +void zebra_term_untrans(ZebraHandle zh, int reg_type, + char *dst, const char *src) { int len = 0; while (*src) @@ -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); - 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); + zebra_term_untrans (p->zh, p->reg_type, term_tmp, name+len+1); + 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, @@ -987,7 +987,55 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, struct grep_info *grep_info, int reg_type, int complete_flag, int num_bases, char **basenames, - char *term_dst, int xpath_use); + 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 >= 0) + { + 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, @@ -1003,11 +1051,17 @@ static ZEBRA_RES term_trunc(ZebraHandle zh, struct rset_key_control *kc) { 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, - term_dst, xpath_use); + term_dst, xpath_use, &ol); if (res != ZEBRA_OK) return res; if (!*term_sub) /* no more terms ? */ @@ -1017,26 +1071,21 @@ 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); + 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, struct grep_info *grep_info, int reg_type, int complete_flag, int num_bases, char **basenames, - char *term_dst, int xpath_use) + char *term_dst, int xpath_use, + struct ord_list **ol) { char term_dict[2*IT_MAX_WORD+4000]; int j, r, base_no; @@ -1051,8 +1100,8 @@ 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); rpn_char_map_prepare (zh->reg, reg_type, &rcmi); attr_init(&use, zapt, 1); @@ -1104,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 */ @@ -1122,6 +1172,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, term_dict[prefix_len++] = ord_buf[i]; } attp.local_attributes = 0; /* no more attributes */ + *ol = ord_list_append(stream, *ol, ord); } else { @@ -1134,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 { @@ -1150,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; } @@ -1163,10 +1218,12 @@ 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) continue; + *ol = ord_list_append(stream, *ol, ord); if (prefix_len) term_dict[prefix_len++] = '|'; else @@ -1184,9 +1241,6 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, attr_ok = 1; term_dict[prefix_len++] = ')'; - term_dict[prefix_len++] = 1; - term_dict[prefix_len++] = reg_type; - yaz_log(log_level_rpn, "reg_type = %d", term_dict[prefix_len-1]); term_dict[prefix_len] = '\0'; j = prefix_len; switch (truncation_value) @@ -1323,10 +1377,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; @@ -1345,7 +1396,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; @@ -1425,50 +1476,6 @@ static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, return ZEBRA_OK; } -char *normalize_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, - const char *termz, NMEM stream, unsigned reg_id) -{ - WRBUF wrbuf = 0; - AttrType truncation; - int truncation_value; - char *ex_list = 0; - - attr_init(&truncation, zapt, 5); - truncation_value = attr_find(&truncation, NULL); - - switch (truncation_value) - { - default: - ex_list = ""; - break; - case 101: - ex_list = "#"; - break; - case 102: - case 103: - ex_list = 0; - break; - case 104: - ex_list = "!#"; - break; - case 105: - ex_list = "!*"; - break; - } - if (ex_list) - wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, ex_list, - termz, strlen(termz)); - if (!wrbuf) - return nmem_strdup(stream, termz); - else - { - char *buf = (char*) nmem_malloc(stream, wrbuf_len(wrbuf)+1); - memcpy (buf, wrbuf_buf(wrbuf), wrbuf_len(wrbuf)); - buf[wrbuf_len(wrbuf)] = '\0'; - return buf; - } -} - static void grep_info_delete(struct grep_info *grep_info) { #ifdef TERM_COUNT @@ -1523,10 +1530,26 @@ static ZEBRA_RES grep_info_prepare(ZebraHandle zh, return ZEBRA_OK; } - +/** + \brief Create result set(s) for list of terms + \param zh Zebra Handle + \param termz term as used in query but converted to UTF-8 + \param attributeSet default attribute set + \param stream memory for result + \param reg_type register type ('w', 'p',..) + \param complete_flag whether it's phrases or not + \param rank_type term flags for ranking + \param xpath_use use attribute for X-Path (-1 for no X-path) + \param num_bases number of databases + \param basenames array of databases + \param rset_mem memory for result sets + \param result_sets output result set for each term in list (output) + \param number number of output result sets + \param kc rset key control to be used for created result sets +*/ static ZEBRA_RES term_list_trunc(ZebraHandle zh, Z_AttributesPlusTerm *zapt, - const char *termz_org, + const char *termz, oid_value attributeSet, NMEM stream, int reg_type, int complete_flag, @@ -1538,7 +1561,6 @@ static ZEBRA_RES term_list_trunc(ZebraHandle zh, { char term_dst[IT_MAX_WORD+1]; struct grep_info grep_info; - char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type); const char *termp = termz; int alloc_sets = 0; @@ -1608,7 +1630,7 @@ static ZEBRA_RES rpn_search_APT_phrase(ZebraHandle zh, if (res != ZEBRA_OK) return res; if (num_result_sets == 0) - *rset = rsnull_create (rset_nmem, kc); + *rset = rsnull_create (rset_nmem, kc, 0); else if (num_result_sets == 1) *rset = result_sets[0]; else @@ -1646,11 +1668,11 @@ static ZEBRA_RES rpn_search_APT_or_list(ZebraHandle zh, if (res != ZEBRA_OK) return res; if (num_result_sets == 0) - *rset = rsnull_create (rset_nmem, kc); + *rset = rsnull_create (rset_nmem, kc, 0); else if (num_result_sets == 1) *rset = result_sets[0]; else - *rset = rsmulti_or_create(rset_nmem, kc, kc->scope, + *rset = rsmulti_or_create(rset_nmem, kc, kc->scope, 0 /* termid */, num_result_sets, result_sets); if (!*rset) return ZEBRA_FAIL; @@ -1683,7 +1705,7 @@ static ZEBRA_RES rpn_search_APT_and_list(ZebraHandle zh, if (res != ZEBRA_OK) return res; if (num_result_sets == 0) - *rset = rsnull_create (rset_nmem, kc); + *rset = rsnull_create (rset_nmem, kc, 0); else if (num_result_sets == 1) *rset = result_sets[0]; else @@ -1774,8 +1796,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); @@ -1811,20 +1831,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; } } @@ -1842,6 +1864,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) @@ -1864,10 +1887,7 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, continue; } bases_ok++; - term_dict[prefix_len++] = ')'; - term_dict[prefix_len++] = 1; - term_dict[prefix_len++] = reg_type; - yaz_log(YLOG_DEBUG, "reg_type = %d", term_dict[prefix_len-1]); + term_dict[prefix_len++] = ')'; term_dict[prefix_len] = '\0'; if (!numeric_relation(zh, zapt, &termp, term_dict, attributeSet, grep_info, &max_pos, reg_type, @@ -1883,15 +1903,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, @@ -1911,6 +1929,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) @@ -1942,7 +1964,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); + kc, kc->scope, 0, reg_type, + hits_limit_value, + term_ref_id_str); if (!result_sets[num_result_sets]) break; num_result_sets++; @@ -1956,7 +1980,7 @@ static ZEBRA_RES rpn_search_APT_numeric(ZebraHandle zh, return ZEBRA_FAIL; } if (num_result_sets == 0) - *rset = rsnull_create(rset_nmem, kc); + *rset = rsnull_create(rset_nmem, kc, 0); if (num_result_sets == 1) *rset = result_sets[0]; else @@ -1998,6 +2022,7 @@ static ZEBRA_RES rpn_sort_spec(ZebraHandle zh, Z_AttributesPlusTerm *zapt, oid_value attributeSet, NMEM stream, Z_SortKeySpecList *sort_sequence, const char *rank_type, + NMEM rset_nmem, RSET *rset, struct rset_key_control *kc) { @@ -2066,7 +2091,7 @@ static ZEBRA_RES rpn_sort_spec(ZebraHandle zh, Z_AttributesPlusTerm *zapt, sks->which = Z_SortKeySpec_null; sks->u.null = odr_nullval (); sort_sequence->specs[i] = sks; - *rset = rsnull_create (NULL, kc); + *rset = rsnull_create (rset_nmem, kc, 0); return ZEBRA_OK; } @@ -2100,16 +2125,17 @@ 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"; if (grep_info_prepare(zh, 0 /* zapt */, &grep_info, '0') == ZEBRA_FAIL) - return rsnull_create(rset_nmem, kc); + return rsnull_create(rset_nmem, kc, 0); if (ord < 0) - return rsnull_create(rset_nmem, kc); + return rsnull_create(rset_nmem, kc, 0); if (prefix_len) term_dict[prefix_len++] = '|'; else @@ -2122,9 +2148,6 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, term_dict[prefix_len++] = ord_buf[i]; } term_dict[prefix_len++] = ')'; - term_dict[prefix_len++] = 1; - term_dict[prefix_len++] = reg_type; - strcpy(term_dict+prefix_len, term); grep_info.isam_p_indx = 0; @@ -2135,7 +2158,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); + kc, kc->scope, 0, reg_type, 0 /* hits_limit */, + 0 /* term_ref_id_str */); grep_info_delete(&grep_info); return rset; } @@ -2327,15 +2351,24 @@ static ZEBRA_RES rpn_search_APT(ZebraHandle zh, Z_AttributesPlusTerm *zapt, if (sort_flag) return rpn_sort_spec(zh, zapt, attributeSet, stream, sort_sequence, - rank_type, rset, kc); + rank_type, rset_nmem, rset, kc); + /* consider if an X-Path query is used */ xpath_len = parse_xpath(zh, zapt, attributeSet, xpath, 10, stream); if (xpath_len >= 0) { - xpath_use = 1016; - if (xpath[xpath_len-1].part[0] == '@') - xpath_use = 1015; - } - + xpath_use = 1016; /* searching for element by default */ + if (xpath[xpath_len-1].part[0] == '@') + xpath_use = 1015; /* last step an attribute .. */ + } + + /* search using one of the various search type strategies + termz is our UTF-8 search term + attributeSet is top-level default attribute set + stream is ODR for search + reg_id is the register type + complete_flag is 1 for complete subfield, 0 for incomplete + xpath_use is use-attribute to be used for X-Path search, 0 for none + */ if (!strcmp(search_type, "phrase")) { res = rpn_search_APT_phrase(zh, zapt, termz, attributeSet, stream, @@ -2506,7 +2539,7 @@ ZEBRA_RES rpn_search_structure(ZebraHandle zh, Z_RPNStructure *zs, break; case Z_Operator_or: rset = rsmulti_or_create(rset_nmem, kc, - kc->scope, + kc->scope, 0, /* termid */ *num_result_sets, *result_sets); break; case Z_Operator_and_not: @@ -2633,13 +2666,13 @@ static int scan_handle (char *name, const char *info, int pos, void *client) return 0; } -static void scan_term_untrans (ZebraHandle zh, NMEM stream, int reg_type, - char **dst, const char *src) +void zebra_term_untrans_iconv(ZebraHandle zh, NMEM stream, int reg_type, + char **dst, const char *src) { char term_src[IT_MAX_WORD]; char term_dst[IT_MAX_WORD]; - term_untrans (zh, reg_type, term_src, src); + zebra_term_untrans (zh, reg_type, term_src, src); if (zh->iconv_from_utf8 != 0) { @@ -2665,28 +2698,29 @@ static void scan_term_untrans (ZebraHandle zh, NMEM stream, int reg_type, *dst = nmem_strdup(stream, term_src); } -static void count_set (RSET r, int *count) +static void count_set(ZebraHandle zh, RSET rset, zint *count) { zint psysno = 0; - int kno = 0; struct it_key key; RSFD rfd; yaz_log(YLOG_DEBUG, "count_set"); + rset->hits_limit = zh->approx_limit; + *count = 0; - rfd = rset_open (r, RSETF_READ); - while (rset_read (rfd, &key,0 /* never mind terms */)) + rfd = rset_open(rset, RSETF_READ); + while (rset_read(rfd, &key,0 /* never mind terms */)) { if (key.mem[0] != psysno) { psysno = key.mem[0]; - (*count)++; + if (rfd->counted_items >= rset->hits_limit) + break; } - kno++; } rset_close (rfd); - yaz_log(YLOG_DEBUG, "%d keys, %d records", kno, *count); + *count = rset->hits_count; } ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, @@ -2786,7 +2820,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 */ @@ -2824,7 +2858,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) @@ -2878,7 +2912,6 @@ 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); - termz[prefix_len++] = reg_id; termz[prefix_len] = 0; strcpy(scan_info->prefix, termz); @@ -2925,12 +2958,13 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, if (lo >= 0) { /* get result set for first term */ - scan_term_untrans(zh, stream->mem, reg_id, - &glist[lo].term, mterm); + zebra_term_untrans_iconv(zh, stream->mem, reg_id, + &glist[lo].term, mterm); 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); + 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 */ @@ -2951,15 +2985,18 @@ 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); + kc, kc->scope, 0, reg_id, 0 /* hits_limit */, + 0 /* term_ref_id_str */ ); rset = rsmulti_or_create(rset_nmem, kc, - 2, kc->scope, rsets); + kc->scope, 0 /* termid */, + 2, rsets); } ptr[j]++; } } if (lo >= 0) { + zint count; /* merge with limit_set if given */ if (limit_set) { @@ -2968,10 +3005,12 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, rsets[1] = rset_dup(limit_set); rset = rsmulti_and_create(rset_nmem, kc, - kc->scope, 2, rsets); + kc->scope, + 2, rsets); } /* count it */ - count_set(rset, &glist[lo].occurrences); + count_set(zh, rset, &count); + glist[lo].occurrences = count; rset_delete(rset); } } @@ -2998,6 +3037,7 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, const char *tst; RSET rset; int lo = before-1-i; /* offset in result list */ + zint count; for (j = 0; j mem, reg_id, - &glist[lo].term, mterm); + zebra_term_untrans_iconv(zh, stream->mem, reg_id, + &glist[lo].term, mterm); rset = rset_trunc (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); + NULL, 0, zapt->term->which, rset_nmem, + kc, kc->scope, 0, reg_id, 0 /* hits_limit */, + 0 /* term_ref_id_str */); ptr[j0]++; @@ -3038,9 +3079,10 @@ 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); + kc, kc->scope, 0, reg_id, 0 /* hits_limit */, + 0 /* term_ref_id_str */); rset = rsmulti_or_create(rset_nmem, kc, - 2, kc->scope, rsets); + kc->scope, 0 /* termid */, 2, rsets); ptr[j]++; } @@ -3054,7 +3096,8 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, rset = rsmulti_and_create(rset_nmem, kc, kc->scope, 2, rsets); } - count_set (rset, &glist[lo].occurrences); + count_set(zh, rset, &count); + glist[lo].occurrences = count; rset_delete (rset); } (*kc->dec)(kc);