X-Git-Url: http://git.indexdata.com/?p=irspy-moved-to-github.git;a=blobdiff_plain;f=bin%2Freindex.pl;h=9328c72ce86877d57b3c50db332ed40a9db2949b;hp=a3079fb34d9243185072ab31e349abf5b27b8826;hb=bede31050ee10e9a8a3dd20f91ab9d62e0f5af66;hpb=5e43bc51335fc81d176e1930ea22197035721f33 diff --git a/bin/reindex.pl b/bin/reindex.pl index a3079fb..9328c72 100755 --- a/bin/reindex.pl +++ b/bin/reindex.pl @@ -1,20 +1,33 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl -# $Id: reindex.pl,v 1.2 2007-03-02 16:12:39 mike Exp $ +# Run as: +# ./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 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 ] \n"; 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"; @@ -23,10 +36,20 @@ 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(); - open F, ">$i.xml" or die "can't open\n"; - print F $xml; - close F; - #update($conn, $xml); + + if ($setUdb) { + my $udb; + if ($xml !~ /<(e:)?databaseInfo.*?>/) { + $udb = qq[irspy-a$i]; + $xml =~ s/\/serverInfo>/$&$udb<\/databaseInfo>/; + print "x"; + } else { + $udb = qq[irspy-$i]; + $xml =~ s/<(e:)?databaseInfo.*?>/$&$udb/; + } + } + + update($conn, $xml); } print " $n/$n (100%)\n" if $n % 50 != 0; commit($conn); @@ -37,8 +60,9 @@ print "committed\n"; sub update { my($conn, $xml) = @_; + return if $noAction; my $p = $conn->package(); - $p->option(action => "specialUpdate"); + $p->option(action => $delete ? "recordDelete" : "specialUpdate"); $p->option(record => $xml); $p->send("update"); $p->destroy();