X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzrpn.c;h=a1eb701e2e06e63b5bc363383ea9b49123a8ef19;hb=732e272a6d35533ccc89f4ccab0ea8069097b8a1;hp=0a2c29ccd5c87717ea235a5428ff6b6a7b7cfbe9;hpb=00d69171180b9edc123986794b572be57caa5bb2;p=idzebra-moved-to-github.git diff --git a/index/zrpn.c b/index/zrpn.c index 0a2c29c..a1eb701 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,5 +1,5 @@ -/* $Id: zrpn.c,v 1.126 2002-12-16 22:59:34 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: zrpn.c,v 1.132 2003-03-31 22:14:18 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps This file is part of the Zebra server. @@ -31,6 +31,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include "index.h" +#include #include #include @@ -43,6 +44,14 @@ struct rpn_char_map_info { int reg_type; }; +typedef struct { + int type; + int major; + int minor; + Z_AttributesPlusTerm *zapt; +} AttrType; + + 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; @@ -70,13 +79,6 @@ static void rpn_char_map_prepare (struct zebra_register *reg, int reg_type, dict_grep_cmap (reg->dict, map_info, rpn_char_map_handler); } -typedef struct { - int type; - int major; - int minor; - Z_AttributesPlusTerm *zapt; -} AttrType; - static int attr_find_ex (AttrType *src, oid_value *attributeSetP, const char **string_value) { @@ -445,18 +447,43 @@ static int term_104 (ZebraMaps zebra_maps, int reg_type, int i = 0; int j = 0; - if (!term_pre (zebra_maps, reg_type, src, "#!", "#!")) + if (!term_pre (zebra_maps, reg_type, src, "?*#", "?*#")) return 0; s0 = *src; while (*s0) { - if (*s0 == '#') + if (*s0 == '?') + { + dst_term[j++] = *s0++; + if (*s0 >= '0' && *s0 <= '9') + { + int limit = 0; + while (*s0 >= '0' && *s0 <= '9') + { + limit = limit * 10 + (*s0 - '0'); + dst_term[j++] = *s0++; + } + if (limit > 20) + limit = 20; + while (--limit >= 0) + { + dst[i++] = '.'; + dst[i++] = '?'; + } + } + else + { + dst[i++] = '.'; + dst[i++] = '*'; + } + } + else if (*s0 == '*') { dst[i++] = '.'; dst[i++] = '*'; dst_term[j++] = *s0++; } - else if (*s0 == '!') + else if (*s0 == '#') { dst[i++] = '.'; dst_term[j++] = *s0++; @@ -923,7 +950,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, { /* set was found, but value wasn't defined */ char val_str[32]; - sprintf (val_str, "%d (1)", use_value); + sprintf (val_str, "%d", use_value); zh->errCode = 114; zh->errString = nmem_strdup (stream, val_str); } @@ -969,7 +996,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, if (!prefix_len) { char val_str[32]; - sprintf (val_str, "%d (2)", use_value); + sprintf (val_str, "%d", use_value); zh->errCode = 114; zh->errString = nmem_strdup (stream, val_str); return -1; @@ -1273,7 +1300,7 @@ static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no, parms.temp_path = res_get (zh->res, "setTmpDir"); result = rset_create (rset_kind_temp, &parms); rsfd_result = rset_open (result, RSETF_WRITE); - + while (*more) { for (i = 1; inn = min_nn; @@ -1747,7 +1775,7 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, oid_value attributeSet, 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, NMEM stream) { char term_dict[2*IT_MAX_WORD+2]; int r, base_no; @@ -1795,7 +1823,12 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d r=%d", curAttributeSet, use_value, r); if (r == -1) + { + char val_str[32]; + sprintf (val_str, "%d", use_value); + zh->errString = nmem_strdup (stream, val_str); zh->errCode = 114; + } else zh->errCode = 121; return -1; @@ -1832,7 +1865,10 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, } if (!prefix_len) { + char val_str[32]; + sprintf (val_str, "%d", use_value); zh->errCode = 114; + zh->errString = nmem_strdup (stream, val_str); return -1; } term_dict[prefix_len++] = ')'; @@ -1873,7 +1909,8 @@ static RSET rpn_search_APT_numeric (ZebraHandle zh, grep_info.isam_p_indx = 0; r = numeric_term (zh, zapt, &termp, attributeSet, &grep_info, reg_type, complete_flag, num_bases, basenames, - term_dst, xpath_use); + term_dst, xpath_use, + stream); if (r < 1) break; logf (LOG_DEBUG, "term: %s", term_dst); @@ -2034,6 +2071,9 @@ static RSET rpn_sort_spec (ZebraHandle zh, Z_AttributesPlusTerm *zapt, return rset_create (rset_kind_null, &parms); } +/* pop - moved to xpath.c */ +#if 0 + struct xpath_predicate { int which; union { @@ -2057,102 +2097,26 @@ struct xpath_location_step { struct xpath_predicate *predicate; }; +#endif + static int parse_xpath(ZebraHandle zh, Z_AttributesPlusTerm *zapt, oid_value attributeSet, - struct xpath_location_step *xpath, NMEM mem) + struct xpath_location_step *xpath, int max, NMEM mem) { oid_value curAttributeSet = attributeSet; AttrType use; const char *use_string = 0; - const char *cp; - int no = 0; attr_init (&use, zapt, 1); attr_find_ex (&use, &curAttributeSet, &use_string); if (!use_string || *use_string != '/') return -1; - cp = use_string; - while (*cp) - { - int i = 0; - while (*cp && !strchr("/[",*cp)) - { - i++; - cp++; - } - xpath[no].predicate = 0; - xpath[no].part = nmem_malloc (mem, i+1); - memcpy (xpath[no].part, cp - i, i); - xpath[no].part[i] = 0; - if (*cp == '[') - { - struct xpath_predicate *p = xpath[no].predicate = - nmem_malloc (mem, sizeof(struct xpath_predicate)); - - p->which = XPATH_PREDICATE_RELATION; - cp++; - while (*cp == ' ') - cp++; - - for (i = 0; *cp && !strchr("><=] ", *cp); i++) - cp++; - p->u.relation.name = nmem_malloc (mem, i+1); - memcpy (p->u.relation.name, cp - i, i); - p->u.relation.name[i] = 0; - while (*cp == ' ') - cp++; - if (*cp != ']') - { - for (i = 0; *cp && strchr(">=u.relation.op = nmem_malloc (mem, i+1); - if (i) - memcpy (p->u.relation.op, cp - i, i); - p->u.relation.op[i] = 0; - - while (*cp == ' ') - cp++; - - if (strchr("\"'", *cp)) - { - cp++; - for (i = 0; *cp && !strchr("\"'", *cp); i++) - cp++; - - p->u.relation.value = nmem_malloc (mem, i+1); - if (i) - memcpy (p->u.relation.value, cp - i, i); - p->u.relation.value[i] = 0; - yaz_log (LOG_LOG, "value=%s", p->u.relation.value); - - cp++; - } - else - { - for (i = 0; *cp && !strchr(" ]", *cp); i++) - cp++; - p->u.relation.value = nmem_malloc (mem, i+1); - if (i) - memcpy (p->u.relation.value, cp - i, i); - p->u.relation.value[i] = 0; - } - while (*cp == ' ') - cp++; - } - if (*cp == ']') - cp++; - } /* end of ] predicate */ - no++; - if (*cp != '/') - break; - cp++; - } - return no; + return zebra_parse_xpath_str(use_string, xpath, max, mem); } - + + static RSET xpath_trunc(ZebraHandle zh, NMEM stream, int reg_type, const char *term, int use, @@ -2388,7 +2352,7 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt, if (sort_flag) return rpn_sort_spec (zh, zapt, attributeSet, stream, sort_sequence, rank_type); - xpath_len = parse_xpath(zh, zapt, attributeSet, xpath, stream); + xpath_len = parse_xpath(zh, zapt, attributeSet, xpath, 10, stream); if (xpath_len >= 0) { xpath_use = 1016; @@ -2536,6 +2500,8 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs, nmem_strdup (stream, zs->u.simple->u.resultSetId); return 0; } + else + rset_dup(r); } else { @@ -2696,7 +2662,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, oid_value attributeset, int num_bases, char **basenames, int *position, int *num_entries, ZebraScanEntry **list, - int *is_partial) + int *is_partial, RSET limit_set, int return_zero) { int i; int pos = *position; @@ -2717,11 +2683,38 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, char rank_type[128]; int complete_flag; int sort_flag; + *list = 0; if (attributeset == VAL_NONE) attributeset = VAL_BIB1; + if (!limit_set) + { + AttrType termset; + int termset_value_numeric; + const char *termset_value_string; + attr_init (&termset, zapt, 8); + termset_value_numeric = + attr_find_ex (&termset, NULL, &termset_value_string); + if (termset_value_numeric != -1) + { + char resname[32]; + const char *termset_name = 0; + + if (termset_value_numeric != -2) + { + + sprintf (resname, "%d", termset_value_numeric); + termset_name = resname; + } + else + termset_name = termset_value_string; + + limit_set = resultSetRef (zh, termset_name); + } + } + yaz_log (LOG_DEBUG, "position = %d, num = %d set=%d", pos, num, attributeset); @@ -2750,7 +2743,12 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d", attributeset, use_value); if (r == -1) - zh->errCode = 114; + { + char val_str[32]; + sprintf (val_str, "%d", use_value); + zh->errCode = 114; + zh->errString = odr_strdup (stream, val_str); + } else zh->errCode = 121; *num_entries = 0; @@ -2873,6 +2871,17 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, ptr[j]++; } } + if (limit_set) + { + rset_bool_parms bool_parms; + + bool_parms.key_size = sizeof(struct it_key); + bool_parms.cmp = key_compare_it; + bool_parms.rset_l = rset; + bool_parms.rset_r = rset_dup(limit_set); + + rset = rset_create (rset_kind_and, &bool_parms); + } count_set (rset, &glist[i+before].occurrences); rset_delete (rset); } @@ -2941,6 +2950,17 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, ptr[j]++; } } + if (limit_set) + { + rset_bool_parms bool_parms; + + bool_parms.key_size = sizeof(struct it_key); + bool_parms.cmp = key_compare_it; + bool_parms.rset_l = rset; + bool_parms.rset_r = rset_dup(limit_set); + + rset = rset_create (rset_kind_and, &bool_parms); + } count_set (rset, &glist[before-1-i].occurrences); rset_delete (rset); }