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