Add new "X-isbn" search for actual ISBN on access-point 7, which isn't
[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
58
59 sub start {
60     my $class = shift();
61     my($conn) = @_;
62
63     start_search($conn, 0);
64 }
65
66
67 sub start_search {
68     my($conn, $qindex) = @_;
69
70     return ZOOM::IRSpy::Status::TEST_GOOD
71         if $qindex >= @bath_queries;
72
73     my $ref = $bath_queries[$qindex];
74     my($name, @attrs) = @$ref;
75
76     my $query = join(" ", map { "\@attr $_=" . $attrs[$_-1] } (1..6)) . " the";
77     $conn->irspy_search_pqf($query, { qindex => $qindex }, {},
78                             ZOOM::Event::ZEND, \&search_complete,
79                             "exception", \&search_complete);
80     return ZOOM::IRSpy::Status::TASK_DONE;
81 }
82
83
84 sub search_complete {
85     my($conn, $task, $udata, $event) = @_;
86     my $ok = ref $event && $event->isa("ZOOM::Exception") ? 0 : 1;
87
88     my $qindex = $udata->{qindex};
89     my $ref = $bath_queries[$qindex];
90     my($name) = @$ref;
91
92     my $n = $task->{rs}->size();
93
94     $conn->log("irspy_test", "bath search #$qindex ('$name') ",
95                $ok ? ("found $n record", $n==1 ? "" : "s") :
96                       "had error: $event");
97
98     my $rec = $conn->record();
99     $rec->append_entry("irspy:status",
100                        "<irspy:search_bath name='$name' ok='$ok'>" .
101                        isodate(time()) . "</irspy:search_bath>");
102
103     return start_search($conn, $qindex+1);
104 }
105
106
107 1;