97659833761fe850665a6f1ea85650a28ab41e01
[idzebra-moved-to-github.git] / perl / t / 05_search.t
1 #!perl
2 # =============================================================================
3 # $Id: 05_search.t,v 1.4 2004-07-28 08:15:47 adam 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 => 12;
18
19 # ----------------------------------------------------------------------------
20 # Session opening and closing
21 BEGIN {
22     use IDZebra;
23     unlink("test05.log");
24     IDZebra::logFile("test05.log");
25     use_ok('IDZebra::Session'); 
26     use_ok('pod');
27 }
28
29
30 # ----------------------------------------------------------------------------
31 # Session opening and closing
32 my $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
33                                   groupName => 'demo2');
34 isa_ok($sess,"IDZebra::Session");
35
36 # ----------------------------------------------------------------------------
37 # search
38 our $filecount = 8;
39
40 my ($hits, $expected);
41
42 # Search 1 databases
43 my $rs1 = $sess->search(cqlmap    => 'demo/cql.map',
44                         cql       => 'IDZebra',
45                         termset   => 1,
46                         databases => [qw(demo1)]);
47
48 $expected = $filecount;
49 $hits = $rs1->count;
50 ok(($hits == $expected), "CQL search - found $hits/$expected records");
51
52
53 $sess->databases('demo1', 'demo2');
54 my @dblist = $sess->databases;
55 ok(($#dblist == 1), "Select multiple databases"); 
56
57
58 # Search 2 databases
59 my $rs2 = $sess->search(cqlmap    => 'demo/cql.map',
60                         cql       => 'IDZebra');
61 $expected = $filecount * 2;
62 $hits = $rs2->count;
63 ok(($hits == $expected), "CQL search - found $hits/$expected records");
64
65 # RPN search;
66 my $rs3 = $sess->search(cqlmap    => 'demo/cql.map',
67                         pqf       => '@attr 1=4 IDZebra');
68 $expected = $filecount * 2;
69 $hits = $rs3->count;
70 ok(($hits == $expected), "RPN search - found $hits/$expected records");
71
72 # Termlists;
73 my $rs4 = $sess->search(pqf       => '@attr 1=4 @and IDZebra Session');
74 $expected = 2;
75 $hits = $rs4->count;
76 ok(($hits == $expected), "RPN search - found $hits/$expected records");
77
78 my @terms = $rs4->terms();
79 ok(($#terms == 1), "Got 2 terms in RPN expression");
80 my $cc = 0;
81 foreach my $t (@terms) {
82     if ($t->{term} eq 'IDZebra') {
83         ok(($t->{count} = $filecount*2), "Term IDZebra ($t->{count})");
84         $cc++;
85     }
86     elsif ($t->{term} eq 'Session') {
87         ok(($t->{count} = 2), "Term Session ($t->{count})");
88         $cc++;
89     } else {
90         ok(0,"Invalid term $t->{term}");
91     }
92
93 }
94 ok (($cc == 2), "Got 2 terms for RS");
95
96
97
98 # More specific search
99
100
101 # ----------------------------------------------------------------------------
102 # Close session
103
104 $sess->close;