- if (!relational_term (zi, zapt, term_sub, term_dict,
- attributeSet, grep_info, &max_pos))
- {
- const char *cp;
-
- j = prefix_len;
- switch (truncation_value)
- {
- case -1: /* not specified */
- case 100: /* do not truncate */
- term_dict[j++] = '(';
- for (i = 0; term_sub[i]; i++)
- verbatim_char (term_sub[i], &j, term_dict);
- strcpy (term_dict+j, ")");
- r = dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info,
- &max_pos, 0, grep_handle);
- if (r)
- logf (LOG_WARN, "dict_lookup_grep err, trunc=none:%d", r);
- break;
- case 1: /* right truncation */
- term_dict[j++] = '(';
- for (i = 0; term_sub[i]; i++)
- verbatim_char (term_sub[i], &j, term_dict);
- strcpy (term_dict+j, ".*)");
- dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info,
- &max_pos, 0, grep_handle);
- break;
- case 2: /* left truncation */
- case 3: /* left&right truncation */
- zi->errCode = 120;
+ j = prefix_len;
+ switch (truncation_value)
+ {
+ case -1: /* not specified */
+ case 100: /* do not truncate */
+ if (!string_relation (zh, zapt, &termp, term_dict,
+ attributeSet,
+ reg_type, space_split, term_dst))
+ return 0;
+ logf (LOG_LOG, "dict_lookup_grep: %s", term_dict+prefix_len);
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0,
+ grep_info, &max_pos, 0, grep_handle);
+ if (r)
+ logf (LOG_WARN, "dict_lookup_grep fail %d", r);
+ break;
+ case 1: /* right truncation */
+ term_dict[j++] = '(';
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ".*)");
+ dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
+ &max_pos, 0, grep_handle);
+ break;
+ case 2: /* keft truncation */
+ term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ")");
+ dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
+ &max_pos, 0, grep_handle);
+ break;
+ case 3: /* left&right truncation */
+ term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
+ if (!term_100 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ".*)");
+ dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
+ &max_pos, 0, grep_handle);
+ break;
+ zh->errCode = 120;
+ return -1;
+ case 101: /* process # in term */
+ term_dict[j++] = '(';
+ if (!term_101 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ")");
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
+ &max_pos, 0, grep_handle);
+ if (r)
+ logf (LOG_WARN, "dict_lookup_grep err, trunc=#: %d", r);
+ break;
+ case 102: /* Regexp-1 */
+ term_dict[j++] = '(';
+ if (!term_102 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ")");
+ logf (LOG_DEBUG, "Regexp-1 tolerance=%d", r);
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
+ &max_pos, 0, grep_handle);
+ if (r)
+ logf (LOG_WARN, "dict_lookup_grep err, trunc=regular: %d",
+ r);
+ break;
+ case 103: /* Regexp-2 */
+ r = 1;
+ term_dict[j++] = '(';
+ if (!term_103 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, &r, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ")");
+ logf (LOG_DEBUG, "Regexp-2 tolerance=%d", r);
+ r = dict_lookup_grep (zh->reg->dict, term_dict, r, grep_info,
+ &max_pos, 2, grep_handle);
+ if (r)
+ logf (LOG_WARN, "dict_lookup_grep err, trunc=eregular: %d",
+ r);
+ break;
+ case 104: /* process # and ! in term */
+ term_dict[j++] = '(';
+ if (!term_104 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ")");
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
+ &max_pos, 0, grep_handle);
+ if (r)
+ logf (LOG_WARN, "dict_lookup_grep err, trunc=#/!: %d", r);
+ break;
+ case 105: /* process * and ! in term */
+ term_dict[j++] = '(';
+ if (!term_105 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst, 1))
+ return 0;
+ strcat (term_dict, ")");
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
+ &max_pos, 0, grep_handle);
+ if (r)
+ logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r);
+ break;
+ case 106: /* process * and ! in term */
+ term_dict[j++] = '(';
+ if (!term_105 (zh->reg->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst, 0))
+ return 0;
+ strcat (term_dict, ")");
+ r = dict_lookup_grep (zh->reg->dict, term_dict, 0, grep_info,
+ &max_pos, 0, grep_handle);
+ if (r)
+ logf (LOG_WARN, "dict_lookup_grep err, trunc=*/!: %d", r);
+ 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;
+}
+
+
+/* convert APT search term to UTF8 */
+static int zapt_term_to_utf8 (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ char *termz)
+{
+ size_t sizez;
+ Z_Term *term = zapt->term;
+
+ switch (term->which)
+ {
+ case Z_Term_general:
+ if (zh->iconv_to_utf8 != 0)
+ {
+ char *inbuf = term->u.general->buf;
+ size_t inleft = term->u.general->len;
+ char *outbuf = termz;
+ size_t outleft = IT_MAX_WORD-1;
+ size_t ret;
+
+ ret = yaz_iconv(zh->iconv_to_utf8, &inbuf, &inleft,
+ &outbuf, &outleft);
+ if (ret == (size_t)(-1))
+ {
+ ret = yaz_iconv(zh->iconv_to_utf8, 0, 0, 0, 0);
+ zh->errCode = 125;