- while (p->more[0] && p->more[1])
- {
- int cmp = (*info->p.cmp)(p->buf[0], p->buf[1]);
- if (cmp < -1)
- p->more[0] = rset_forward (info->p.rset[0], p->rfd[0],
- p->buf[0],
- term_index, info->p.cmp, p->buf[0]);
- else if (cmp > 1)
- p->more[1] = rset_forward (info->p.rset[1], p->rfd[1],
- p->buf[1],
- term_index, info->p.cmp, p->buf[1]);
- else
- {
- int seqno[500];
- int n = 0;
-
- seqno[n++] = (*info->p.getseq)(p->buf[0]);
- while ((p->more[0] = rset_read (info->p.rset[0], p->rfd[0],
- p->buf[0],
- term_index)) >= -1 &&
- p->more[0] <= -1)
- if (n < 500)
- seqno[n++] = (*info->p.getseq)(p->buf[0]);
-
- for (i = 0; i<n; i++)
- {
- int diff = (*info->p.getseq)(p->buf[1]) - seqno[i];
- int excl = info->p.exclusion;
- if (!info->p.ordered && diff < 0)
- diff = -diff;
- switch (info->p.relation)
- {
- case 1: /* < */
- if (diff < info->p.distance && diff >= 0)
- excl = !excl;
- break;
- case 2: /* <= */
- if (diff <= info->p.distance && diff >= 0)
- excl = !excl;
- break;
- case 3: /* == */
- if (diff == info->p.distance && diff >= 0)
- excl = !excl;
- break;
- case 4: /* >= */
- if (diff >= info->p.distance && diff >= 0)
- excl = !excl;
- break;
- case 5: /* > */
- if (diff > info->p.distance && diff >= 0)
- excl = !excl;
- break;
- case 6: /* != */
- if (diff != info->p.distance && diff >= 0)
- excl = !excl;
- break;
- }
- if (excl)
- {
- memcpy (buf, p->buf[1], info->p.key_size);
- *term_index = 0;
-
- p->more[1] = rset_read (info->p.rset[1],
- p->rfd[1], p->buf[1],
- term_index);
- return 1;
- }
- }
- p->more[1] = rset_read (info->p.rset[1], p->rfd[1],
- p->buf[1],
- term_index);
- }
- }
+ while (p->more[0] && p->more[1])
+ {
+ int cmp = (*kctrl->cmp)(p->buf[0], p->buf[1]);
+ if ( cmp <= - rfd->rset->scope) /* cmp<-1*/
+ p->more[0] = rset_forward (p->rfd[0], p->buf[0],
+ &p->terms[0],p->buf[1]);
+ else if ( cmp >= rfd->rset->scope ) /* cmp>1 */
+ p->more[1] = rset_forward (p->rfd[1], p->buf[1],
+ &p->terms[1],p->buf[0]);
+ else
+ {
+ zint seqno[500]; /* FIXME - why 500 ?? */
+ int n = 0;
+
+ seqno[n++] = (*kctrl->getseq)(p->buf[0]);
+ while ((p->more[0] = rset_read (p->rfd[0],
+ p->buf[0], &p->terms[0])) >= -1 &&
+ p->more[0] <= -1)
+ if (n < 500)
+ seqno[n++] = (*kctrl->getseq)(p->buf[0]);
+
+ for (i = 0; i<n; i++)
+ {
+ zint diff = (*kctrl->getseq)(p->buf[1]) - seqno[i];
+ int excl = info->exclusion;
+ if (!info->ordered && diff < 0)
+ diff = -diff;
+ switch (info->relation)
+ {
+ case 1: /* < */
+ if (diff < info->distance && diff >= 0)
+ excl = !excl;
+ break;
+ case 2: /* <= */
+ if (diff <= info->distance && diff >= 0)
+ excl = !excl;
+ break;
+ case 3: /* == */
+ if (diff == info->distance && diff >= 0)
+ excl = !excl;
+ break;
+ case 4: /* >= */
+ if (diff >= info->distance && diff >= 0)
+ excl = !excl;
+ break;
+ case 5: /* > */
+ if (diff > info->distance && diff >= 0)
+ excl = !excl;
+ break;
+ case 6: /* != */
+ if (diff != info->distance && diff >= 0)
+ excl = !excl;
+ break;
+ }
+ if (excl)
+ {
+ memcpy (buf, p->buf[1], kctrl->key_size);
+ if (term)
+ *term = p->terms[1];
+ p->more[1] = rset_read ( p->rfd[1], p->buf[1],
+ &p->terms[1]);
+ p->hits++;
+ return 1;
+ }
+ }
+ p->more[1] = rset_read (p->rfd[1], p->buf[1], &p->terms[1]);
+ }
+ }