+ case 3:
+ default:
+ logf (LOG_DEBUG, "Relation =");
+ if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_component,
+ space_split, term_dst))
+ return 0;
+ strcat (term_tmp, "(");
+ strcat (term_tmp, term_component);
+ strcat (term_tmp, ")");
+ }
+ return 1;
+}
+
+static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ const char **term_sub,
+ oid_value attributeSet, NMEM stream,
+ struct grep_info *grep_info,
+ int reg_type, int complete_flag,
+ int num_bases, char **basenames,
+ char *term_dst)
+{
+ char term_dict[2*IT_MAX_WORD+4000];
+ int j, r, base_no;
+ AttrType truncation;
+ int truncation_value;
+ AttrType use;
+ int use_value;
+ oid_value curAttributeSet = attributeSet;
+ const char *termp;
+ struct rpn_char_map_info rcmi;
+ int space_split = complete_flag ? 0 : 1;
+
+ rpn_char_map_prepare (zh, reg_type, &rcmi);
+ attr_init (&use, zapt, 1);
+ use_value = attr_find (&use, &curAttributeSet);
+ logf (LOG_DEBUG, "string_term, use value %d", use_value);
+ attr_init (&truncation, zapt, 5);
+ truncation_value = attr_find (&truncation, NULL);
+ logf (LOG_DEBUG, "truncation value %d", truncation_value);
+
+ if (use_value == -1)
+ use_value = 1016;
+
+ for (base_no = 0; base_no < num_bases; base_no++)
+ {
+ attent attp;
+ data1_local_attribute *local_attr;
+ int max_pos, prefix_len = 0;
+
+ termp = *term_sub;
+ if ((r=att_getentbyatt (zh, &attp, curAttributeSet, use_value)))
+ {
+ logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d r=%d",
+ curAttributeSet, use_value, r);
+ if (r == -1)
+ {
+ char val_str[32];
+ sprintf (val_str, "%d", use_value);
+ zh->errCode = 114;
+ zh->errString = nmem_strdup (stream, val_str);
+ }
+ else
+ {
+ int oid[OID_SIZE];
+ struct oident oident;
+
+ oident.proto = PROTO_Z3950;
+ oident.oclass = CLASS_ATTSET;
+ oident.value = curAttributeSet;
+ oid_ent_to_oid (&oident, oid);
+
+ zh->errCode = 121;
+ zh->errString = nmem_strdup (stream, oident.desc);
+ }
+ return -1;
+ }
+ if (zebraExplain_curDatabase (zh->zei, basenames[base_no]))
+ {
+ zh->errCode = 109; /* Database unavailable */
+ zh->errString = basenames[base_no];
+ return -1;
+ }
+ for (local_attr = attp.local_attributes; local_attr;
+ local_attr = local_attr->next)
+ {
+ int ord;
+ char ord_buf[32];
+ int i, ord_len;
+
+ ord = zebraExplain_lookupSU (zh->zei, attp.attset_ordinal,
+ local_attr->local);
+ if (ord < 0)
+ continue;
+ if (prefix_len)
+ term_dict[prefix_len++] = '|';
+ else
+ term_dict[prefix_len++] = '(';
+
+ ord_len = key_SU_code (ord, ord_buf);
+ for (i = 0; i<ord_len; i++)
+ {
+ term_dict[prefix_len++] = 1;
+ term_dict[prefix_len++] = ord_buf[i];
+ }
+ }
+ if (!prefix_len)
+ {
+ char val_str[32];
+ sprintf (val_str, "%d", use_value);
+ zh->errCode = 114;
+ zh->errString = nmem_strdup (stream, val_str);
+ return -1;
+ }
+ term_dict[prefix_len++] = ')';
+ term_dict[prefix_len++] = 1;
+ term_dict[prefix_len++] = reg_type;
+ logf (LOG_DEBUG, "reg_type = %d", term_dict[prefix_len-1]);
+ term_dict[prefix_len] = '\0';
+ 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_DEBUG, "dict_lookup_grep: %s", term_dict+prefix_len);
+ r = dict_lookup_grep (zh->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->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ".*)");
+ dict_lookup_grep (zh->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->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ")");
+ dict_lookup_grep (zh->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->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst))
+ return 0;
+ strcat (term_dict, ".*)");
+ dict_lookup_grep (zh->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->zebra_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;
+ case 102: /* Regexp-1 */
+ term_dict[j++] = '(';
+ if (!term_102 (zh->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->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->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->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->zebra_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;
+ case 105: /* process * and ! in term */
+ term_dict[j++] = '(';
+ if (!term_105 (zh->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst, 1))
+ 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;
+ case 106: /* process * and ! in term */
+ term_dict[j++] = '(';
+ if (!term_105 (zh->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split, term_dst, 0))
+ 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;
+ 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->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_proximity (ZebraHandle zh, RSET rset1, RSET rset2,
+ int ordered,
+ int exclusion, int relation, int distance)
+{
+ int i;
+ RSFD rsfd1, rsfd2;
+ int more1, more2;
+ struct it_key buf1, buf2;
+ RSFD rsfd_result;
+ RSET result;
+ rset_temp_parms parms;
+ int term_index;
+
+ rsfd1 = rset_open (rset1, RSETF_READ);
+ more1 = rset_read (rset1, rsfd1, &buf1, &term_index);
+
+ rsfd2 = rset_open (rset2, RSETF_READ);
+ more2 = rset_read (rset2, rsfd2, &buf2, &term_index);
+
+ parms.key_size = sizeof (struct it_key);
+ parms.temp_path = res_get (zh->res, "setTmpDir");
+ result = rset_create (rset_kind_temp, &parms);
+ rsfd_result = rset_open (result, RSETF_WRITE);
+
+ logf (LOG_DEBUG, "rpn_proximity excl=%d ord=%d rel=%d dis=%d",
+ exclusion, ordered, relation, distance);
+ while (more1 && more2)
+ {
+ int cmp = key_compare_it (&buf1, &buf2);
+ if (cmp < -1)
+ more1 = rset_read (rset1, rsfd1, &buf1, &term_index);
+ else if (cmp > 1)
+ more2 = rset_read (rset2, rsfd2, &buf2, &term_index);
+ else
+ {
+ int sysno = buf1.sysno;
+ int seqno[500];
+ int n = 0;
+
+ seqno[n++] = buf1.seqno;
+ while ((more1 = rset_read (rset1, rsfd1, &buf1, &term_index)) &&
+ sysno == buf1.sysno)
+ if (n < 500)
+ seqno[n++] = buf1.seqno;
+ do
+ {
+ for (i = 0; i<n; i++)
+ {
+ int diff = buf2.seqno - seqno[i];
+ int excl = exclusion;
+ if (!ordered && diff < 0)
+ diff = -diff;
+ switch (relation)
+ {
+ case 1: /* < */
+ if (diff < distance)
+ excl = !excl;
+ break;
+ case 2: /* <= */
+ if (diff <= distance)
+ excl = !excl;
+ break;
+ case 3: /* == */
+ if (diff == distance)
+ excl = !excl;
+ break;
+ case 4: /* >= */
+ if (diff >= distance)
+ excl = !excl;
+ break;
+ case 5: /* > */
+ if (diff > distance)
+ excl = !excl;
+ break;
+ case 6: /* != */
+ if (diff != distance)
+ excl = !excl;
+ break;
+ }
+ if (excl)
+ rset_write (result, rsfd_result, &buf2);
+ }
+ } while ((more2 = rset_read (rset2, rsfd2, &buf2, &term_index)) &&
+ sysno == buf2.sysno);
+ }
+ }
+ rset_close (result, rsfd_result);
+ rset_close (rset1, rsfd1);
+ rset_close (rset2, rsfd2);
+ return result;
+}
+
+static RSET rpn_prox (ZebraHandle zh, RSET *rset, int rset_no)
+{
+ 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)
+ {
+ 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; i<rset_no; i++)
+ {
+ buf[i] = (struct it_key *) xmalloc (sizeof(**buf));
+ rsfd[i] = rset_open (rset[i], RSETF_READ);
+ if (!(more[i] = rset_read (rset[i], rsfd[i], buf[i], &term_index)))
+ break;
+ }
+ if (i != rset_no)
+ {
+ rset_null_parms parms;
+
+ while (i >= 0)
+ {
+ rset_close (rset[i], rsfd[i]);
+ xfree (buf[i]);
+ --i;
+ }
+ parms.rset_term = rset_term_create (prox_term, length_prox_term,
+ flags);
+ parms.rset_term->nn = 0;
+ result = rset_create (rset_kind_null, &parms);
+ }
+ else
+ {
+ rset_temp_parms parms;
+ RSFD rsfd_result;
+
+ 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");
+ result = rset_create (rset_kind_temp, &parms);
+ rsfd_result = rset_open (result, RSETF_WRITE);
+
+ while (*more)
+ {
+ for (i = 1; i<rset_no; i++)
+ {
+ int cmp;
+
+ if (!more[i])
+ {
+ *more = 0;
+ break;
+ }
+ cmp = key_compare_it (buf[i], buf[i-1]);
+ if (cmp > 1)
+ {
+ more[i-1] = rset_read (rset[i-1], rsfd[i-1],
+ buf[i-1], &term_index);
+ break;
+ }
+ else if (cmp == 1)
+ {
+ if (buf[i-1]->seqno+1 != buf[i]->seqno)
+ {
+ more[i-1] = rset_read (rset[i-1], rsfd[i-1],
+ buf[i-1], &term_index);
+ break;
+ }
+ }
+ else
+ {
+ more[i] = rset_read (rset[i], rsfd[i], buf[i],
+ &term_index);
+ break;
+ }
+ }
+ if (i == rset_no)
+ {
+ rset_write (result, rsfd_result, buf[0]);
+ more[0] = rset_read (*rset, *rsfd, *buf, &term_index);
+ }
+ }
+
+ for (i = 0; i<rset_no; i++)
+ {
+ rset_close (rset[i], rsfd[i]);
+ xfree (buf[i]);
+ }
+ rset_close (result, rsfd_result);
+ }
+ xfree (buf);
+ xfree (more);
+ xfree (rsfd);
+ 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;
+ case 105:
+ 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_org,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type,
+ int num_bases, char **basenames)
+{
+ char term_dst[IT_MAX_WORD+1];
+ 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
+ grep_info.isam_p_size = 0;
+ grep_info.isam_p_buf = NULL;
+ grep_info.zh = zh;
+ grep_info.reg_type = reg_type;
+
+ while (1)
+ {
+ logf (LOG_DEBUG, "APT_phrase termp=%s", termp);
+ grep_info.isam_p_indx = 0;
+ r = string_term (zh, zapt, &termp, attributeSet, stream, &grep_info,
+ reg_type, complete_flag, num_bases, basenames,
+ term_dst);
+ if (r < 1)
+ break;
+ logf (LOG_DEBUG, "term: %s", term_dst);
+ rset[rset_no] = rset_trunc (zh, grep_info.isam_p_buf,
+ grep_info.isam_p_indx, term_dst,
+ strlen(term_dst), rank_type);
+ assert (rset[rset_no]);
+ if (++rset_no >= (int) (sizeof(rset)/sizeof(*rset)))
+ break;
+ }
+#ifdef TERM_COUNT
+ xfree(grep_info.term_no);
+#endif
+ xfree (grep_info.isam_p_buf);
+ if (rset_no == 0)
+ {
+ rset_null_parms parms;
+
+ parms.rset_term = rset_term_create (term_dst, -1, rank_type);
+ return rset_create (rset_kind_null, &parms);
+ }
+ else if (rset_no == 1)
+ return (rset[0]);
+ result = rpn_prox (zh, rset, rset_no);
+ for (i = 0; i<rset_no; i++)
+ rset_delete (rset[i]);
+ return result;
+}
+
+static RSET rpn_search_APT_or_list (ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ const char *termz_org,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type,
+ int num_bases, char **basenames)
+{
+ char term_dst[IT_MAX_WORD+1];
+ 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
+ grep_info.isam_p_size = 0;
+ grep_info.isam_p_buf = NULL;
+ grep_info.zh = zh;
+ grep_info.reg_type = reg_type;
+
+ while (1)
+ {
+ logf (LOG_DEBUG, "APT_or_list termp=%s", termp);
+ grep_info.isam_p_indx = 0;
+ r = string_term (zh, zapt, &termp, attributeSet, stream, &grep_info,
+ reg_type, complete_flag, num_bases, basenames,
+ term_dst);
+ if (r < 1)
+ break;
+ logf (LOG_DEBUG, "term: %s", term_dst);
+ rset[rset_no] = rset_trunc (zh, grep_info.isam_p_buf,
+ grep_info.isam_p_indx, term_dst,
+ strlen(term_dst), rank_type);
+ assert (rset[rset_no]);
+ if (++rset_no >= (int) (sizeof(rset)/sizeof(*rset)))
+ break;
+ }
+#ifdef TERM_COUNT
+ xfree(grep_info.term_no);
+#endif
+ xfree (grep_info.isam_p_buf);
+ if (rset_no == 0)
+ {
+ rset_null_parms parms;
+
+ parms.rset_term = rset_term_create (term_dst, -1, rank_type);
+ return rset_create (rset_kind_null, &parms);
+ }
+ result = rset[0];
+ for (i = 1; i<rset_no; i++)
+ {
+ rset_bool_parms bool_parms;
+
+ bool_parms.rset_l = result;
+ bool_parms.rset_r = rset[i];
+ bool_parms.key_size = sizeof(struct it_key);
+ bool_parms.cmp = key_compare_it;
+ result = rset_create (rset_kind_or, &bool_parms);
+ }
+ return result;
+}
+
+static RSET rpn_search_APT_and_list (ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ const char *termz_org,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type,
+ int num_bases, char **basenames)
+{
+ char term_dst[IT_MAX_WORD+1];
+ 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
+ grep_info.isam_p_size = 0;
+ grep_info.isam_p_buf = NULL;
+ grep_info.zh = zh;
+ grep_info.reg_type = reg_type;
+
+ while (1)
+ {
+ logf (LOG_DEBUG, "APT_and_list termp=%s", termp);
+ grep_info.isam_p_indx = 0;
+ r = string_term (zh, zapt, &termp, attributeSet, stream, &grep_info,
+ reg_type, complete_flag, num_bases, basenames,
+ term_dst);
+ if (r < 1)
+ break;
+ logf (LOG_DEBUG, "term: %s", term_dst);
+ rset[rset_no] = rset_trunc (zh, grep_info.isam_p_buf,
+ grep_info.isam_p_indx, term_dst,
+ strlen(term_dst), rank_type);
+ assert (rset[rset_no]);
+ if (++rset_no >= (int) (sizeof(rset)/sizeof(*rset)))
+ break;
+ }
+#ifdef TERM_COUNT
+ xfree(grep_info.term_no);
+#endif
+ xfree (grep_info.isam_p_buf);
+ if (rset_no == 0)
+ {
+ rset_null_parms parms;
+
+ parms.rset_term = rset_term_create (term_dst, -1, rank_type);
+ return rset_create (rset_kind_null, &parms);
+ }
+ result = rset[0];
+ for (i = 1; i<rset_no; i++)
+ {
+ rset_bool_parms bool_parms;
+
+ bool_parms.rset_l = result;
+ bool_parms.rset_r = rset[i];
+ bool_parms.key_size = sizeof(struct it_key);
+ bool_parms.cmp = key_compare_it;
+ result = rset_create (rset_kind_and, &bool_parms);
+ }
+ return result;
+}
+
+static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ const char **term_sub,
+ char *term_dict,
+ oid_value attributeSet,
+ struct grep_info *grep_info,
+ int *max_pos,
+ int reg_type,
+ char *term_dst)
+{
+ AttrType relation;
+ int relation_value;
+ int term_value;
+ int r;
+ char *term_tmp = term_dict + strlen(term_dict);
+
+ attr_init (&relation, zapt, 2);
+ relation_value = attr_find (&relation, NULL);
+
+ logf (LOG_DEBUG, "numeric relation value=%d", relation_value);
+
+ if (!term_100 (zh->zebra_maps, reg_type, term_sub, term_tmp, 1,
+ term_dst))
+ return 0;
+ term_value = atoi (term_tmp);
+ switch (relation_value)
+ {
+ case 1:
+ logf (LOG_DEBUG, "Relation <");
+ gen_regular_rel (term_tmp, term_value-1, 1);