1 # $Id: Fetch.pm,v 1.31 2009-04-21 13:42:58 mike Exp $
3 # See the "Main" test package for documentation
5 package ZOOM::IRSpy::Test::Record::Fetch;
11 use ZOOM::IRSpy::Test;
12 our @ISA = qw(ZOOM::IRSpy::Test);
18 "\@attr 1=4 computer",
19 "\@attr 1=44 mineral", # Smithsonian doesn't support AP 4!
20 "\@attr 1=1016 water", # Connector Framework only does 1016
21 ### We can add more queries here
29 # Here I want to get a use attribute from the session, which we've
30 # managed to search for in the Search/Bib1 or Search/Dan1 tests.
31 # But how? So far we search for title: 1=4
32 $conn->irspy_search_pqf($queries[0], { queryindex => 0 }, {},
33 ZOOM::Event::ZEND, \&completed_search,
34 exception => \&completed_search);
38 sub completed_search {
39 my($conn, $task, $udata, $event) = @_;
41 my $n = $task->{rs}->size();
42 $conn->log("irspy_test", "Fetch test search (", $task->render_query(), ") ",
43 ref $event && $event->isa("ZOOM::Exception") ?
44 "failed: $event" : "found $n records (event=$event)");
46 $task->{rs}->destroy();
47 my $qindex = $udata->{queryindex}+1;
48 my $q = $queries[$qindex];
49 return ZOOM::IRSpy::Status::TEST_SKIPPED
52 $conn->log("irspy_test", "Trying another search ...");
53 $conn->irspy_search_pqf($queries[$qindex], { queryindex => $qindex }, {},
54 ZOOM::Event::ZEND, \&completed_search,
55 exception => \&completed_search);
56 return ZOOM::IRSpy::Status::TASK_DONE;
80 #@syntax = qw(grs-1 sutrs usmarc xml); # simplify for debugging
81 foreach my $i (0 ..$#syntax) {
82 my $syntax = $syntax[$i];
83 $conn->irspy_rs_record($task->{rs}, 0,
85 last => ($i == $#syntax) },
86 { start => 0, count => 1,
87 preferredRecordSyntax => $syntax },
88 ZOOM::Event::ZEND, \&record,
89 exception => \&fetch_error);
92 return ZOOM::IRSpy::Status::TASK_DONE;
97 my($conn, $task, $udata, $event) = @_;
98 my $syn = $udata->{'syntax'};
101 my $record = _fetch_record($rs, 0, $syn);
103 if (!$record || $record->error()) {
104 $conn->log("irspy_test", "retrieval of $syn record failed: ",
105 defined $record ? $record->exception() :
109 my $text = $record->render();
110 $conn->log("irspy_test", "Successfully retrieved a $syn record");
112 print STDERR "Hits: ", $rs->size(), "\n";
113 print STDERR "Syntax: ", $syn, "\n";
118 $conn->record()->store_result('record_fetch',
122 $rs->destroy() if $udata->{last};
123 return ($udata->{last} ?
124 ZOOM::IRSpy::Status::TEST_GOOD :
125 ZOOM::IRSpy::Status::TASK_DONE);
130 my($rs, $index0, $syntax) = @_;
132 my $oldSyntax = $rs->option(preferredRecordSyntax => $syntax);
133 my $record = $rs->record(0);
134 $oldSyntax = "" if !defined $oldSyntax;
135 $rs->option(preferredRecordSyntax => $oldSyntax);
141 sub __UNUSED_search_error {
142 my($conn, $task, $test_args, $exception) = @_;
144 $conn->log("irspy_test", "Initial search failed: ", $exception);
145 return ZOOM::IRSpy::Status::TEST_SKIPPED;
150 my($conn, $task, $udata, $exception) = @_;
151 my $syn = $udata->{'syntax'};
153 $conn->log("irspy_test", "Retrieval of $syn record failed: ", $exception);
154 $conn->record()->store_result('record_fetch',
157 $task->{rs}->destroy() if $udata->{last};
158 return ZOOM::IRSpy::Status::TASK_DONE;