--- trunk/run.pl 2005/12/16 21:09:48 269 +++ trunk/run.pl 2005/12/19 21:26:04 301 @@ -9,19 +9,63 @@ use WebPAC::Common 0.02; use WebPAC::Lookup; -use WebPAC::Input::ISIS; +use WebPAC::Input 0.03; use WebPAC::Store 0.03; use WebPAC::Normalize::XML; use WebPAC::Output::TT; use WebPAC::Output::Estraier 0.05; use YAML qw/LoadFile/; -use LWP::Simple; +use Getopt::Long; +use File::Path; -my $limit = shift @ARGV; +=head1 NAME -my $config = LoadFile('conf/config.yml'); +run.pl - start WebPAC indexing -print "config = ",Dumper($config); +B + +Options: + +=over 4 + +=item --offset 42 + +start loading (all) databases at offset 42 + +=item --limit 100 + +limit loading to 100 records + +=item --clean + +remove database and Hyper Estraier index before indexing + +=item --config conf/config.yml + +path to YAML configuration file + +=back + +=cut + +my $offset; +my $limit; + +my $clean = 0; +my $config = 'conf/config.yml'; +my $debug = 0; + +GetOptions( + "limit=i" => \$limit, + "offset=i" => \$offset, + "clean" => \$clean, + "config" => \$config, + "debug" => \$debug, +); + +$config = LoadFile($config); + +print "config = ",Dumper($config) if ($debug); die "no databases in config file!\n" unless ($config->{databases}); @@ -38,12 +82,16 @@ my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); $est_config->{database} = $database; - $log->info("using HyperEstraier URL $est_config->{masterurl}"); - my $est = new WebPAC::Output::Estraier( %{ $est_config }, ); + if ($clean) { + $log->warn("creating new empty index $database"); + $est->master( action => 'nodedel', name => $database ); + $est->master( action => 'nodeadd', name => $database, label => $database ); + } + # # now WebPAC::Store # @@ -52,12 +100,17 @@ my $db_path = $config->{webpac}->{db_path} . '/' . $database; - $log->info("working on $database in $db_path"); + if ($clean) { + $log->info("creating new database $database in $db_path"); + rmtree( $db_path ) || $log->warn("can't remove $db_path: $!"); + } else { + $log->info("working on $database in $db_path"); + } my $db = new WebPAC::Store( path => $db_path, database => $database, - debug => 1, + debug => $debug, ); @@ -74,26 +127,33 @@ $log->info("database $database doesn't have inputs defined"); } + my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; + foreach my $input (@inputs) { my $type = lc($input->{type}); - die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis'); + die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); my $lookup = new WebPAC::Lookup( lookup_file => $input->{lookup}, ); - $log->info("working on input $input->{path} [$input->{type}]"); + my $input_module = $config->{webpac}->{inputs}->{$type}; + + $log->info("working on input $input->{path} [$input->{type}] using $input_module"); - my $isis = new WebPAC::Input::ISIS( + my $input_db = new WebPAC::Input( + module => $input_module, code_page => $config->{webpac}->{webpac_encoding}, - limit_mfn => $input->{limit}, + limit => $limit || $input->{limit}, + offset => $offset, lookup => $lookup, ); + $log->logdie("can't create input using $input_module") unless ($input); - my $maxmfn = $isis->open( - filename => $input->{path}, + my $maxmfn = $input_db->open( + path => $input->{path}, code_page => $input->{encoding}, # database encoding ); @@ -119,16 +179,22 @@ ); } - for ( 0 ... $isis->size ) { + foreach my $pos ( 0 ... $input_db->size ) { + + my $row = $input_db->fetch || next; - my $row = $isis->fetch || next; + my $mfn = $row->{'000'}->[0]; - my $mfn = $row->{'000'}->[0] || die "can't find MFN"; + if (! $mfn || $mfn !~ m#^\d+$#) { + $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); + $mfn = $pos; + push @{ $row->{'000'} }, $pos; + } my $ds = $n->data_structure($row); $est->add( - id => $input->{name} . "#" . $mfn, + id => $input->{name} . "/" . $mfn, ds => $ds, type => $config->{hyperestraier}->{type}, );