From fb791f9a754adf7b26695fdb1ddd0fdee9bf28f9 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 6 Oct 2009 13:06:44 +0200 Subject: [PATCH] Fix generic proximity for re-occuring 2nd op. 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 | 89 ++++++++++++++++++++++++++---------------------- test/api/test_search.c | 8 ++++- 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/rset/rsprox.c b/rset/rsprox.c index 6972828..15e5b19 100644 --- a/rset/rsprox.c +++ b/rset/rsprox.c @@ -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; ibuf[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]); } } } diff --git a/test/api/test_search.c b/test/api/test_search.c index 80e75d3..9fe04ec 100644 --- a/test/api/test_search.c +++ b/test/api/test_search.c @@ -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) */ -- 1.7.10.4