Remove extraneous and misleading old CVS IDs
[ZOOM-Perl-moved-to-github.git] / samples / zoom / zoomscan.pl
1 #!/usr/bin/perl -w
2
3 # This is the scanning counterpart to zoomscan.pl's searching
4 # perl -I../../blib/lib -I../../blib/arch zoomscan.pl <target> <scanQuery>
5 #
6 # For example (using Z39.50 and SRW, Type-1 and CQL):
7 # perl zoomscan.pl tcp:localhost:8018/IR-Explain---1 '@attr 1=dc.title the'
8 # perl zoomscan.pl http://localhost:8018/IR-Explain---1 '@attr 1=dc.title the'
9 # perl zoomscan.pl -q http://localhost:8018/IR-Explain---1 'dc.title=the'
10
11 use strict;
12 use warnings;
13 use Getopt::Std;
14 use ZOOM;
15
16 my %opts;
17 if (!getopts('q', \%opts) || @ARGV != 2) {
18     print STDERR "Usage: $0 [options] target scanQuery
19         -q      Query is CQL [default: PQF]
20         eg. $0 z3950.indexdata.dk/gils computer\n";
21     exit 1;
22 }
23
24 my($host, $scanQuery) = @ARGV;
25
26 eval {
27     my $conn = new ZOOM::Connection($host, 0);
28     $conn->option(preferredRecordSyntax => "usmarc");
29     ### Could use ZOOM::Query::CQL below, but that only works in SRU/W.
30     my $q = $opts{q} ? new ZOOM::Query::CQL($scanQuery) :
31                        new ZOOM::Query::PQF($scanQuery);
32     my $ss = $conn->scan($q);
33     my $n = $ss->size();
34     for my $i (0..$n-1) {
35         my($term, $occ) = $ss->term($i);
36         print $i+1, ": $term";
37         print " ($occ)" if defined $occ;
38         print "\n";
39     }
40     
41     $ss->destroy();
42     $conn->destroy();
43 }; if ($@) {
44     die "Non-ZOOM error: $@" if !$@->isa("ZOOM::Exception");
45     print STDERR "ZOOM error $@\n";
46     exit 1;
47 }