Comments on Bath Profile vs. Masterkey needs.
[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     [ author => 1003 ], # 5.A.0.1
38     [ title => 4 ],     # 5.A.0.2
39     [ subject => 21 ],  # 5.A.0.3
40     [ any => 1016 ],    # 5.A.0.4
41     );
42
43
44 sub start {
45     my $class = shift();
46     my($conn) = @_;
47
48     start_search($conn, 0);
49 }
50
51
52 sub start_search {
53     my($conn, $qindex) = @_;
54
55     return ZOOM::IRSpy::Status::TEST_GOOD
56         if $qindex >= @bath_queries;
57
58     my $ref = $bath_queries[$qindex];
59     my($name, $use_attr) = @$ref;
60
61     my $query = "\@attr 1=$use_attr \@attr 2=3 \@attr 3=3 \@attr 4=2 \@attr 5=100 \@attr 6=1 the";
62     $conn->irspy_search_pqf($query, { qindex => $qindex }, {},
63                             ZOOM::Event::ZEND, \&search_complete,
64                             "exception", \&search_complete);
65     return ZOOM::IRSpy::Status::TASK_DONE;
66 }
67
68
69 sub search_complete {
70     my($conn, $task, $udata, $event) = @_;
71     my $ok = ref $event && $event->isa("ZOOM::Exception") ? 0 : 1;
72
73     my $qindex = $udata->{qindex};
74     my $ref = $bath_queries[$qindex];
75     my($name, $use_attr) = @$ref;
76
77     my $n = $task->{rs}->size();
78
79     $conn->log("irspy_test", "bath search #$qindex ('$name') ",
80                $ok ? ("found $n record", $n==1 ? "" : "s") :
81                       "had error: $event");
82
83     my $rec = $conn->record();
84     $rec->append_entry("irspy:status",
85                        "<irspy:search_bath name='$name' ok='$ok'>" .
86                        isodate(time()) . "</irspy:search_bath>");
87
88     return start_search($conn, $qindex+1);
89 }
90
91
92 1;