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