- 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_DEBUG, "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, rel=gt: %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;
- }
- }
- *term_sub = termp;
- logf (LOG_DEBUG, "%d positions", grep_info->isam_p_indx);
- return 1;
-}
-
-static void trans_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- char *termz)
-{
- size_t sizez;
- Z_Term *term = zapt->term;
-
- sizez = term->u.general->len;
- if (sizez > IT_MAX_WORD-1)
- sizez = IT_MAX_WORD-1;
- memcpy (termz, term->u.general->buf, sizez);
- termz[sizez] = '\0';
-}
-
-static void trans_scan_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
- char *termz, int reg_type)
-{
- Z_Term *term = zapt->term;
- const char **map;
- const char *cp = (const char *) term->u.general->buf;
- const char *cp_end = cp + term->u.general->len;
- const char *src;
- int i = 0;
- const char *space_map = NULL;
- int len;
-
- while ((len = (cp_end - cp)) > 0)
- {
- map = zebra_maps_input (zh->reg->zebra_maps, reg_type, &cp, len);
- if (**map == *CHR_SPACE)
- space_map = *map;
- else
- {
- if (i && space_map)
- for (src = space_map; *src; src++)
- termz[i++] = *src;
- space_map = NULL;
- for (src = *map; *src; src++)
- termz[i++] = *src;
- }
- }
- termz[i] = '\0';
-}
-
-static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no,
- int ordered, int exclusion, int relation, int distance)
-{
- int i;
- RSFD *rsfd;
- int *more;
- struct it_key **buf;
- RSET result;
- char prox_term[1024];
- int length_prox_term = 0;
- int min_nn = 10000000;
- int term_index;
- const char *flags = NULL;
-
- rsfd = (RSFD *) xmalloc (sizeof(*rsfd)*rset_no);
- more = (int *) xmalloc (sizeof(*more)*rset_no);
- buf = (struct it_key **) xmalloc (sizeof(*buf)*rset_no);
-
- *prox_term = '\0';
- for (i = 0; i<rset_no; i++)
- {
- int j;
- for (j = 0; j<rset[i]->no_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 (lterm + length_prox_term < sizeof(prox_term)-1)