47af8943bc68d72b98bce708e17c752986114c2e
[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 (3).
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; but
25 # we can't test for 5=100 here, as the Bath Profile says to do, and
26 # then use that as justification for emitting 5=3 in the Toroid.
27
28 package ZOOM::IRSpy::Test::Search::Bath;
29
30 use 5.008;
31 use strict;
32 use warnings;
33
34 use ZOOM::IRSpy::Test;
35 our @ISA = qw(ZOOM::IRSpy::Test);
36
37 use ZOOM::IRSpy::Utils qw(isodate);
38
39
40 my @bath_queries = (
41     # Name    =>  use, rel, pos, str, tru, com
42     [ author  => 1003,   3,   3,   2, 100,   1 ],       # 5.A.0.1
43     [ title   =>    4,   3,   3,   2, 100,   1 ],       # 5.A.0.2
44     [ subject =>   21,   3,   3,   2, 100,   1 ],       # 5.A.0.3
45     [ any     => 1016,   3,   3,   2, 100,   1 ],       # 5.A.0.4
46     );
47
48
49 sub start {
50     my $class = shift();
51     my($conn) = @_;
52
53     start_search($conn, 0);
54 }
55
56
57 sub start_search {
58     my($conn, $qindex) = @_;
59
60     return ZOOM::IRSpy::Status::TEST_GOOD
61         if $qindex >= @bath_queries;
62
63     my $ref = $bath_queries[$qindex];
64     my($name, @attrs) = @$ref;
65
66     my $query = join(" ", map { "\@attr $_=" . $attrs[$_-1] } (1..6)) . " the";
67     $conn->irspy_search_pqf($query, { qindex => $qindex }, {},
68                             ZOOM::Event::ZEND, \&search_complete,
69                             "exception", \&search_complete);
70     return ZOOM::IRSpy::Status::TASK_DONE;
71 }
72
73
74 sub search_complete {
75     my($conn, $task, $udata, $event) = @_;
76     my $ok = ref $event && $event->isa("ZOOM::Exception") ? 0 : 1;
77
78     my $qindex = $udata->{qindex};
79     my $ref = $bath_queries[$qindex];
80     my($name) = @$ref;
81
82     my $n = $task->{rs}->size();
83
84     $conn->log("irspy_test", "bath search #$qindex ('$name') ",
85                $ok ? ("found $n record", $n==1 ? "" : "s") :
86                       "had error: $event");
87
88     my $rec = $conn->record();
89     $rec->append_entry("irspy:status",
90                        "<irspy:search_bath name='$name' ok='$ok'>" .
91                        isodate(time()) . "</irspy:search_bath>");
92
93     return start_search($conn, $qindex+1);
94 }
95
96
97 1;