Generalise to handle incompletely specified searches.
[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 # And section 5.A.1 ("Functional Area A: Level 1 Bibliographic Search
7 # and Retrieval") and subsections 14 (Standard Identifier Search) and
8 # 15 (Date of Publication Search):
9 #       http://www.collectionscanada.gc.ca/bath/tp-bath2.10-e.htm#b
10 #
11 # The Bath Level 0 searches have different access-points, but share:
12 #       Relation (2)            3       equal
13 #       Position (3)            3       any position in field
14 #       Structure (4)           2       word
15 #       Truncation (5)          100     do not truncate
16 #       Completeness (6)        1       incomplete subfield
17 # But Seb's bug report at:
18 #       http://bugzilla.indexdata.dk/show_bug.cgi?id=3352#c0
19 # wants use to use s=al t=r,l, where "s" is structure (4) and "al" is
20 # AND-list, which apparently sends NO structure attribute; and "t" is
21 # truncation (5) and "r,l" is right-and-left truncation.
22 #
23 # AND-listing (and selection of word or phrase-structure) is now
24 # invoked in the Toroid, when the list of attributes is emitted; we
25 # test for we can't test for 5=100 here, as the Bath Profile says to
26 # do, and rather optimistically use that as justification for emitting
27 # t=l,r in the Toroid (which means that individual queries can request
28 # either left- or right-truncation using "?".
29 #
30 # Finally, we also make a test for "X-isbn", an ISBN number search,
31 # which is not actually in the Bath Profile.  This gives us something
32 # to back down to when the more general Standard Identifier search
33 # isn't supported.
34
35 package ZOOM::IRSpy::Test::Search::Bath;
36
37 use 5.008;
38 use strict;
39 use warnings;
40
41 use ZOOM::IRSpy::Test;
42 our @ISA = qw(ZOOM::IRSpy::Test);
43
44 use ZOOM::IRSpy::Utils qw(isodate);
45
46
47 my @bath_queries = (
48     # Name    =>  use, rel, pos, str, tru, com
49     [ author  => 1003,   3,   3,   2, 100,   1 ],       # 5.A.0.1
50     [ title   =>    4,   3,   3,   2, 100,   1 ],       # 5.A.0.2
51     [ subject =>   21,   3,   3,   2, 100,   1 ],       # 5.A.0.3
52     [ any     => 1016,   3,   3,   2, 100,   1 ],       # 5.A.0.4
53     [ ident   => 1007,   3,   1,   1, 100,   1 ],       # 5.A.1.14
54     [ date    =>   31,   3,   1,   4, 100,   1 ],       # 5.A.1.15
55     [ "X-isbn"=>    7,   3,   1,   1, 100,   1 ],       # Not in Bath Profile
56
57     # Use attribute only -- fallbacks for when True Bath queries fail
58     [ "X-author1"    => 1 ],
59     [ "X-author1003" => 1003 ],
60     [ "X-author1004" => 1004 ],
61     [ "X-title"      => 4 ],
62     [ "X-subject"    => 21 ],
63     [ "X-any1016"    => 1016 ],
64     [ "X-any1017"    => 1035 ],
65     [ "X-any1035"    => 1035 ],
66     [ "X-isbn7"      => 7 ],
67     );
68
69
70 sub start {
71     my $class = shift();
72     my($conn) = @_;
73
74     start_search($conn, 0);
75 }
76
77
78 sub start_search {
79     my($conn, $qindex) = @_;
80
81     return ZOOM::IRSpy::Status::TEST_GOOD
82         if $qindex >= @bath_queries;
83
84     my $ref = $bath_queries[$qindex];
85     my($name, @attrs) = @$ref;
86
87     my $query = "the";
88     foreach my $i (1 .. @$ref) {
89         $query = "\@attr $i=" . $ref->[$i] . " " . $query
90             if defined $ref->[$i];
91     }
92
93     $conn->irspy_search_pqf($query, { qindex => $qindex }, {},
94                             ZOOM::Event::ZEND, \&search_complete,
95                             "exception", \&search_complete);
96     return ZOOM::IRSpy::Status::TASK_DONE;
97 }
98
99
100 sub search_complete {
101     my($conn, $task, $udata, $event) = @_;
102     my $ok = ref $event && $event->isa("ZOOM::Exception") ? 0 : 1;
103
104     my $qindex = $udata->{qindex};
105     my $ref = $bath_queries[$qindex];
106     my($name) = @$ref;
107
108     my $n = $task->{rs}->size();
109
110     $conn->log("irspy_test", "bath search #$qindex ('$name') ",
111                $ok ? ("found $n record", $n==1 ? "" : "s") :
112                       "had error: $event");
113
114     my $rec = $conn->record();
115     $rec->append_entry("irspy:status",
116                        "<irspy:search_bath name='$name' ok='$ok'>" .
117                        isodate(time()) . "</irspy:search_bath>");
118
119     return start_search($conn, $qindex+1);
120 }
121
122
123 1;