@@ -, +, @@ --- misc/z3950_test.pl | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 misc/z3950_test.pl --- a/misc/z3950_test.pl +++ a/misc/z3950_test.pl @@ -0,0 +1,120 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Getopt::Long; +use List::Util qw/min/; +use ZOOM; + +# command-line parameters +my $host = undef; +my $port = undef; +my $database = undef; +my $verbose = 0; +my ( $isbn, $issn, $title, $author, $dewey, $subject, $lccn, $lccall, $controlnumber, $stdid, $srchany ); + +my $result = GetOptions( + 'h|host=s' => \$host, + 'p|port=s' => \$port, + 'd|database=s' => \$database, + + 'isbn=s' => \$isbn, + 'issn=s' => \$issn, + 'title=s' => \$title, + 'author=s' => \$author, + 'dewey=s' => \$dewey, + 'subject=s' => \$subject, + 'lccn=s' => \$lccn, + 'lccall=s' => \$lccall, + 'controlnumber=s' => \$controlnumber, + 'stdid=s' => \$stdid, + 'srchany=s' => \$srchany, + + 'v|verbose' => \$verbose, +); + +die("Error: missing required options") unless ( $host && $port && $database ); + +print "\n"; +print "Using host '$host'\n"; +print "Using port '$port'\n"; +print "Using database '$database'\n"; +print "\n"; + +my $query = ''; +my $nterms; +if ($isbn) { + $query .= " \@attr 1=7 \@attr 5=1 \"$isbn\" "; + $nterms++; +} +if ($issn) { + $query .= " \@attr 1=8 \@attr 5=1 \"$issn\" "; + $nterms++; +} +if ($title) { + utf8::decode($title); + $query .= " \@attr 1=4 \"$title\" "; + $nterms++; +} +if ($author) { + utf8::decode($author); + $query .= " \@attr 1=1003 \"$author\" "; + $nterms++; +} +if ($dewey) { + $query .= " \@attr 1=16 \"$dewey\" "; + $nterms++; +} +if ($subject) { + utf8::decode($subject); + $query .= " \@attr 1=21 \"$subject\" "; + $nterms++; +} +if ($lccn) { + $query .= " \@attr 1=9 $lccn "; + $nterms++; +} +if ($lccall) { + $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" "; + $nterms++; +} +if ($controlnumber) { + $query .= " \@attr 1=12 \"$controlnumber\" "; + $nterms++; +} +if ($stdid) { + $query .= " \@attr 1=1007 \"$stdid\" "; + $nterms++; +} +if ($srchany) { + $query .= " \@attr 1=1016 \"$srchany\" "; + $nterms++; +} +for my $i ( 1 .. $nterms - 1 ) { + $query = "\@and " . $query; +} +warn "\nQUERY: $query\n\n"; + +my ( $start_run, $end_run ); + +my $conn = new ZOOM::Connection( $host, $port, databaseName => $database ); +$conn->option( preferredRecordSyntax => "usmarc" ); +$start_run = time(); +my $rs = $conn->search_pqf($query); +my $n = $rs->size(); + +## Koha only display 20 results per page, so set +## $i to no more than 20 +for ( my $i = 0 ; $i < min( $n, 20 ) ; $i++ ) { + my $record = $rs->record($i)->render(); + print "\n$record\n" if $verbose; +} + +$end_run = time(); + +print "\nRecieved $n results\n"; + +my $run_time = $end_run - $start_run; +print "\nSearch took $run_time seconds\n\n"; + --