2 # =============================================================================
3 # $Id: 08_scan.t,v 1.4 2004-09-20 15:59:48 heikki Exp $
6 # =============================================================================
11 push (@INC,'demo','blib/lib','blib/arch');
17 use Test::More tests => 32;
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
46 $sess->databases('demo1', 'demo2');
47 for $F (<lib/IDZebra/*.pm>)
49 ($ret,$sysno)=$sess->insert_record (file=>$F, recordType => 'grs.perl.pod');
50 ok( $ret==0, "inserted $F");
53 $ret=$sess->end_trans;
54 ok($filecount>0,"Inserted files");
55 is($ret->{inserted},$filecount, "Inserted all");
56 $sess->databases('demo1');
58 # -----------------------------------------------------------------------------
59 # Scan titles in a single (default) database
61 IDZebra::logMsg(2,"t08: Starting to scan");
62 my $sl0 = $sess->scan(expression => "\@attr 1=4 \@attr 6=1 a");
63 IDZebra::logMsg(2,"t08: scan done");
65 my @ent=$sl0->entries(position => 1,
68 is ($nent,3,"got 3 entries");
70 my $cnt= $sl0->num_entries;
72 is($cnt,3,"num_entries");
73 is($ent[0]->term(),"a", "first entry");
74 is($ent[1]->term(),"an", "second entry");
75 is($ent[2]->term(),"and", "third entry");
78 # -----------------------------------------------------------------------------
79 # Scan titles in a named database
81 my $sl1 = $sess->scan(expression => "\@attr 1=4 \@attr 6=2 a",
82 databases => [qw(demo1)]);
83 &test_list($sl1,$filecount, $filecount,1);
85 # FIXME - Should test multiple databases, but I can't get that to work
88 # -----------------------------------------------------------------------------
89 # Scan titles in a single and default database
90 my $sl2 = $sess->scan(expression => "\@attr 1=4 \@attr 6=2 a");
91 &test_list($sl2,$filecount, $filecount,1);
94 # -----------------------------------------------------------------------------
95 # Scan long list, with position...
96 my $sl3 = $sess->scan(expression => "\@attr 1=1016 a");
98 my @entries = $sl3->entries(position => 5,
99 num_entries => 10000);
101 my $count = $#entries + 1;
102 ok (($sl3->errCode == 0),"scan successful");
103 ok (($sl3->num_entries == $count),"fetched $count entries");
106 foreach my $se (@entries) {
107 $posok = 0 if ($se->position != $i);
110 ok (($posok),"position of each term");
113 # -----------------------------------------------------------------------------
115 eval {my $sl4 = $sess->scan(expression => "\@attr 1=9999 a");};
116 ok (($@ ne ""),"Wrong scan die");
117 ok (($sess->errCode != 0),
118 "Error reported in session: ".$sess->errCode.
119 " (". $sess->errString. ")");
122 # ----------------------------------------------------------------------------
126 # ============================================================================
128 my ($sl, $ecount, $occ, $offset) = @_;
129 my @entries = $sl->entries();
130 my $count = $#entries + 1;
131 ok (($sl->errCode == 0),"scan successfull");
132 ok (($sl->num_entries == $ecount),
133 "number of entries is ".$sl->num_entries);
134 is ($count,$sl->num_entries,"fetched $count entries");
139 foreach my $se (@entries) {
140 $occcount += $se->occurrences();
141 $posok = 0 if ($se->position != $i);
145 is ($occcount, $occ,"occurrences: $occcount");
146 ok (($posok),"position of each term");