X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Fzrpn.c;h=caccbcde3be959f469a137d49b8b7c2b8e6cffec;hp=8dbb231282d8db8bbf68d753056711a6ebd33989;hb=ecf94fc25324414287d3bbfbeba4440e558edd17;hpb=0aa335e5f7fddc3b5996598de19113ddf3050a07 diff --git a/index/zrpn.c b/index/zrpn.c index 8dbb231..caccbcd 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,6 +1,6 @@ -/* $Id: zrpn.c,v 1.166 2005-01-15 19:22:27 adam Exp $ +/* $Id: zrpn.c,v 1.173 2005-04-13 13:03:47 adam Exp $ Copyright (C) 1995-2005 - Index Data Aps + Index Data ApS This file is part of the Zebra server. @@ -66,8 +66,8 @@ typedef struct } AttrType; -static int log_level_set=0; -static int log_level_rpn=0; +static int log_level_set = 0; +static int log_level_rpn = 0; static const char **rpn_char_map_handler(void *vp, const char **from, int len) { @@ -180,7 +180,7 @@ struct grep_info { #ifdef TERM_COUNT int *term_no; #endif - ISAMC_P *isam_p_buf; + ISAM_P *isam_p_buf; int isam_p_size; int isam_p_indx; ZebraHandle zh; @@ -195,7 +195,7 @@ static void term_untrans(ZebraHandle zh, int reg_type, while (*src) { const char *cp = zebra_maps_output(zh->reg->zebra_maps, - reg_type, &src); + reg_type, &src); if (!cp && len < IT_MAX_WORD-1) dst[len++] = *src++; else @@ -206,22 +206,22 @@ 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) { log_level_rpn = yaz_log_module_level("rpn"); - log_level_set=1; + log_level_set = 1; } if (p->isam_p_indx == p->isam_p_size) { - ISAMC_P *new_isam_p_buf; + ISAM_P *new_isam_p_buf; #ifdef TERM_COUNT int *new_term_no; #endif p->isam_p_size = 2*p->isam_p_size + 100; - new_isam_p_buf = (ISAMC_P *) xmalloc(sizeof(*new_isam_p_buf) * - p->isam_p_size); + new_isam_p_buf = (ISAM_P *) xmalloc(sizeof(*new_isam_p_buf) * + p->isam_p_size); if (p->isam_p_buf) { memcpy(new_isam_p_buf, p->isam_p_buf, @@ -231,8 +231,7 @@ static void add_isam_p(const char *name, const char *info, p->isam_p_buf = new_isam_p_buf; #ifdef TERM_COUNT - new_term_no = (int *) xmalloc(sizeof(*new_term_no) * - p->isam_p_size); + new_term_no = (int *) xmalloc(sizeof(*new_term_no) * p->isam_p_size); if (p->term_no) { memcpy(new_term_no, p->isam_p_buf, @@ -296,14 +295,41 @@ static int term_pre(ZebraMaps zebra_maps, int reg_type, const char **src, return *s0; } + +static void esc_str(char *out_buf, int out_size, + const char *in_buf, int in_size) +{ + int k; + + assert(out_buf); + assert(in_buf); + assert(out_size > 20); + *out_buf = '\0'; + for (k = 0; k 126) + pc = '?'; + else + pc = c; + sprintf(out_buf +strlen(out_buf), "%02X:%c ", c, pc); + if (strlen(out_buf) > out_size-20) + { + strcat(out_buf, ".."); + break; + } + } +} + #define REGEX_CHARS " []()|.*+?!" -/* term_100: handle term, where trunc=none(no operators at all) */ +/* term_100: handle term, where trunc = none(no operators at all) */ static int term_100(ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term) { - const char *s0, *s1; + const char *s0; const char **map; int i = 0; int j = 0; @@ -316,8 +342,10 @@ static int term_100(ZebraMaps zebra_maps, int reg_type, s0 = *src; while (*s0) { - s1 = s0; - map = zebra_maps_input(zebra_maps, reg_type, &s0, strlen(s0), 0); + const char *s1 = s0; + int q_map_match = 0; + map = zebra_maps_search(zebra_maps, reg_type, &s0, strlen(s0), + &q_map_match); if (space_split) { if (**map == *CHR_SPACE) @@ -344,14 +372,26 @@ static int term_100(ZebraMaps zebra_maps, int reg_type, space_start = space_end = 0; } } - /* add non-space char */ - while (s1 < s0) - { - if (strchr(REGEX_CHARS, *s1)) - dst[i++] = '\\'; - dst_term[j++] = *s1; - dst[i++] = *s1++; - } + /* add non-space char */ + memcpy(dst_term+j, s1, s0 - s1); + j += (s0 - s1); + if (!q_map_match) + { + while (s1 < s0) + { + if (strchr(REGEX_CHARS, *s1)) + dst[i++] = '\\'; + dst[i++] = *s1++; + } + } + else + { + char tmpbuf[80]; + esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); + + strcpy(dst + i, map[0]); + i += strlen(map[0]); + } } dst[i] = '\0'; dst_term[j] = '\0'; @@ -359,12 +399,12 @@ static int term_100(ZebraMaps zebra_maps, int reg_type, return i; } -/* term_101: handle term, where trunc=Process # */ +/* term_101: handle term, where trunc = Process # */ static int term_101(ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term) { - const char *s0, *s1; + const char *s0; const char **map; int i = 0; int j = 0; @@ -382,17 +422,33 @@ static int term_101(ZebraMaps zebra_maps, int reg_type, } else { - s1 = s0; - map = zebra_maps_input(zebra_maps, reg_type, &s0, strlen(s0), 0); + const char *s1 = s0; + int q_map_match = 0; + map = zebra_maps_search(zebra_maps, reg_type, &s0, strlen(s0), + &q_map_match); if (space_split && **map == *CHR_SPACE) break; - while (s1 < s0) - { - if (strchr(REGEX_CHARS, *s1)) - dst[i++] = '\\'; - dst_term[j++] = *s1; - dst[i++] = *s1++; - } + + /* add non-space char */ + memcpy(dst_term+j, s1, s0 - s1); + j += (s0 - s1); + if (!q_map_match) + { + while (s1 < s0) + { + if (strchr(REGEX_CHARS, *s1)) + dst[i++] = '\\'; + dst[i++] = *s1++; + } + } + else + { + char tmpbuf[80]; + esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); + + strcpy(dst + i, map[0]); + i += strlen(map[0]); + } } } dst[i] = '\0'; @@ -401,14 +457,14 @@ static int term_101(ZebraMaps zebra_maps, int reg_type, return i; } -/* term_103: handle term, where trunc=re-2 (regular expressions) */ +/* term_103: handle term, where trunc = re-2 (regular expressions) */ static int term_103(ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int *errors, int space_split, char *dst_term) { int i = 0; int j = 0; - const char *s0, *s1; + const char *s0; const char **map; if (!term_pre(zebra_maps, reg_type, src, "^\\()[].*+?|", "(", !space_split)) @@ -431,26 +487,43 @@ static int term_103(ZebraMaps zebra_maps, int reg_type, const char **src, } else { - s1 = s0; - map = zebra_maps_input(zebra_maps, reg_type, &s0, strlen(s0), 0); - if (**map == *CHR_SPACE) + const char *s1 = s0; + int q_map_match = 0; + map = zebra_maps_search(zebra_maps, reg_type, &s0, strlen(s0), + &q_map_match); + if (space_split && **map == *CHR_SPACE) break; - while (s1 < s0) - { - if (strchr(REGEX_CHARS, *s1)) - dst[i++] = '\\'; - dst_term[j++] = *s1; - dst[i++] = *s1++; - } + + /* add non-space char */ + memcpy(dst_term+j, s1, s0 - s1); + j += (s0 - s1); + if (!q_map_match) + { + while (s1 < s0) + { + if (strchr(REGEX_CHARS, *s1)) + dst[i++] = '\\'; + dst[i++] = *s1++; + } + } + else + { + char tmpbuf[80]; + esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); + + strcpy(dst + i, map[0]); + i += strlen(map[0]); + } } } dst[i] = '\0'; dst_term[j] = '\0'; *src = s0; + return i; } -/* term_103: handle term, where trunc=re-1 (regular expressions) */ +/* term_103: handle term, where trunc = re-1 (regular expressions) */ static int term_102 (ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term) { @@ -459,7 +532,7 @@ static int term_102 (ZebraMaps zebra_maps, int reg_type, const char **src, } -/* term_104: handle term, where trunc=Process # and ! */ +/* term_104: handle term, where trunc = Process # and ! */ static int term_104(ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term) @@ -510,6 +583,7 @@ static int term_104(ZebraMaps zebra_maps, int reg_type, dst[i++] = '.'; dst_term[j++] = *s0++; } + else { s1 = s0; map = zebra_maps_input(zebra_maps, reg_type, &s0, strlen(s0), 0); @@ -530,7 +604,7 @@ static int term_104(ZebraMaps zebra_maps, int reg_type, return i; } -/* term_105/106: handle term, where trunc=Process * and ! and right trunc */ +/* term_105/106: handle term, where trunc = Process * and ! and right trunc */ static int term_105 (ZebraMaps zebra_maps, int reg_type, const char **src, char *dst, int space_split, char *dst_term, int right_truncate) @@ -556,6 +630,7 @@ static int term_105 (ZebraMaps zebra_maps, int reg_type, dst[i++] = '.'; dst_term[j++] = *s0++; } + else { s1 = s0; map = zebra_maps_input(zebra_maps, reg_type, &s0, strlen(s0), 0); @@ -682,7 +757,7 @@ static void gen_regular_rel(char *dst, int val, int islt) { /* match everything less than 10^(pos-1) */ strcat(dst, "0*"); - for (i=1; i 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->dict, term_dict, regex_range, grep_info, &max_pos, init_pos, @@ -1436,8 +1543,8 @@ static RSET rpn_search_APT_or_list (ZebraHandle zh, grep_info_delete (&grep_info); if (rset_no == 0) return rsnull_create (rset_nmem,key_it_ctrl); - return rsmultior_create(rset_nmem, key_it_ctrl,key_it_ctrl->scope, - rset_no, rset); + return rsmulti_or_create(rset_nmem, key_it_ctrl,key_it_ctrl->scope, + rset_no, rset); } static RSET rpn_search_APT_and_list (ZebraHandle zh, @@ -1474,10 +1581,10 @@ static RSET rpn_search_APT_and_list (ZebraHandle zh, } grep_info_delete (&grep_info); if (rset_no == 0) - return rsnull_create (rset_nmem,key_it_ctrl); - - return rsmultiand_create( rset_nmem, key_it_ctrl, key_it_ctrl->scope, - rset_no, rset); + return rsnull_create(rset_nmem,key_it_ctrl); + + return rsmulti_and_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, + rset_no, rset); } static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, @@ -1531,7 +1638,7 @@ static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt, r = dict_lookup_grep(zh->reg->dict, term_dict, 0, grep_info, max_pos, 0, grep_handle); if (r) - yaz_log(YLOG_WARN, "dict_lookup_grep fail, rel=gt: %d", r); + yaz_log(YLOG_WARN, "dict_lookup_grep fail, rel = gt: %d", r); yaz_log(log_level_rpn, "%d positions", grep_info->isam_p_indx); return 1; } @@ -1588,7 +1695,7 @@ static int numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, } else { - if ((r=att_getentbyatt (zh, &attp, curAttributeSet, use_value, + if ((r = att_getentbyatt (zh, &attp, curAttributeSet, use_value, use_string))) { yaz_log(YLOG_DEBUG, "att_getentbyatt fail. set=%d use=%d r=%d", @@ -1616,8 +1723,9 @@ static int numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, char ord_buf[32]; int i, ord_len; - 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) continue; if (prefix_len) @@ -1702,11 +1810,11 @@ static RSET rpn_search_APT_numeric (ZebraHandle zh, } grep_info_delete (&grep_info); if (rset_no == 0) - return rsnull_create (rset_nmem,key_it_ctrl); + return rsnull_create(rset_nmem,key_it_ctrl); if (rset_no == 1) return rset[0]; - return rsmultiand_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope, - rset_no, rset); + return rsmulti_and_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope, + rset_no, rset); } static RSET rpn_search_APT_local (ZebraHandle zh, Z_AttributesPlusTerm *zapt, @@ -1857,7 +1965,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"; @@ -1887,7 +1995,7 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, grep_info.isam_p_indx = 0; r = dict_lookup_grep(zh->reg->dict, term_dict, 0, &grep_info, &max_pos, 0, grep_handle); - yaz_log (YLOG_LOG, "%s %d positions", term, + yaz_log (YLOG_DEBUG, "%s %d positions", term, grep_info.isam_p_indx); rset = rset_trunc(zh, grep_info.isam_p_buf, grep_info.isam_p_indx, term, strlen(term), @@ -1928,14 +2036,14 @@ static RSET rpn_search_xpath (ZebraHandle zh, / -> none - a[@attr=value]/b[@other=othervalue] + a[@attr = value]/b[@other = othervalue] /e/@a val range(e/,range(@a,freetext(w,1015,val),@a),e/) /a/b val range(b/a/,freetext(w,1016,val),b/a/) /a/b/@c val range(b/a/,range(@c,freetext(w,1016,val),@c),b/a/) - /a/b[@c=y] val range(b/a/,freetext(w,1016,val),b/a/,@c=y) - /a[@c=y]/b val range(a/,range(b/a/,freetext(w,1016,val),b/a/),a/,@c=y) - /a[@c=x]/b[@c=y] range(a/,range(b/a/,freetext(w,1016,val),b/a/,@c=y),a/,@c=x) + /a/b[@c = y] val range(b/a/,freetext(w,1016,val),b/a/,@c = y) + /a[@c = y]/b val range(a/,range(b/a/,freetext(w,1016,val),b/a/),a/,@c = y) + /a[@c = x]/b[@c = y] range(a/,range(b/a/,freetext(w,1016,val),b/a/,@c = y),a/,@c = x) */ @@ -2029,18 +2137,10 @@ static RSET rpn_search_xpath (ZebraHandle zh, rset_end_tag = xpath_trunc(zh, stream, '0', xpath_rev, 2, curAttributeSet, rset_nmem); - /* - parms.key_size = sizeof(struct it_key); - parms.cmp = key_compare_it; - parms.rset_l = rset_start_tag; - parms.rset_m = rset; - parms.rset_r = rset_end_tag; - parms.rset_attr = rset_attr; - parms.printer = key_print_it; - rset = rset_create (rset_kind_between, &parms); - */ - rset=rsbetween_create( rset_nmem,key_it_ctrl,key_it_ctrl->scope, - rset_start_tag, rset, rset_end_tag, rset_attr); + rset = rsbetween_create(rset_nmem, key_it_ctrl, + key_it_ctrl->scope, + rset_start_tag, rset, + rset_end_tag, rset_attr); } first_path = 0; } @@ -2071,7 +2171,7 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, if (!log_level_set) { log_level_rpn = yaz_log_module_level("rpn"); - log_level_set=1; + log_level_set = 1; } zebra_maps_attr (zh->reg->zebra_maps, zapt, ®_id, &search_type, rank_type, &complete_flag, &sort_flag); @@ -2170,12 +2270,12 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs, switch (zop->which) { case Z_Operator_and: - r=rsmultiand_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, - 2, rsets); + r = rsmulti_and_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, + 2, rsets); break; case Z_Operator_or: - r=rsmultior_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, - 2, rsets); + r = rsmulti_or_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope, + 2, rsets); break; case Z_Operator_and_not: r = rsbool_create_not(rset_nmem,key_it_ctrl, key_it_ctrl->scope, @@ -2198,7 +2298,7 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs, else { /* new / old prox */ - r=rsprox_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope, + r = rsprox_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope, 2, rsets, *zop->u.prox->ordered, (!zop->u.prox->exclusion ? @@ -2306,7 +2406,7 @@ RSET rpn_search(ZebraHandle zh, NMEM nmem, NMEM rset_nmem, struct scan_info_entry { char *term; - ISAMC_P isam_p; + ISAM_P isam_p; }; struct scan_info { @@ -2330,8 +2430,8 @@ static int scan_handle (char *name, const char *info, int pos, void *client) scan_info->list[idx].term = (char *) odr_malloc(scan_info->odr, strlen(name + len_prefix)+1); strcpy(scan_info->list[idx].term, name + len_prefix); - assert (*info == sizeof(ISAMC_P)); - memcpy (&scan_info->list[idx].isam_p, info+1, sizeof(ISAMC_P)); + assert (*info == sizeof(ISAM_P)); + memcpy (&scan_info->list[idx].isam_p, info+1, sizeof(ISAM_P)); return 0; } @@ -2421,7 +2521,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, char rank_type[128]; int complete_flag; int sort_flag; - NMEM rset_nmem=NULL; + NMEM rset_nmem = NULL; *list = 0; @@ -2473,44 +2573,58 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, use_value = 1016; for (base_no = 0; base_no < num_bases && ord_no < 32; base_no++) { - int r; - attent attp; - data1_local_attribute *local_attr; + data1_local_attribute *local_attr; + attent attp; + int ord; - if ((r=att_getentbyatt (zh, &attp, attributeset, use_value, - use_string))) - { - yaz_log(YLOG_DEBUG, "att_getentbyatt fail. set=%d use=%d", - attributeset, use_value); - if (r == -1) - { - char val_str[32]; - sprintf (val_str, "%d", use_value); - errCode = 114; - errString = odr_strdup (stream, val_str); - } - else - errCode = 121; - continue; - } - if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) - { - zh->errString = basenames[base_no]; - zh->errCode = 109; /* Database unavailable */ - *num_entries = 0; - return; - } - bases_ok++; - for (local_attr = attp.local_attributes; local_attr && ord_no < 32; - local_attr = local_attr->next) - { - int ord; + if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) + { + zh->errString = basenames[base_no]; + zh->errCode = 109; /* Database unavailable */ + *num_entries = 0; + return; + } - ord = zebraExplain_lookupSU (zh->reg->zei, attp.attset_ordinal, - local_attr->local); - if (ord > 0) - ords[ord_no++] = ord; - } + if (use_string && + (ord = zebraExplain_lookup_attr_str(zh->reg->zei, + use_string)) >= 0) + { + /* we have a match for a raw string attribute */ + if (ord > 0) + ords[ord_no++] = ord; + attp.local_attributes = 0; /* no more attributes */ + } + else + { + int r; + + if ((r = att_getentbyatt (zh, &attp, attributeset, use_value, + use_string))) + { + yaz_log(YLOG_DEBUG, "att_getentbyatt fail. set=%d use=%d", + attributeset, use_value); + if (r == -1) + { + char val_str[32]; + sprintf (val_str, "%d", use_value); + errCode = 114; + errString = odr_strdup (stream, val_str); + } + else + errCode = 121; + continue; + } + } + bases_ok++; + for (local_attr = attp.local_attributes; local_attr && ord_no < 32; + local_attr = local_attr->next) + { + ord = zebraExplain_lookup_attr_su(zh->reg->zei, + attp.attset_ordinal, + local_attr->local); + if (ord > 0) + ords[ord_no++] = ord; + } } if (!bases_ok && errCode) { @@ -2553,7 +2667,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, if (trans_scan_term(zh, zapt, termz+prefix_len, reg_id)) return ; - + dict_scan(zh->reg->dict, termz, &before_tmp, &after_tmp, scan_info, scan_handle); } @@ -2577,7 +2691,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, for (j = 0; j < ord_no; j++) { if (ptr[j] < before+after && - (tst=scan_info_array[j].list[ptr[j]].term) && + (tst = scan_info_array[j].list[ptr[j]].term) && (!mterm || strcmp (tst, mterm) < 0)) { j0 = j; @@ -2589,104 +2703,116 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, scan_term_untrans (zh, stream->mem, reg_id, &glist[i+before].term, mterm); rset = rset_trunc(zh, &scan_info_array[j0].list[ptr[j0]].isam_p, 1, - glist[i+before].term, strlen(glist[i+before].term), - NULL, 0, zapt->term->which, rset_nmem, - key_it_ctrl,key_it_ctrl->scope); + glist[i+before].term, strlen(glist[i+before].term), + NULL, 0, zapt->term->which, rset_nmem, + key_it_ctrl,key_it_ctrl->scope); ptr[j0]++; for (j = j0+1; jterm->which,rset_nmem, - key_it_ctrl, key_it_ctrl->scope); - rset = rsbool_create_or(rset_nmem,key_it_ctrl, - key_it_ctrl->scope, rset, rset2); - /* FIXME - Use a proper multi-or */ - + RSET rsets[2]; + + rsets[0] = rset; + rsets[1] = + rset_trunc(zh, &scan_info_array[j].list[ptr[j]].isam_p, 1, + glist[i+before].term, + strlen(glist[i+before].term), NULL, 0, + zapt->term->which,rset_nmem, + key_it_ctrl, key_it_ctrl->scope); + rset = rsmulti_or_create(rset_nmem, key_it_ctrl, + 2, key_it_ctrl->scope, rsets); ptr[j]++; } } if (limit_set) - rset = rsbool_create_and(rset_nmem,key_it_ctrl,key_it_ctrl->scope, - rset, rset_dup(limit_set)); - count_set (rset, &glist[i+before].occurrences); - rset_delete (rset); + { + RSET rsets[2]; + rsets[0] = rset; + rsets[1] = rset_dup(limit_set); + + rset = rsmulti_and_create(rset_nmem, key_it_ctrl, + key_it_ctrl->scope, 2, rsets); + } + count_set(rset, &glist[i+before].occurrences); + rset_delete(rset); } if (i < after) { - *num_entries -= (after-i); - *is_partial = 1; + *num_entries -= (after-i); + *is_partial = 1; } - + /* consider terms before main term */ for (i = 0; i 0)) - { - j0 = j; - mterm = tst; - } - } - if (j0 == -1) - break; - - scan_term_untrans (zh, stream->mem, reg_id, - &glist[before-1-i].term, mterm); - - rset = rset_trunc - (zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1, - glist[before-1-i].term, strlen(glist[before-1-i].term), - NULL, 0, zapt->term->which,rset_nmem, - key_it_ctrl,key_it_ctrl->scope); - - ptr[j0]++; - - for (j = j0+1; j 0)) + { + j0 = j; + mterm = tst; + } + } + if (j0 == -1) + break; + + scan_term_untrans (zh, stream->mem, reg_id, + &glist[before-1-i].term, mterm); + + rset = rset_trunc + (zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1, + glist[before-1-i].term, strlen(glist[before-1-i].term), + NULL, 0, zapt->term->which,rset_nmem, + key_it_ctrl,key_it_ctrl->scope); + + ptr[j0]++; + + for (j = j0+1; jterm->which, rset_nmem, key_it_ctrl, key_it_ctrl->scope); - rset = rsbool_create_and(rset_nmem,key_it_ctrl, - key_it_ctrl->scope, rset, rset2); - /* FIXME - multi-and ?? */ - ptr[j]++; - } - } + rset = rsmulti_or_create(rset_nmem, key_it_ctrl, + 2, key_it_ctrl->scope, rsets); + + ptr[j]++; + } + } if (limit_set) - rset = rsbool_create_and(rset_nmem,key_it_ctrl,key_it_ctrl->scope, - rset, rset_dup(limit_set)); - count_set (rset, &glist[before-1-i].occurrences); - rset_delete (rset); + { + RSET rsets[2]; + rsets[0] = rset; + rsets[1] = rset_dup(limit_set); + + rset = rsmulti_and_create(rset_nmem, key_it_ctrl, + key_it_ctrl->scope, 2, rsets); + } + count_set (rset, &glist[before-1-i].occurrences); + rset_delete (rset); } i = before-i; if (i) @@ -2695,13 +2821,13 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, *position -= i; *num_entries -= i; } - + nmem_destroy(rset_nmem); *list = glist + i; /* list is set to first 'real' entry */ yaz_log(YLOG_DEBUG, "position = %d, num_entries = %d", - *position, *num_entries); + *position, *num_entries); if (zh->errCode) yaz_log(YLOG_DEBUG, "scan error: %d", zh->errCode); } - +