fb3433b001c4f0377e3e6a3f3293a729c44ccf2d
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Explain.pm
1 # $Id: Explain.pm,v 1.5 2007-02-26 18:48:50 mike Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::Search::Explain;
6
7 use 5.008;
8 use strict;
9 use warnings;
10
11 use ZOOM::IRSpy::Test;
12 our @ISA = qw(ZOOM::IRSpy::Test);
13
14
15 sub start {
16     my $class = shift();
17     my($conn) = @_;
18     my @explain = qw(CategoryList TargetInfo DatabaseInfo SchemaInfo TagSetInfo
19                      RecordSyntaxInfo AttributeSetInfo TermListInfo
20                      ExtendedServicesInfo AttributeDetails TermListDetails
21                      ElementSetDetails RetrivalRecordDetails SortDetails
22                      Processing VariantSetInfo UnitSet);
23
24     foreach my $category (@explain) {
25         $conn->irspy_search_pqf('@attr exp-1 1=1 ' . $category,
26                                 {'category' => $category},
27                                 { databaseName => 'IR-Explain-1' },
28                                 ZOOM::Event::ZEND, \&found,
29                                 exception => \&error);
30     }
31 }
32
33
34 sub found {
35     my($conn, $task, $test_args, $event) = @_;
36     my $category = $test_args->{'category'};
37     my $n = $task->{rs}->size();
38     my $ok = 0;
39
40     $conn->log("irspy_test", "Explain category ", $category, " gave ", $n,
41                " hit(s).");
42     if ($n > 0) {
43         $ok = 1;
44     }
45
46     update($conn, $category, $ok);
47
48     return ZOOM::IRSpy::Status::TASK_DONE;
49 }
50
51
52 sub error {
53     my($conn, $task, $test_args, $exception) = @_;
54     my $category = $test_args->{'category'};
55
56     $conn->log("irspy_test", "Explain category lookup failed: ", $exception);
57     update($conn, $category, 0);
58
59     return ZOOM::IRSpy::Status::TEST_BAD
60         if $exception->code() == 109; # Database unavailable
61
62     return ZOOM::IRSpy::Status::TASK_DONE;
63 }
64
65
66 sub update {
67     my ($conn, $category, $ok) = @_;
68     $conn->record()->store_result('explain', 'category'  => $category,
69                                              'ok'        => $ok);
70 }
71
72 1;