Left-assoc for proximity code and tests for it
[idzebra-moved-to-github.git] / rset / rsprox.c
index a88e4fc..6972828 100644 (file)
@@ -1,8 +1,5 @@
-/* $Id: rsprox.c,v 1.32 2006-08-14 10:40:21 adam Exp $
-   Copyright (C) 1995-2006
-   Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+   Copyright (C) 1994-2009 Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -197,10 +194,11 @@ static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
             }
             if (i == ct->no_children)
             {
-                memcpy (buf, p->buf[0], kctrl->key_size);
+                i = ct->no_children-1;
+                memcpy(buf, p->buf[i], kctrl->key_size);
                 if (term)
-                    *term = p->terms[0];
-                p->more[0] = rset_read (p->rfd[0], p->buf[0], &p->terms[0]);
+                    *term = p->terms[i];
+                p->more[i] = rset_read(p->rfd[i], p->buf[i], &p->terms[i]);
                 p->hits++;
                 return 1;
             }
@@ -224,11 +222,14 @@ static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
                 
                 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)
+                                        p->buf[0], &p->terms[0])))
+                {
+                    cmp = (*kctrl->cmp)(p->buf[0], p->buf[1]);
+                    if (cmp <= - rfd->rset->scope || cmp >= rfd->rset->scope)
+                        break;
                     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];
@@ -336,6 +337,7 @@ static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab