X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzrpn.c;h=249e7e9655de70776608988611d732a79219aa8d;hb=245ce174727953c86b42469927d469f860f07230;hp=ca8e014dc0547624f126e7e002881ac1e1a1be84;hpb=ef696645cc3b7e0f4027008d1dc589c0f0f90c1f;p=idzebra-moved-to-github.git diff --git a/index/zrpn.c b/index/zrpn.c index ca8e014..249e7e9 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -4,7 +4,16 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zrpn.c,v $ - * Revision 1.92 1999-05-26 07:49:13 adam + * Revision 1.95 1999-09-07 07:19:21 adam + * Work on character mapping. Implemented replace rules. + * + * Revision 1.94 1999/07/20 13:59:18 adam + * Fixed bug that occurred when phrases had 0 hits. + * + * Revision 1.93 1999/06/17 14:38:40 adam + * Bug fix: Scan SEGV'ed when getting unknown use attribute. + * + * Revision 1.92 1999/05/26 07:49:13 adam * C++ compilation. * * Revision 1.91 1999/02/02 14:51:13 adam @@ -446,8 +455,11 @@ static void term_untrans (ZebraHandle zh, int reg_type, while (*src) { const char *cp = zebra_maps_output (zh->zebra_maps, reg_type, &src); - while (*cp) - *dst++ = *cp++; + if (!cp) + *dst++ = *src++; + else + while (*cp) + *dst++ = *cp++; } *dst = '\0'; } @@ -523,6 +535,7 @@ static int term_pre (ZebraMaps zebra_maps, int reg_type, const char **src, return *s0; } +/* 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) @@ -555,6 +568,7 @@ static int term_100 (ZebraMaps zebra_maps, int reg_type, return i; } +/* 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) @@ -596,7 +610,7 @@ static int term_101 (ZebraMaps zebra_maps, int reg_type, return i; } - +/* 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) @@ -645,6 +659,7 @@ static int term_103 (ZebraMaps zebra_maps, int reg_type, const char **src, return i; } +/* 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) { @@ -652,6 +667,54 @@ static int term_102 (ZebraMaps zebra_maps, int reg_type, const char **src, dst_term); } + +/* 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) +{ + const char *s0, *s1; + const char **map; + int i = 0; + int j = 0; + + if (!term_pre (zebra_maps, reg_type, src, "#!", "#!")) + return 0; + s0 = *src; + while (*s0) + { + if (*s0 == '#') + { + dst[i++] = '.'; + dst[i++] = '*'; + dst_term[j++] = *s0++; + } + else if (*s0 == '!') + { + dst[i++] = '.'; + dst_term[j++] = *s0++; + } + { + s1 = s0; + map = zebra_maps_input (zebra_maps, reg_type, &s0, strlen(s0)); + if (space_split && **map == *CHR_SPACE) + break; + while (s1 < s0) + { + if (!isalnum (*s1)) + dst[i++] = '\\'; + dst_term[j++] = *s1; + dst[i++] = *s1++; + } + } + } + dst[i] = '\0'; + dst_term[j++] = '\0'; + *src = s0; + return i; +} + + /* gen_regular_rel - generate regular expression from relation * val: border value (inclusive) * islt: 1 if <=; 0 if >=. @@ -749,11 +812,14 @@ static void gen_regular_rel (char *dst, int val, int islt) dst[dst_p] = '\0'; if (islt) { - for (i=1; izebra_maps, reg_type, + &termp, term_dict + j, space_split, term_dst)) + return 0; + strcat (term_dict, ")"); + r = dict_lookup_grep (zh->dict, term_dict, 0, grep_info, + &max_pos, 0, grep_handle); + if (r) + logf (LOG_WARN, "dict_lookup_grep err, trunc=#/!: %d", r); + break; } } *term_sub = termp; @@ -1280,27 +1357,34 @@ static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no) more = (int *) xmalloc (sizeof(*more)*rset_no); buf = (struct it_key **) xmalloc (sizeof(*buf)*rset_no); + *prox_term = '\0'; for (i = 0; ino_rset_terms; j++) { const char *nflags = rset[i]->rset_terms[j]->flags; char *term = rset[i]->rset_terms[j]->name; int lterm = strlen(term); - if (length_prox_term) - prox_term[length_prox_term++] = ' '; - strcpy (prox_term + length_prox_term, term); - length_prox_term += lterm; + if (lterm + length_prox_term < sizeof(prox_term)-1) + { + if (length_prox_term) + prox_term[length_prox_term++] = ' '; + strcpy (prox_term + length_prox_term, term); + length_prox_term += lterm; + } if (min_nn > rset[i]->rset_terms[j]->nn) min_nn = rset[i]->rset_terms[j]->nn; flags = nflags; } } + for (i = 0; inn = 0; result = rset_create (rset_kind_null, &parms); } @@ -1320,7 +1405,8 @@ static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no) rset_temp_parms parms; RSFD rsfd_result; - parms.rset_term = rset_term_create (prox_term, -1, flags); + parms.rset_term = rset_term_create (prox_term, length_prox_term, + flags); parms.rset_term->nn = min_nn; parms.key_size = sizeof (struct it_key); parms.temp_path = res_get (zh->res, "setTmpDir"); @@ -1381,9 +1467,51 @@ static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no) return result; } + +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; + } + if (ex_list) + wrbuf = zebra_replace(zh->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 RSET rpn_search_APT_phrase (ZebraHandle zh, Z_AttributesPlusTerm *zapt, - const char *termz, + const char *termz_org, oid_value attributeSet, NMEM stream, int reg_type, int complete_flag, @@ -1391,10 +1519,11 @@ static RSET rpn_search_APT_phrase (ZebraHandle zh, int num_bases, char **basenames) { char term_dst[IT_MAX_WORD+1]; - const char *termp = termz; RSET rset[60], result; int i, r, rset_no = 0; struct grep_info grep_info; + char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type); + const char *termp = termz; #ifdef TERM_COUNT grep_info.term_no = 0; @@ -1442,7 +1571,7 @@ static RSET rpn_search_APT_phrase (ZebraHandle zh, static RSET rpn_search_APT_or_list (ZebraHandle zh, Z_AttributesPlusTerm *zapt, - const char *termz, + const char *termz_org, oid_value attributeSet, NMEM stream, int reg_type, int complete_flag, @@ -1450,11 +1579,11 @@ static RSET rpn_search_APT_or_list (ZebraHandle zh, int num_bases, char **basenames) { char term_dst[IT_MAX_WORD+1]; - const char *termp = termz; RSET rset[60], result; int i, r, rset_no = 0; struct grep_info grep_info; - + char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type); + const char *termp = termz; #ifdef TERM_COUNT grep_info.term_no = 0; #endif @@ -1507,7 +1636,7 @@ static RSET rpn_search_APT_or_list (ZebraHandle zh, static RSET rpn_search_APT_and_list (ZebraHandle zh, Z_AttributesPlusTerm *zapt, - const char *termz, + const char *termz_org, oid_value attributeSet, NMEM stream, int reg_type, int complete_flag, @@ -1515,10 +1644,11 @@ static RSET rpn_search_APT_and_list (ZebraHandle zh, int num_bases, char **basenames) { char term_dst[IT_MAX_WORD+1]; - const char *termp = termz; RSET rset[60], result; int i, r, rset_no = 0; struct grep_info grep_info; + char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type); + const char *termp = termz; #ifdef TERM_COUNT grep_info.term_no = 0; @@ -2159,8 +2289,7 @@ static int scan_handle (char *name, const char *info, int pos, void *client) len_prefix = strlen(scan_info->prefix); if (memcmp (name, scan_info->prefix, len_prefix)) return 1; - if (pos > 0) - idx = scan_info->after - pos + scan_info->before; + if (pos > 0) idx = scan_info->after - pos + scan_info->before; else idx = - pos - 1; scan_info->list[idx].term = (char *) @@ -2232,6 +2361,7 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, char *rank_type = NULL; int complete_flag; int sort_flag; + *list = 0; if (attributeset == VAL_NONE) attributeset = VAL_BIB1; @@ -2264,6 +2394,8 @@ void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt, zh->errCode = 114; else zh->errCode = 121; + *num_entries = 0; + return; } if (zebraExplain_curDatabase (zh->zei, basenames[base_no])) {