Fix generic proximity for re-occuring 2nd op.
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 6 Oct 2009 11:06:44 +0000 (13:06 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 6 Oct 2009 11:14:35 +0000 (13:14 +0200)
Fix generic proximity. This patch makes it handle this case:
"a b a" with a search for @prox 0 1 1 2 k 2 b a .

rset/rsprox.c
test/api/test_search.c

index 6972828..15e5b19 100644 (file)
@@ -230,51 +230,60 @@ static int r_forward(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
                     if (n < 500)
                         seqno[n++] = (*kctrl->getseq)(p->buf[0]);
                 }
-                for (i = 0; i<n; i++)
+                /* set up return buffer.. (save buf[1]) */
+                memcpy(buf, p->buf[1], kctrl->key_size);
+                if (term)
+                    *term = p->terms[1];
+                while (1)
                 {
-                    zint diff = (*kctrl->getseq)(p->buf[1]) - seqno[i];
-                    int excl = info->exclusion;
-                    if (!info->ordered && diff < 0)
-                        diff = -diff;
-                    switch (info->relation)
+                    for (i = 0; i < n; i++)
                     {
-                    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;
+                        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)
+                        {
+                            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]);
+                    if (!p->more[1])
                         break;
-                    case 6:      /* != */
-                        if (diff != info->distance && diff >= 0)
-                            excl = !excl;
+                    cmp = (*kctrl->cmp)(buf, p->buf[1]);
+                    if (cmp <= - rfd->rset->scope || cmp >= rfd->rset->scope)
                         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]);
             }
         }
     }
index 80e75d3..9fe04ec 100644 (file)
@@ -246,6 +246,12 @@ static void tst(int argc, char **argv)
     /* exl=0 distance=1 order=1 relation=3 (=), known, unit=word */
     YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 3 k 2 a b", 1));
 
+
+    /* exl=0 distance=1 order=1 relation=3 (=), known, unit=word */
+    YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 3 k 2 c a", 1));
+    /* exl=0 distance=1 order=1 relation=2 (<=), known, unit=word */
+    YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 2 k 2 c a", 1));
+
     /* 3 term @prox test.. */
     YAZ_CHECK(tl_query(zh, "@attr 1=1016 \"a b c\"", 1));
 
@@ -255,7 +261,7 @@ static void tst(int argc, char **argv)
     /* left associative (works fine) */
     YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 2 k 2 @prox 0 1 1 2 k 2 a b c", 1));
 
-    /* exl=0 distance=1 order=1 relation=3 (=), known, unit=word *
+    /* exl=0 distance=1 order=1 relation=3 (=), known, unit=word */
     /* right associative (does not work, so zero hits) */
     YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 3 k 2 a @prox 0 1 1 3 k 2 b c", 0));
     /* left associative (works fine) */