From: Adam Dickmeiss Date: Thu, 1 Sep 2011 10:51:58 +0000 (+0200) Subject: Scan: allow preferred position > number + 1 X-Git-Tag: v2.0.49~1 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=049a7363a54b6e467e8f0d2202b01848fe98dc70 Scan: allow preferred position > number + 1 Add a few scan test cases as well. --- diff --git a/index/rpnscan.c b/index/rpnscan.c index f638f83..341acb2 100644 --- a/index/rpnscan.c +++ b/index/rpnscan.c @@ -300,13 +300,6 @@ static ZEBRA_RES rpn_scan_norm(ZebraHandle zh, ODR stream, NMEM nmem, odr_malloc(stream, *num_entries * sizeof(*glist)); *is_partial = 0; - if (*position > *num_entries+1) - { - *is_partial = 1; - *position = 1; - *num_entries = 0; - return ZEBRA_OK; - } rpn_char_map_prepare(zh->reg, zm, &rcmi); for (i = 0; i < ord_no; i++) @@ -376,8 +369,13 @@ static ZEBRA_RES rpn_scan_norm(ZebraHandle zh, ODR stream, NMEM nmem, { /* did not get all terms; adjust the real position and reduce number of entries */ - glist = glist + dif; - *num_entries -= dif; + if (dif < *num_entries) + { + glist = glist + dif; + *num_entries -= dif; + } + else + *num_entries = 0; *position -= dif; *is_partial = 1; } @@ -438,7 +436,7 @@ static ZEBRA_RES rpn_scan_norm(ZebraHandle zh, ODR stream, NMEM nmem, pos++; } - if (pos != *num_entries) + if (pos < *num_entries) { if (pos >= 0) *num_entries = pos; diff --git a/test/api/test_scan.c b/test/api/test_scan.c index a30c833..d1e3f8c 100644 --- a/test/api/test_scan.c +++ b/test/api/test_scan.c @@ -136,12 +136,33 @@ static void tst(int argc, char **argv) YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 10, 100, 1, 6, 1, ent)); } + { - const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 }; + const char *ent[] = { 0 }; YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 22, 10, 1, 0, 1, ent)); } { + const char *ent[] = { "a", "b", "c", "d", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 f", 6, 4, 6, 4, 0, ent)); + } + + { + const char *ent[] = { "a", "b", "c", "d", "e", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 f", 6, 5, 6, 5, 0, ent)); + } + + { + const char *ent[] = { "a", "b", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 c", 6, 5, 3, 2, 1, ent)); + } + + { + const char *ent[] = { "c", "d", "e", "f", 0 }; + YAZ_CHECK(tl_scan(zh, "@attr 1=4 c", 1, 6, 1, 4, 1, ent)); + } + + { const char *ent[] = { 0 }; YAZ_CHECK(tl_scan(zh, "@attr 1=4 z", -22, 10, -22, 0, 1, ent)); }