1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl 25-scan.t'
6 use Test::More tests => 81;
8 BEGIN { use_ok('ZOOM') };
10 my $host = "z3950.indexdata.com/gils";
12 eval { $conn = new ZOOM::Connection($host, 0) };
13 ok(!$@, "connection to '$host'");
15 $conn->option(number => 10);
16 my($ss, $n) = scan($conn, 0, "w", 10);
20 my $previous = ""; # Sorts before all legitimate terms
21 foreach my $i (1 .. $n) {
22 my($term, $occ) = $ss->term($i-1);
24 "got term $i of $n: '$term' ($occ occurences)");
25 ok($term ge $previous, "term '$term' ge previous '$previous'");
28 (my $disp, $occ) = $ss->display_term($i-1);
30 "display term $i of $n: '$disp' ($occ occurences)");
31 ok(lc($disp) eq lc($term),
32 "display term $i ($disp) equivalent to term ($term)");
36 ok(1, "destroyed scanset");
37 eval { $ss->destroy() };
38 ok(defined $@ && $@ =~ /been destroy\(\)ed/,
39 "can't re-destroy scanset");
41 # Now re-scan, but only for words that occur in the title
42 # This time, use a Query object for the start-term
43 ($ss, $n) = scan($conn, 1, new ZOOM::Query::PQF('@attr 1=4 w'), 6);
45 $previous = ""; # Sorts before all legitimate terms
46 foreach my $i (1 .. $n) {
47 my($term, $occ) = $ss->term($i-1);
49 "got title term $i of $n: '$term' ($occ occurences)");
50 ok($term ge $previous, "title term '$term' ge previous '$previous'");
53 # Previously we used to assert that the each title-term was
54 # included in the initial term-list that we got by scanning across
55 # all indexes. Of course this will not in general be true,
56 # because not all terms are title terms, which means that the $n
57 # title terms will include some that are past the end of $n
58 # general terms. So remove that test.
59 #ok((grep { $term eq $_ } @terms), "title term ($term) was in term list (@terms)");
63 ok(1, "destroyed second scanset");
65 # Now re-do the same scan, but limiting the results to four terms at a
66 # time. This time, use a CQL query
67 $conn->option(number => 4);
68 $conn->option(cqlfile => "samples/cql/pqf.properties");
70 ($ss, $n) = scan($conn, 1, new ZOOM::Query::CQL2RPN('title=w', $conn), 4);
71 # Get last term and use it as seed for next scan
72 my($term, $occ) = $ss->term($n-1);
73 ok($ss->option("position") == 1,
74 "seed-term is start of returned list");
76 "got last title term '$term' to use as seed");
79 ok(1, "destroyed third scanset");
81 $conn->option(cclfile => "samples/ccl/default.bib");
82 ($ss, $n) = scan($conn, 1, new ZOOM::Query::CCL2RPN('ti=w', $conn), 4);
83 # Get last term and use it as seed for next scan
84 ($term, $occ) = $ss->term($n-1);
85 ok($ss->option("position") == 1,
86 "seed-term is start of returned list");
88 "got last title term '$term' to use as seed");
91 ok(1, "destroyed fourth scanset");
93 # We want the seed-term to be in "position zero", i.e. just before the start
94 $conn->option(position => 0);
95 ($ss, $n) = scan($conn, 0, "\@attr 1=4 $term", 2);
96 ok($ss->option("position") == 0,
97 "seed-term before start of returned list");
99 # Silly test of option setting and getting
100 $ss->option(position => "fruit");
101 ok($ss->option("position") eq "fruit",
102 "option setting/getting works");
105 ok(1, "destroyed fifth scanset");
107 # Some more testing still to do: see comment in "15-scan.t"
111 my($conn, $startterm_is_query, $startterm, $nexpected) = @_;
115 if ($startterm_is_query) {
116 $ss = $conn->scan($startterm);
118 $ss = $conn->scan_pqf($startterm);
121 ok(!$@, "scan for '$startterm'");
124 ok(defined $n, "got size");
125 ok($n == $nexpected, "got $n terms for '$startterm' (expected $nexpected)");