2 # =============================================================================
3 # $Id: 08_scan.t,v 1.3 2004-09-15 14:11:06 heikki Exp $
6 # =============================================================================
11 push (@INC,'demo','blib/lib','blib/arch');
17 #use Test::More tests => 17;
18 use Test::More skip_all => "Something rotten with scan.";
20 # ----------------------------------------------------------------------------
21 # Session opening and closing
25 IDZebra::logFile("test08.log");
26 IDZebra::logLevel(15);
27 use_ok('IDZebra::Session');
32 # ----------------------------------------------------------------------------
33 # Session opening and closing
34 my $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
35 groupName => 'demo1');
37 # ----------------------------------------------------------------------------
38 # Insert some test data
45 $sess->databases('demo1', 'demo2');
46 $ret=$sess->end_trans;
49 $sess->databases('demo1', 'demo2');
50 for $F (<lib/IDZebra/*.pm>)
52 ($ret,$sysno)=$sess->insert_record (file=>$F, recordType => 'grs.perl.pod');
53 ok( $ret==0, "inserted $F");
54 #print STDERR "Inserted $F ok. ret=$ret sys=$sysno\n";
57 $ret=$sess->end_trans;
58 ok($filecount>0,"Inserted files");
59 is($ret->{inserted},$filecount, "Inserted all");
60 $sess->databases('demo1');
62 # -----------------------------------------------------------------------------
63 # Scan titles in multiple databases
65 my $sl1 = $sess->scan(expression => "\@attr 1=4 \@attr 6=2 a",
66 databases => [qw(demo1 demo2)]);
68 &test_list($sl1,$filecount, $filecount*2,1);
69 # -----------------------------------------------------------------------------
70 # Scan titles in a single and default database
71 my $sl2 = $sess->scan(expression => "\@attr 1=4 \@attr 6=2 a");
72 &test_list($sl2,$filecount, $filecount,1);
75 # -----------------------------------------------------------------------------
76 # Scan long list, with position...
77 my $sl3 = $sess->scan(expression => "\@attr 1=1016 a");
79 my @entries = $sl3->entries(position => 5,
80 num_entries => 10000);
82 my $count = $#entries + 1;
83 ok (($sl3->errCode == 0),"scan successful");
84 ok (($sl3->num_entries == $count),"fetched $count entries");
87 foreach my $se (@entries) {
88 $posok = 0 if ($se->position != $i);
91 ok (($posok),"position of each term");
94 # -----------------------------------------------------------------------------
96 eval {my $sl4 = $sess->scan(expression => "\@attr 1=9999 a");};
97 ok (($@ ne ""),"Wrong scan die");
98 ok (($sess->errCode != 0),
99 "Error reported in session: ".$sess->errCode.
100 " (". $sess->errString. ")");
103 # ----------------------------------------------------------------------------
107 # ============================================================================
109 my ($sl, $ecount, $occ, $offset) = @_;
110 my @entries = $sl->entries();
111 my $count = $#entries + 1;
112 ok (($sl->errCode == 0),"scan successfull");
113 ok (($sl->num_entries == $ecount),
114 "number of entries is ".$sl->num_entries);
115 ok (($count == $sl->num_entries),"fetched $count entries");
120 foreach my $se (@entries) {
121 $occcount += $se->occurrences();
122 $posok = 0 if ($se->position != $i);
126 ok ($occcount == $occ,"occurrences: $occcount");
127 ok (($posok),"position of each term");