Validate hostname and port number of new records.
[irspy-moved-to-github.git] / bin / reindex.pl
1 #!/usr/bin/perl -w
2
3 # $Id: reindex.pl,v 1.3 2007-03-07 11:35:38 mike Exp $
4
5 use strict;
6 use warnings;
7 use ZOOM;
8
9 if (@ARGV != 1) {
10     print STDERR "Usage: $0 target\n";
11     exit 1;
12 }
13
14 my $conn = new ZOOM::Connection($ARGV[0]);
15 $conn->option(preferredRecordSyntax => "xml");
16 $conn->option(elementSetName => "zebra::data");
17 my $rs = $conn->search_pqf('@attr 1=_ALLRECORDS @attr 2=103 ""');
18 my $n = $rs->size();
19 $| = 1;
20 print "$0: reindexing $n records\n";
21 foreach my $i (1..$n) {
22     print ".";
23     print " $i/$n (", int($i*100/$n), "%)\n" if $i % 50 == 0;
24     my $rec = $rs->record($i-1);
25     my $xml = $rec->render();
26     update($conn, $xml);
27 }
28 print " $n/$n (100%)\n" if $n % 50 != 0;
29 commit($conn);
30 print "committed\n";
31
32
33 # These might be better as ZOOM::Connection methods
34 sub update {
35     my($conn, $xml) = @_;
36
37     my $p = $conn->package();
38     $p->option(action => "specialUpdate");
39     $p->option(record => $xml);
40     $p->send("update");
41     $p->destroy();
42 }
43
44 sub commit {
45     my($conn) = @_;
46
47     my $p = $conn->package();
48     $p->send("commit");
49     $p->destroy();
50 }