Cleaned test scripts to be (nearly?) atomic
[idzebra-moved-to-github.git] / perl / t / 05_search.t
1 #!perl
2 # =============================================================================
3 # $Id: 05_search.t,v 1.5 2004-09-15 14:11:06 heikki Exp $
4 #
5 # Perl API header
6 # =============================================================================
7 BEGIN {
8     if ($ENV{PERL_CORE}) {
9         chdir 't' if -d 't';
10     }
11     push (@INC,'demo','blib/lib','blib/arch');
12 }
13
14 use strict;
15 use warnings;
16
17 use Test::More tests => 7;
18
19 # ----------------------------------------------------------------------------
20 BEGIN {
21     use IDZebra;
22     unlink("test05.log");
23     IDZebra::logFile("test05.log");
24     use_ok('IDZebra::Session'); 
25     use_ok('pod');
26 }
27
28
29 # ----------------------------------------------------------------------------
30 # Session opening and closing
31 my $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
32                                   groupName => 'demo2');
33 isa_ok($sess,"IDZebra::Session");
34
35 # Insert some test data
36 my $ret;
37 my $sysno;
38 my $F;
39 my $filecount=0;
40 $sess->databases('demo1', 'demo2');
41 $sess->init();
42 for $F (<"lib/IDZebra/*.pm">)
43 {
44     ($ret,$sysno)=$sess->insert_record (file=>$F, recordType => 'grs.perl.pod');
45     ok( $ret==0, "inserted $F");
46     $filecount++;
47 }
48 # ----------------------------------------------------------------------------
49 # search
50
51 my ($hits, $expected);
52
53 # Search 1 databases
54 my $rs1 = $sess->search(cqlmap    => 'demo/cql.map',
55                         cql       => 'IDZebra',
56                         termset   => 1,
57                         databases => [qw(demo1)]);
58
59 $expected = $filecount;
60 $hits = $rs1->count;
61 ok(($hits == $expected), "CQL search - found $hits/$expected records");
62
63
64 $sess->databases('demo1', 'demo2');
65 my @dblist = $sess->databases;
66 ok(($#dblist == 1), "Select multiple databases"); 
67
68
69 # Search 2 databases
70 my $rs2 = $sess->search(cqlmap    => 'demo/cql.map',
71                         cql       => 'IDZebra');
72 $expected = $filecount * 2;
73 $hits = $rs2->count;
74 ok(($hits == $expected), "CQL search - found $hits/$expected records");
75
76 # RPN search;
77 my $rs3 = $sess->search(cqlmap    => 'demo/cql.map',
78                         pqf       => '@attr 1=4 IDZebra');
79 $expected = $filecount * 2;
80 $hits = $rs3->count;
81 ok(($hits == $expected), "RPN search - found $hits/$expected records");
82
83 #### Terms is broken time being, don't bother testing it
84 # Termlists;
85 #my $rs4 = $sess->search(pqf       => '@attr 1=4 @and IDZebra Session');
86 #$expected = 2;
87 #$hits = $rs4->count;
88 #ok(($hits == $expected), "RPN search - found $hits/$expected records");
89 #print STDERR "Test 8: found $hits of $expected\n";
90 #
91 #my @terms = $rs4->terms();
92 #ok(($#terms == 1), "Got 2 terms in RPN expression");
93 #my $cc = 0;
94 #foreach my $t (@terms) {
95 #    if ($t->{term} eq 'IDZebra') {
96 #       ok(($t->{count} = $filecount*2), "Term IDZebra ($t->{count})");
97 #       $cc++;
98 #    }
99 #    elsif ($t->{term} eq 'Session') {
100 #       ok(($t->{count} = 2), "Term Session ($t->{count})");
101 #       $cc++;
102 #    } else {
103 #       ok(0,"Invalid term $t->{term}");
104 #    }
105 #
106 #}
107 #ok (($cc == 2), "Got 2 terms for RS");
108
109
110
111 # More specific search
112
113
114 # ----------------------------------------------------------------------------
115 # Close session
116
117 $sess->close;