Towards IR364 and IR-350.
authorMike Taylor <mike@indexdata.com>
Mon, 15 Dec 2014 12:22:43 +0000 (12:22 +0000)
committerMike Taylor <mike@indexdata.com>
Mon, 15 Dec 2014 12:22:43 +0000 (12:22 +0000)
Major enhancements to reindex.pl:
* New --setDb option (not yet tested)
* New --delete option
* New -n option (do not carry out actions)
* New -q <query> option to limit set of affected records
Skip the undeletable phantom record -- there's nothing more we can do.

bin/reindex.pl

index 67e4976..36fa799 100755 (executable)
@@ -1,21 +1,33 @@
 #!/usr/bin/perl
 
 # Run as:
 #!/usr/bin/perl
 
 # Run as:
-#      perl -I../lib reindex.pl user=admin,password=SWORDFISH,localhost:8018/IR-Explain---1
+#      ./reindex.pl user=admin,password=SWORDFISH,localhost:8018/IR-Explain---1
+#      ./reindex.pl -d -q zeerex.reliability=0 localhost:8018/IR-Explain---1
 
 use strict;
 use warnings;
 use ZOOM;
 
 use strict;
 use warnings;
 use ZOOM;
+use Getopt::Long;
 
 
-if (@ARGV != 1) {
-    print STDERR "Usage: $0 target\n";
+my $setUdb = 0;
+my $delete = 0;
+my $noAction = 0;
+my $query = 'cql.allRecords=1';
+if (!GetOptions(
+        'setUdb' => \$setUdb,
+        'delete' => \$delete,
+        'noAction' => \$noAction,
+        'query=s' => \$query,
+    ) || @ARGV != 1) {
+    print STDERR "Usage: $0 [-s|--setUdb] [-d|--delete] [-n|--noaction] [-q <query>] <target>\n";
     exit 1;
 }
 
 my $conn = new ZOOM::Connection($ARGV[0]);
 $conn->option(preferredRecordSyntax => "xml");
 $conn->option(elementSetName => "zebra::data");
     exit 1;
 }
 
 my $conn = new ZOOM::Connection($ARGV[0]);
 $conn->option(preferredRecordSyntax => "xml");
 $conn->option(elementSetName => "zebra::data");
-my $rs = $conn->search_pqf('@attr 1=_ALLRECORDS @attr 2=103 ""');
+my $rs = $conn->search(new ZOOM::Query::CQL($query));
+
 my $n = $rs->size();
 $| = 1;
 print "$0: reindexing $n records\n";
 my $n = $rs->size();
 $| = 1;
 print "$0: reindexing $n records\n";
@@ -24,6 +36,16 @@ foreach my $i (1..$n) {
     print " $i/$n (", int($i*100/$n), "%)\n" if $i % 50 == 0;
     my $rec = $rs->record($i-1);
     my $xml = $rec->render();
     print " $i/$n (", int($i*100/$n), "%)\n" if $i % 50 == 0;
     my $rec = $rs->record($i-1);
     my $xml = $rec->render();
+    if ($xml !~ /<\/(e:)?host>/) {
+       # There is an undeletable phantom record: ignore it
+       next;
+    }
+
+    if ($setUdb) {
+       my $udb = qq[<i:udb xmlns:i="http://indexdata.com/irspy/1.0">irspy-$i</i:udb>];
+       $xml =~ s/<\/(e:)?host>/$1$udb/;
+    }
+
     update($conn, $xml);
 }
 print " $n/$n (100%)\n" if $n % 50 != 0;
     update($conn, $xml);
 }
 print " $n/$n (100%)\n" if $n % 50 != 0;
@@ -35,8 +57,9 @@ print "committed\n";
 sub update {
     my($conn, $xml) = @_;
 
 sub update {
     my($conn, $xml) = @_;
 
+    return if $noAction;
     my $p = $conn->package();
     my $p = $conn->package();
-    $p->option(action => "specialUpdate");
+    $p->option(action => $delete ? "recordDelete" : "specialUpdate");
     $p->option(record => $xml);
     $p->send("update");
     $p->destroy();
     $p->option(record => $xml);
     $p->send("update");
     $p->destroy();