Added support for resultset terms.
[idzebra-moved-to-github.git] / perl / t / 05_search.t
1 #!perl
2 # =============================================================================
3 # $Id: 05_search.t,v 1.3 2003-07-26 16:27:46 pop 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     IDZebra::logFile("test.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 # ----------------------------------------------------------------------------
36 # search
37 our $filecount = 8;
38
39 my ($hits, $expected);
40
41 # Search 1 databases
42 my $rs1 = $sess->search(cqlmap    => 'demo/cql.map',
43                         cql       => 'IDZebra',
44                         termset   => 1,
45                         databases => [qw(demo1)]);
46
47 $expected = $filecount;
48 $hits = $rs1->count;
49 ok(($hits == $expected), "CQL search - found $hits/$expected records");
50
51
52 $sess->databases('demo1', 'demo2');
53 my @dblist = $sess->databases;
54 ok(($#dblist == 1), "Select multiple databases"); 
55
56
57 # Search 2 databases
58 my $rs2 = $sess->search(cqlmap    => 'demo/cql.map',
59                         cql       => 'IDZebra');
60 $expected = $filecount * 2;
61 $hits = $rs2->count;
62 ok(($hits == $expected), "CQL search - found $hits/$expected records");
63
64 # RPN search;
65 my $rs3 = $sess->search(cqlmap    => 'demo/cql.map',
66                         pqf       => '@attr 1=4 IDZebra');
67 $expected = $filecount * 2;
68 $hits = $rs3->count;
69 ok(($hits == $expected), "RPN search - found $hits/$expected records");
70
71 # Termlists;
72 my $rs4 = $sess->search(pqf       => '@attr 1=4 @and IDZebra Session');
73 $expected = 2;
74 $hits = $rs4->count;
75 ok(($hits == $expected), "RPN search - found $hits/$expected records");
76
77 my @terms = $rs4->terms();
78 ok(($#terms == 1), "Got 2 terms in RPN expression");
79 my $cc = 0;
80 foreach my $t (@terms) {
81     if ($t->{term} eq 'IDZebra') {
82         ok(($t->{count} = $filecount*2), "Term IDZebra ($t->{count})");
83         $cc++;
84     }
85     elsif ($t->{term} eq 'Session') {
86         ok(($t->{count} = 2), "Term Session ($t->{count})");
87         $cc++;
88     } else {
89         ok(0,"Invalid term $t->{term}");
90     }
91
92 }
93 ok (($cc == 2), "Got 2 terms for RS");
94
95
96
97 # More specific search
98
99
100 # ----------------------------------------------------------------------------
101 # Close session
102
103 $sess->close;