X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Frpnsearch.c;h=88a411f4fe6ac571f53f5c5d613cf71817570684;hb=09aa21f9fc2a275701c7820a260b75b6323fcc42;hp=d4c84b34874f8243bc6bd3ae081e1a1ca99de288;hpb=9f937bde31af9c7d6eb0f1355d884110131fa2b9;p=idzebra-moved-to-github.git diff --git a/index/rpnsearch.c b/index/rpnsearch.c index d4c84b3..88a411f 100644 --- a/index/rpnsearch.c +++ b/index/rpnsearch.c @@ -1,4 +1,4 @@ -/* $Id: rpnsearch.c,v 1.13 2007-05-14 12:33:33 adam Exp $ +/* $Id: rpnsearch.c,v 1.15 2007-10-29 09:25:41 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -134,9 +134,9 @@ static int add_isam_p(const char *name, const char *info, char term_tmp[IT_MAX_WORD]; int ord = 0; const char *index_name; - int len = key_SU_decode (&ord, (const unsigned char *) name); + int len = key_SU_decode(&ord, (const unsigned char *) name); - zebra_term_untrans (p->zh, p->reg_type, term_tmp, name+len); + zebra_term_untrans (p->zh, p->reg_type, term_tmp, name+len); yaz_log(log_level_rpn, "grep: %d %c %s", ord, name[len], term_tmp); zebraExplain_lookup_ord(p->zh->reg->zei, ord, 0 /* index_type */, &db, &index_name); @@ -206,6 +206,33 @@ static void esc_str(char *out_buf, size_t out_size, #define REGEX_CHARS " []()|.*+?!" +static void add_non_space(const char *start, const char *end, + WRBUF term_dict, + char *dst_term, int *dst_ptr, + const char **map, int q_map_match) +{ + size_t sz = end - start; + memcpy(dst_term + *dst_ptr, start, sz); + (*dst_ptr) += sz; + if (!q_map_match) + { + while (start < end) + { + if (strchr(REGEX_CHARS, *start)) + wrbuf_putc(term_dict, '\\'); + wrbuf_putc(term_dict, *start); + start++; + } + } + else + { + char tmpbuf[80]; + esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); + + wrbuf_puts(term_dict, map[0]); + } +} + /* term_100: handle term, where trunc = none(no operators at all) */ static int term_100(ZebraMaps zebra_maps, int reg_type, const char **src, WRBUF term_dict, int space_split, @@ -256,27 +283,10 @@ static int term_100(ZebraMaps zebra_maps, int reg_type, space_start = space_end = 0; } } - /* add non-space char */ i++; - memcpy(dst_term+j, s1, s0 - s1); - j += (s0 - s1); - if (!q_map_match) - { - while (s1 < s0) - { - if (strchr(REGEX_CHARS, *s1)) - wrbuf_putc(term_dict, '\\'); - wrbuf_putc(term_dict, *s1); - s1++; - } - } - else - { - char tmpbuf[80]; - esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); - wrbuf_puts(term_dict, map[0]); - } + add_non_space(s1, s0, term_dict, dst_term, &j, + map, q_map_match); } dst_term[j] = '\0'; *src = s0; @@ -314,26 +324,8 @@ static int term_101(ZebraMaps zebra_maps, int reg_type, break; i++; - /* 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)) - wrbuf_putc(term_dict, '\\'); - wrbuf_putc(term_dict, *s1); - s1++; - } - } - else - { - char tmpbuf[80]; - esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); - - wrbuf_puts(term_dict, map[0]); - } + add_non_space(s1, s0, term_dict, dst_term, &j, + map, q_map_match); } } dst_term[j++] = '\0'; @@ -380,27 +372,9 @@ static int term_103(ZebraMaps zebra_maps, int reg_type, const char **src, if (space_split && **map == *CHR_SPACE) break; - /* add non-space char */ - memcpy(dst_term+j, s1, s0 - s1); - j += (s0 - s1); i++; - if (!q_map_match) - { - while (s1 < s0) - { - if (strchr(REGEX_CHARS, *s1)) - wrbuf_putc(term_dict, '\\'); - wrbuf_putc(term_dict, *s1); - s1++; - } - } - else - { - char tmpbuf[80]; - esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); - - wrbuf_puts(term_dict, map[0]); - } + add_non_space(s1, s0, term_dict, dst_term, &j, + map, q_map_match); } } dst_term[j] = '\0'; @@ -479,26 +453,8 @@ static int term_104(ZebraMaps zebra_maps, int reg_type, break; i++; - /* 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)) - wrbuf_putc(term_dict, '\\'); - wrbuf_putc(term_dict, *s1); - s1++; - } - } - else - { - char tmpbuf[80]; - esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); - - wrbuf_puts(term_dict, map[0]); - } + add_non_space(s1, s0, term_dict, dst_term, &j, + map, q_map_match); } } dst_term[j++] = '\0'; @@ -543,26 +499,8 @@ static int term_105(ZebraMaps zebra_maps, int reg_type, break; i++; - /* 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)) - wrbuf_putc(term_dict, '\\'); - wrbuf_putc(term_dict, *s1); - s1++; - } - } - else - { - char tmpbuf[80]; - esc_str(tmpbuf, sizeof(tmpbuf), map[0], strlen(map[0])); - - wrbuf_puts(term_dict, map[0]); - } + add_non_space(s1, s0, term_dict, dst_term, &j, + map, q_map_match); } } if (right_truncate) @@ -801,8 +739,8 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_putc(term_dict, ')'); break; case 5: - if (!term_100 (zh->reg->zebra_maps, reg_type, - term_sub, term_component, space_split, term_dst)) + if (!term_100(zh->reg->zebra_maps, reg_type, + term_sub, term_component, space_split, term_dst)) { wrbuf_destroy(term_component); return 0; @@ -1026,7 +964,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, *ol = ord_list_create(stream); - rpn_char_map_prepare (zh->reg, reg_type, &rcmi); + rpn_char_map_prepare(zh->reg, reg_type, &rcmi); attr_init_APT(&truncation, zapt, 5); truncation_value = attr_find(&truncation, NULL); yaz_log(log_level_rpn, "truncation value %d", truncation_value); @@ -1043,7 +981,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, termp = *term_sub; /* start of term for each database */ - if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) + if (zebraExplain_curDatabase(zh->reg->zei, basenames[base_no])) { zebra_setError(zh, YAZ_BIB1_DATABASE_UNAVAILABLE, basenames[base_no]); @@ -1060,7 +998,7 @@ static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, bases_ok++; *ol = ord_list_append(stream, *ol, ord); - ord_len = key_SU_encode (ord, ord_buf); + ord_len = key_SU_encode(ord, ord_buf); wrbuf_putc(term_dict, '('); @@ -1352,7 +1290,7 @@ static ZEBRA_RES term_list_trunc(ZebraHandle zh, int i; for (i = 0; i < *num_result_sets; i++) rset_delete((*result_sets)[i]); - grep_info_delete (&grep_info); + grep_info_delete(&grep_info); return res; } if ((*result_sets)[*num_result_sets] == 0) @@ -1420,7 +1358,7 @@ static ZEBRA_RES rpn_search_APT_position(ZebraHandle zh, char *val; ISAM_P isam_p; - if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) + if (zebraExplain_curDatabase(zh->reg->zei, basenames[base_no])) { zebra_setError(zh, YAZ_BIB1_DATABASE_UNAVAILABLE, basenames[base_no]); @@ -1431,7 +1369,7 @@ static ZEBRA_RES rpn_search_APT_position(ZebraHandle zh, attributeSet, &ord) != ZEBRA_OK) continue; - ord_len = key_SU_encode (ord, ord_buf); + ord_len = key_SU_encode(ord, ord_buf); memcpy(term_dict, ord_buf, ord_len); strcpy(term_dict+ord_len, FIRST_IN_FIELD_STR); val = dict_lookup(zh->reg->dict, term_dict); @@ -1685,7 +1623,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_destroy(term_num); return 0; } - term_value = atoi (wrbuf_cstr(term_num)); + term_value = atoi(wrbuf_cstr(term_num)); gen_regular_rel(term_dict, term_value-1, 1); break; case 2: @@ -1696,7 +1634,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_destroy(term_num); return 0; } - term_value = atoi (wrbuf_cstr(term_num)); + term_value = atoi(wrbuf_cstr(term_num)); gen_regular_rel(term_dict, term_value, 1); break; case 4: @@ -1707,7 +1645,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_destroy(term_num); return 0; } - term_value = atoi (wrbuf_cstr(term_num)); + term_value = atoi(wrbuf_cstr(term_num)); gen_regular_rel(term_dict, term_value, 0); break; case 5: @@ -1718,7 +1656,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_destroy(term_num); return 0; } - term_value = atoi (wrbuf_cstr(term_num)); + term_value = atoi(wrbuf_cstr(term_num)); gen_regular_rel(term_dict, term_value+1, 0); break; case -1: @@ -1730,7 +1668,7 @@ static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt, wrbuf_destroy(term_num); return 0; } - term_value = atoi (wrbuf_cstr(term_num)); + term_value = atoi(wrbuf_cstr(term_num)); wrbuf_printf(term_dict, "(0*%d)", term_value); break; case 103: @@ -1774,7 +1712,7 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, *ol = ord_list_create(stream); - rpn_char_map_prepare (zh->reg, reg_type, &rcmi); + rpn_char_map_prepare(zh->reg, reg_type, &rcmi); for (base_no = 0; base_no < num_bases; base_no++) { @@ -1785,7 +1723,7 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, termp = *term_sub; - if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) + if (zebraExplain_curDatabase(zh->reg->zei, basenames[base_no])) { zebra_setError(zh, YAZ_BIB1_DATABASE_UNAVAILABLE, basenames[base_no]); @@ -1801,7 +1739,7 @@ static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt, *ol = ord_list_append(stream, *ol, ord); - ord_len = key_SU_encode (ord, ord_buf); + ord_len = key_SU_encode(ord, ord_buf); wrbuf_putc(term_dict, '('); for (i = 0; i < ord_len; i++) @@ -1986,7 +1924,7 @@ static ZEBRA_RES rpn_sort_spec(ZebraHandle zh, Z_AttributesPlusTerm *zapt, if (zapt->term->which != Z_Term_general) i = 0; else - i = atoi_n ((char *) zapt->term->u.general->buf, + i = atoi_n((char *) zapt->term->u.general->buf, zapt->term->u.general->len); if (i >= sort_sequence->num_specs) i = 0; @@ -2067,7 +2005,7 @@ static RSET xpath_trunc(ZebraHandle zh, NMEM stream, char ord_buf[32]; RSET rset; WRBUF term_dict = wrbuf_alloc(); - int ord_len = key_SU_encode (ord, ord_buf); + int ord_len = key_SU_encode(ord, ord_buf); int term_type = Z_Term_characterString; const char *flags = "void"; @@ -2141,14 +2079,14 @@ ZEBRA_RES rpn_search_xpath(ZebraHandle zh, */ - dict_grep_cmap (zh->reg->dict, 0, 0); + dict_grep_cmap(zh->reg->dict, 0, 0); for (base_no = 0; base_no < num_bases; base_no++) { int level = xpath_len; int first_path = 1; - if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no])) + if (zebraExplain_curDatabase(zh->reg->zei, basenames[base_no])) { zebra_setError(zh, YAZ_BIB1_DATABASE_UNAVAILABLE, basenames[base_no]);