r947@llin: dpavlin | 2006-09-12 16:45:55 +0200
[webpac2] / run.pl
diff --git a/run.pl b/run.pl
index 173bfc0..25c1a8d 100755 (executable)
--- a/run.pl
+++ b/run.pl
@@ -232,8 +232,6 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                        use WebPAC::Output::EstraierNative;
                        $indexer = new WebPAC::Output::EstraierNative( %{ $indexer_config } );
 
-                       $use_indexer = 'hyperestraier';
-
                } elsif ($use_indexer eq 'kinosearch') {
 
                        # open KinoSearch
@@ -363,6 +361,16 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                        %{ $input },
                );
 
+               my $report_fh;
+               if ($stats || $validate) {
+                       my $path = "out/report/" . $database . '-' . $input->{name} . '.txt';
+                       open($report_fh, '>', $path) || $log->logdie("can't open $path: $!");
+
+                       print $report_fh "Report for database '$database' input '$input->{name}' records ",
+                               $offset || 1, "-", $limit || $input->{limit} || $maxmfn, "\n\n";
+                       $log->info("Generating report file $path");
+               }
+
                my @norm_array = ref($input->{normalize}) eq 'ARRAY' ?
                        @{ $input->{normalize} } : ( $input->{normalize} );
 
@@ -392,6 +400,10 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                        # reset position in database
                        $input_db->seek(1);
 
+                       # generate name of config key for indexer (strip everything after -)
+                       my $indexer_config = $use_indexer;
+                       $indexer_config =~ s/^(\w+)-?.*$/$1/g;
+
                        foreach my $pos ( 0 ... $input_db->size ) {
 
                                my $row = $input_db->fetch || next;
@@ -408,7 +420,7 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                                if ($validate) {
                                        if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) {
                                                $log->error( "MFN $mfn validation error:\n",
-                                                       dump( $errors )
+                                                       $validate->report_error( $errors )
                                                );
                                        }
                                }
@@ -441,7 +453,7 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                                $indexer->add(
                                        id => $input->{name} . "/" . $mfn,
                                        ds => $ds,
-                                       type => $config->{$use_indexer}->{type},
+                                       type => $config->{$indexer_config}->{type},
                                ) if ($indexer && $ds);
 
                                if ($marc) {
@@ -463,13 +475,25 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
                                $total_rows++;
                        }
 
-                       $log->info("validation errors:\n", dump( $validate->all_errors ) ) if ($validate && defined($validate->all_errors));
+                       if ($validate) {
+                               my $errors = $validate->report;
+                               if ($errors) {
+                                       $log->info("validation errors:\n$errors\n" );
+                                       print $report_fh "$errors\n" if ($report_fh);
+                               }
+                       }
 
-                       $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
+                       if ($stats) {
+                               my $s = $input_db->stats;
+                               $log->info("statistics of fields usage:\n$s");
+                               print $report_fh "Statistics of fields usage:\n$s" if ($report_fh);
+                       }
 
                        # close MARC file
                        $marc->finish if ($marc);
 
+                       # close report
+                       close($report_fh) if ($report_fh)
                }
 
        }