--- trunk/run.pl 2005/12/19 21:26:04 301 +++ trunk/run.pl 2006/04/17 15:10:04 431 @@ -13,10 +13,10 @@ use WebPAC::Store 0.03; use WebPAC::Normalize::XML; use WebPAC::Output::TT; -use WebPAC::Output::Estraier 0.05; use YAML qw/LoadFile/; use Getopt::Long; use File::Path; +use Time::HiRes qw/time/; =head1 NAME @@ -40,6 +40,10 @@ remove database and Hyper Estraier index before indexing +=item --only=database_name + +reindex just single database (legacy name is --one) + =item --config conf/config.yml path to YAML configuration file @@ -54,11 +58,14 @@ my $clean = 0; my $config = 'conf/config.yml'; my $debug = 0; +my $only_db_name; GetOptions( "limit=i" => \$limit, "offset=i" => \$offset, "clean" => \$clean, + "one=s" => \$only_db_name, + "only=s" => \$only_db_name, "config" => \$config, "debug" => \$debug, ); @@ -69,29 +76,43 @@ die "no databases in config file!\n" unless ($config->{databases}); +my $log = _new WebPAC::Common()->_get_logger(); + +my $use_indexer = $config->{use_indexer} || 'hyperestraier'; +$log->info("using $use_indexer indexing engine..."); + my $total_rows = 0; +my $start_t = time(); while (my ($database, $db_config) = each %{ $config->{databases} }) { - my $log = _new WebPAC::Common()->_get_logger(); - - # - # open Hyper Estraier database - # + next if ($only_db_name && $database !~ m/$only_db_name/i); - my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); - $est_config->{database} = $database; + my $indexer; - my $est = new WebPAC::Output::Estraier( - %{ $est_config }, - ); + my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration"); + $indexer_config->{database} = $database; + $indexer_config->{clean} = $clean; + $indexer_config->{label} = $db_config->{name}; + + if ($use_indexer eq 'hyperestraier') { + + # open Hyper Estraier database + use WebPAC::Output::Estraier '0.10'; + $indexer = new WebPAC::Output::Estraier( %{ $indexer_config } ); + + } elsif ($use_indexer eq 'kinosearch') { + + # open KinoSearch + use WebPAC::Output::KinoSearch; + $indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } ); - if ($clean) { - $log->warn("creating new empty index $database"); - $est->master( action => 'nodedel', name => $database ); - $est->master( action => 'nodeadd', name => $database, label => $database ); + } else { + $log->logdie("unknown use_indexer: $use_indexer"); } + $log->logide("can't continue without valid indexer") unless ($indexer); + # # now WebPAC::Store # @@ -104,7 +125,7 @@ $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"); + $log->debug("working on $database in $db_path"); } my $db = new WebPAC::Store( @@ -141,7 +162,7 @@ my $input_module = $config->{webpac}->{inputs}->{$type}; - $log->info("working on input $input->{path} [$input->{type}] using $input_module"); + $log->info("working on input '$input->{path}' [$input->{type}] using $input_module lookup '$input->{lookup}'"); my $input_db = new WebPAC::Input( module => $input_module, @@ -149,6 +170,7 @@ limit => $limit || $input->{limit}, offset => $offset, lookup => $lookup, + recode => $input->{recode}, ); $log->logdie("can't create input using $input_module") unless ($input); @@ -193,10 +215,10 @@ my $ds = $n->data_structure($row); - $est->add( + $indexer->add( id => $input->{name} . "/" . $mfn, ds => $ds, - type => $config->{hyperestraier}->{type}, + type => $config->{$use_indexer}->{type}, ); $total_rows++; @@ -204,19 +226,28 @@ }; - $log->info("$total_rows records indexed"); + my $dt = time() - $start_t; + $log->info("$total_rows records indexed in " . + sprintf("%.2f sec [%.2f rec/sec]", + $dt, ($total_rows / $dt) + ) + ); # # add Hyper Estraier links to other databases # if (ref($db_config->{links}) eq 'ARRAY') { foreach my $link (@{ $db_config->{links} }) { - $log->info("adding link $database -> $link->{to} [$link->{credit}]"); - $est->add_link( - from => $database, - to => $link->{to}, - credit => $link->{credit}, - ); + if ($use_indexer eq 'hyperestraier') { + $log->info("adding link $database -> $link->{to} [$link->{credit}]"); + $indexer->add_link( + from => $database, + to => $link->{to}, + credit => $link->{credit}, + ); + } else { + $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]"); + } } }