|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Getopt::Long; |
| 7 |
use List::Util qw/min/; |
| 8 |
use ZOOM; |
| 9 |
|
| 10 |
# command-line parameters |
| 11 |
my $host = undef; |
| 12 |
my $port = undef; |
| 13 |
my $database = undef; |
| 14 |
my $verbose = 0; |
| 15 |
my ( $isbn, $issn, $title, $author, $dewey, $subject, $lccn, $lccall, $controlnumber, $stdid, $srchany ); |
| 16 |
|
| 17 |
my $result = GetOptions( |
| 18 |
'h|host=s' => \$host, |
| 19 |
'p|port=s' => \$port, |
| 20 |
'd|database=s' => \$database, |
| 21 |
|
| 22 |
'isbn=s' => \$isbn, |
| 23 |
'issn=s' => \$issn, |
| 24 |
'title=s' => \$title, |
| 25 |
'author=s' => \$author, |
| 26 |
'dewey=s' => \$dewey, |
| 27 |
'subject=s' => \$subject, |
| 28 |
'lccn=s' => \$lccn, |
| 29 |
'lccall=s' => \$lccall, |
| 30 |
'controlnumber=s' => \$controlnumber, |
| 31 |
'stdid=s' => \$stdid, |
| 32 |
'srchany=s' => \$srchany, |
| 33 |
|
| 34 |
'v|verbose' => \$verbose, |
| 35 |
); |
| 36 |
|
| 37 |
die("Error: missing required options") unless ( $host && $port && $database ); |
| 38 |
|
| 39 |
print "\n"; |
| 40 |
print "Using host '$host'\n"; |
| 41 |
print "Using port '$port'\n"; |
| 42 |
print "Using database '$database'\n"; |
| 43 |
print "\n"; |
| 44 |
|
| 45 |
my $query = ''; |
| 46 |
my $nterms; |
| 47 |
if ($isbn) { |
| 48 |
$query .= " \@attr 1=7 \@attr 5=1 \"$isbn\" "; |
| 49 |
$nterms++; |
| 50 |
} |
| 51 |
if ($issn) { |
| 52 |
$query .= " \@attr 1=8 \@attr 5=1 \"$issn\" "; |
| 53 |
$nterms++; |
| 54 |
} |
| 55 |
if ($title) { |
| 56 |
utf8::decode($title); |
| 57 |
$query .= " \@attr 1=4 \"$title\" "; |
| 58 |
$nterms++; |
| 59 |
} |
| 60 |
if ($author) { |
| 61 |
utf8::decode($author); |
| 62 |
$query .= " \@attr 1=1003 \"$author\" "; |
| 63 |
$nterms++; |
| 64 |
} |
| 65 |
if ($dewey) { |
| 66 |
$query .= " \@attr 1=16 \"$dewey\" "; |
| 67 |
$nterms++; |
| 68 |
} |
| 69 |
if ($subject) { |
| 70 |
utf8::decode($subject); |
| 71 |
$query .= " \@attr 1=21 \"$subject\" "; |
| 72 |
$nterms++; |
| 73 |
} |
| 74 |
if ($lccn) { |
| 75 |
$query .= " \@attr 1=9 $lccn "; |
| 76 |
$nterms++; |
| 77 |
} |
| 78 |
if ($lccall) { |
| 79 |
$query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" "; |
| 80 |
$nterms++; |
| 81 |
} |
| 82 |
if ($controlnumber) { |
| 83 |
$query .= " \@attr 1=12 \"$controlnumber\" "; |
| 84 |
$nterms++; |
| 85 |
} |
| 86 |
if ($stdid) { |
| 87 |
$query .= " \@attr 1=1007 \"$stdid\" "; |
| 88 |
$nterms++; |
| 89 |
} |
| 90 |
if ($srchany) { |
| 91 |
$query .= " \@attr 1=1016 \"$srchany\" "; |
| 92 |
$nterms++; |
| 93 |
} |
| 94 |
for my $i ( 1 .. $nterms - 1 ) { |
| 95 |
$query = "\@and " . $query; |
| 96 |
} |
| 97 |
warn "\nQUERY: $query\n\n"; |
| 98 |
|
| 99 |
my ( $start_run, $end_run ); |
| 100 |
|
| 101 |
my $conn = new ZOOM::Connection( $host, $port, databaseName => $database ); |
| 102 |
$conn->option( preferredRecordSyntax => "usmarc" ); |
| 103 |
$start_run = time(); |
| 104 |
my $rs = $conn->search_pqf($query); |
| 105 |
my $n = $rs->size(); |
| 106 |
|
| 107 |
## Koha only display 20 results per page, so set |
| 108 |
## $i to no more than 20 |
| 109 |
for ( my $i = 0 ; $i < min( $n, 20 ) ; $i++ ) { |
| 110 |
my $record = $rs->record($i)->render(); |
| 111 |
print "\n$record\n" if $verbose; |
| 112 |
} |
| 113 |
|
| 114 |
$end_run = time(); |
| 115 |
|
| 116 |
print "\nRecieved $n results\n"; |
| 117 |
|
| 118 |
my $run_time = $end_run - $start_run; |
| 119 |
print "\nSearch took $run_time seconds\n\n"; |
| 120 |
|