@bath_queries includes all six attributes for each query type.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Bath.pm
1 # This tests the main searches specified The Bath Profile, Release 2.0, 
2 #       http://www.collectionscanada.gc.ca/bath/tp-bath2-e.htm
3 # Specifically section 5.A.0 ("Functional Area A: Level 0 Basic
4 # Bibliographic Search and Retrieval") and its subsections:
5 #       http://www.collectionscanada.gc.ca/bath/tp-bath2.7-e.htm#a
6 #
7 # The Bath Level 0 searches have different access-points, but share:
8 #       Relation (2)            3       equal
9 #       Position (3)            3       any position in field
10 #       Structure (4)           2       word
11 #       Truncation (5)          100     do not truncate
12 #       Completeness (6)        1       incomplete subfield
13 # But Seb's bug report at:
14 #       http://bugzilla.indexdata.dk/show_bug.cgi?id=3352#c0
15 # wants use to use s=al t=r,l, where "s" is structure (4) and "al" is
16 # AND-list, which apparently sends NO structure attribute; and "t" is
17 # truncation (5) and "r,l" is right-and-left truncation (3).
18 #
19 # AND-listing (and selection of word or phrase-structure) is now
20 # invoked in the Toroid, when the list of attributes is emitted; but
21 # we can't test for 5=100 here, as the Bath Profile says to do, and
22 # then use that as justification for emitting 5=3 in the Toroid.
23
24 package ZOOM::IRSpy::Test::Search::Bath;
25
26 use 5.008;
27 use strict;
28 use warnings;
29
30 use ZOOM::IRSpy::Test;
31 our @ISA = qw(ZOOM::IRSpy::Test);
32
33 use ZOOM::IRSpy::Utils qw(isodate);
34
35
36 my @bath_queries = (
37     # Name    =>  use, rel, pos, str, tru, com
38     [ author  => 1003,   3,   3,   2, 100,   1 ],       # 5.A.0.1
39     [ title   =>    4,   3,   3,   2, 100,   1 ],       # 5.A.0.2
40     [ subject =>   21,   3,   3,   2, 100,   1 ],       # 5.A.0.3
41     [ any     => 1016,   3,   3,   2, 100,   1 ],       # 5.A.0.4
42     );
43
44
45 sub start {
46     my $class = shift();
47     my($conn) = @_;
48
49     start_search($conn, 0);
50 }
51
52
53 sub start_search {
54     my($conn, $qindex) = @_;
55
56     return ZOOM::IRSpy::Status::TEST_GOOD
57         if $qindex >= @bath_queries;
58
59     my $ref = $bath_queries[$qindex];
60     my($name, @attrs) = @$ref;
61
62     my $query = join(" ", map { "\@attr $_=" . $attrs[$_-1] } (1..6)) . " the";
63     $conn->irspy_search_pqf($query, { qindex => $qindex }, {},
64                             ZOOM::Event::ZEND, \&search_complete,
65                             "exception", \&search_complete);
66     return ZOOM::IRSpy::Status::TASK_DONE;
67 }
68
69
70 sub search_complete {
71     my($conn, $task, $udata, $event) = @_;
72     my $ok = ref $event && $event->isa("ZOOM::Exception") ? 0 : 1;
73
74     my $qindex = $udata->{qindex};
75     my $ref = $bath_queries[$qindex];
76     my($name) = @$ref;
77
78     my $n = $task->{rs}->size();
79
80     $conn->log("irspy_test", "bath search #$qindex ('$name') ",
81                $ok ? ("found $n record", $n==1 ? "" : "s") :
82                       "had error: $event");
83
84     my $rec = $conn->record();
85     $rec->append_entry("irspy:status",
86                        "<irspy:search_bath name='$name' ok='$ok'>" .
87                        isodate(time()) . "</irspy:search_bath>");
88
89     return start_search($conn, $qindex+1);
90 }
91
92
93 1;