Add tests for "ident" and "date" 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 (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     [ ident   => 1007,   3,   1,   1, 100,   1 ],       # 5.A.1.14
47     [ date    =>   31,   3,   1,   4, 100,   1 ],       # 5.A.1.15
48     );
49
50
51 sub start {
52     my $class = shift();
53     my($conn) = @_;
54
55     start_search($conn, 0);
56 }
57
58
59 sub start_search {
60     my($conn, $qindex) = @_;
61
62     return ZOOM::IRSpy::Status::TEST_GOOD
63         if $qindex >= @bath_queries;
64
65     my $ref = $bath_queries[$qindex];
66     my($name, @attrs) = @$ref;
67
68     my $query = join(" ", map { "\@attr $_=" . $attrs[$_-1] } (1..6)) . " the";
69     $conn->irspy_search_pqf($query, { qindex => $qindex }, {},
70                             ZOOM::Event::ZEND, \&search_complete,
71                             "exception", \&search_complete);
72     return ZOOM::IRSpy::Status::TASK_DONE;
73 }
74
75
76 sub search_complete {
77     my($conn, $task, $udata, $event) = @_;
78     my $ok = ref $event && $event->isa("ZOOM::Exception") ? 0 : 1;
79
80     my $qindex = $udata->{qindex};
81     my $ref = $bath_queries[$qindex];
82     my($name) = @$ref;
83
84     my $n = $task->{rs}->size();
85
86     $conn->log("irspy_test", "bath search #$qindex ('$name') ",
87                $ok ? ("found $n record", $n==1 ? "" : "s") :
88                       "had error: $event");
89
90     my $rec = $conn->record();
91     $rec->append_entry("irspy:status",
92                        "<irspy:search_bath name='$name' ok='$ok'>" .
93                        isodate(time()) . "</irspy:search_bath>");
94
95     return start_search($conn, $qindex+1);
96 }
97
98
99 1;