X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=index%2Fzrpn.c;h=99da03be1f91c6e32174027f474a70795c3cdff4;hb=2dd8bfd275211ec1c984b93562c2085ae87040e0;hp=d238961fe80184ca39185a1408aa8e495731b774;hpb=2953b2e39b289b3625e6a3a7c5a3f2b5e1d95ce8;p=idzebra-moved-to-github.git diff --git a/index/zrpn.c b/index/zrpn.c index d238961..99da03b 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -1,5 +1,5 @@ -/* $Id: zrpn.c,v 1.133 2003-04-15 20:48:04 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 +/* $Id: zrpn.c,v 1.136 2004-01-22 11:27:21 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps This file is part of the Zebra server. @@ -912,6 +912,10 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, struct rpn_char_map_info rcmi; 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 */ + rpn_char_map_prepare (zh->reg, reg_type, &rcmi); attr_init (&use, zapt, 1); use_value = attr_find_ex (&use, &curAttributeSet, &use_string); @@ -962,9 +966,9 @@ 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", use_value); - zh->errCode = 114; - zh->errString = nmem_strdup (stream, val_str); + sprintf (val_str, "%d 1", use_value); + errCode = 114; + errString = nmem_strdup (stream, val_str); } else { @@ -976,10 +980,10 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, oident.value = curAttributeSet; oid_ent_to_oid (&oident, oid); - zh->errCode = 121; - zh->errString = nmem_strdup (stream, oident.desc); + errCode = 121; + errString = nmem_strdup (stream, oident.desc); } - return -1; + continue; } } for (local_attr = attp.local_attributes; local_attr; @@ -1007,12 +1011,18 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, } if (!prefix_len) { +#if 1 + bases_ok++; +#else char val_str[32]; - sprintf (val_str, "%d", use_value); - zh->errCode = 114; - zh->errString = nmem_strdup (stream, val_str); - return -1; + sprintf (val_str, "%d 2", use_value); + errCode = 114; + errString = nmem_strdup (stream, val_str); +#endif + continue; } + bases_ok++; /* this has OK attributes */ + term_dict[prefix_len++] = ')'; term_dict[prefix_len++] = 1; term_dict[prefix_len++] = reg_type; @@ -1135,6 +1145,12 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, break; } } + if (!bases_ok) + { + zh->errCode = errCode; + zh->errString = errString; + return -1; + } *term_sub = termp; logf (LOG_DEBUG, "%d positions", grep_info->isam_p_indx); return 1; @@ -1798,6 +1814,10 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, const char *termp; 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); use_value = attr_find_ex (&use, &curAttributeSet, &use_string); @@ -1838,12 +1858,12 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, { char val_str[32]; sprintf (val_str, "%d", use_value); - zh->errString = nmem_strdup (stream, val_str); - zh->errCode = 114; + errString = nmem_strdup (stream, val_str); + errCode = 114; } else - zh->errCode = 121; - return -1; + errCode = 121; + continue; } } if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) @@ -1879,10 +1899,11 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, { char val_str[32]; sprintf (val_str, "%d", use_value); - zh->errCode = 114; - zh->errString = nmem_strdup (stream, val_str); - return -1; + errCode = 114; + errString = nmem_strdup (stream, val_str); + continue; } + bases_ok++; term_dict[prefix_len++] = ')'; term_dict[prefix_len++] = 1; term_dict[prefix_len++] = reg_type; @@ -1893,6 +1914,12 @@ static int numeric_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, term_dst)) return 0; } + if (!bases_ok) + { + zh->errCode = errCode; + zh->errString = errString; + return -1; + } *term_sub = termp; logf (LOG_DEBUG, "%d positions", grep_info->isam_p_indx); return 1; @@ -2289,18 +2316,25 @@ static RSET rpn_search_xpath (ZebraHandle zh, xpath[level].predicate->which == XPATH_PREDICATE_RELATION && xpath[level].predicate->u.relation.name[0]) { - char predicate_str[128]; - - strcpy (predicate_str, - xpath[level].predicate->u.relation.name+1); + WRBUF wbuf = wrbuf_alloc(); + wrbuf_puts(wbuf, xpath[level].predicate->u.relation.name+1); if (xpath[level].predicate->u.relation.value) { - strcat (predicate_str, "="); - strcat (predicate_str, - xpath[level].predicate->u.relation.value); + const char *cp = xpath[level].predicate->u.relation.value; + wrbuf_putc(wbuf, '='); + + while (*cp) + { + if (strchr(REGEX_CHARS, *cp)) + wrbuf_putc(wbuf, '\\'); + wrbuf_putc(wbuf, *cp); + cp++; + } } + wrbuf_puts(wbuf, ""); rset_attr = xpath_trunc ( - zh, stream, '0', predicate_str, 3, curAttributeSet); + zh, stream, '0', wrbuf_buf(wbuf), 3, curAttributeSet); + wrbuf_free(wbuf, 1); } else { @@ -2690,6 +2724,10 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, int ords[32], ord_no = 0; int ptr[32]; + int bases_ok = 0; /* no of databases with OK attribute */ + int errCode = 0; /* err code (if any is not OK) */ + char *errString = 0; /* addinfo */ + unsigned reg_id; char *search_type = NULL; char rank_type[128]; @@ -2758,13 +2796,12 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, { char val_str[32]; sprintf (val_str, "%d", use_value); - zh->errCode = 114; - zh->errString = odr_strdup (stream, val_str); + errCode = 114; + errString = odr_strdup (stream, val_str); } else - zh->errCode = 121; - *num_entries = 0; - return; + errCode = 121; + continue; } if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) { @@ -2773,6 +2810,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, *num_entries = 0; return; } + bases_ok++; for (local_attr = attp.local_attributes; local_attr && ord_no < 32; local_attr = local_attr->next) { @@ -2784,10 +2822,20 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, ords[ord_no++] = ord; } } + if (!bases_ok && errCode) + { + zh->errCode = errCode; + zh->errString = errString; + *num_entries = 0; + } if (ord_no == 0) { + char val_str[32]; + sprintf (val_str, "%d", use_value); + zh->errCode = 114; + zh->errString = odr_strdup (stream, val_str); + *num_entries = 0; - zh->errCode = 113; return; } /* prepare dictionary scanning */