/[webpac2]/trunk/run.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/run.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 509 by dpavlin, Mon May 15 17:23:38 2006 UTC revision 523 by dpavlin, Sun May 21 19:29:26 2006 UTC
# Line 14  use WebPAC::Store 0.03; Line 14  use WebPAC::Store 0.03;
14  use WebPAC::Normalize::XML;  use WebPAC::Normalize::XML;
15  use WebPAC::Normalize::Set;  use WebPAC::Normalize::Set;
16  use WebPAC::Output::TT;  use WebPAC::Output::TT;
17    use WebPAC::Validate;
18  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
19  use Getopt::Long;  use Getopt::Long;
20  use File::Path;  use File::Path;
# Line 42  limit loading to 100 records Line 43  limit loading to 100 records
43    
44  remove database and Hyper Estraier index before indexing  remove database and Hyper Estraier index before indexing
45    
46  =item --only=database_name  =item --only=database_name/input_filter
47    
48  reindex just single database (legacy name is --one)  reindex just single database (legacy name is --one)
49    
50    C</input_filter> is optional part which can be C<name>
51    or C<type> from input
52    
53  =item --config conf/config.yml  =item --config conf/config.yml
54    
55  path to YAML configuration file  path to YAML configuration file
# Line 60  C<.xml> to C<.pl> Line 64  C<.xml> to C<.pl>
64  disable indexing and dump statistics about field and subfield  disable indexing and dump statistics about field and subfield
65  usage for each input  usage for each input
66    
67    =item --validate path/to/validation_file
68    
69    turn on extra validation of imput records, see L<WebPAC::Validation>
70    
71  =back  =back
72    
73  =cut  =cut
# Line 70  my $limit; Line 78  my $limit;
78  my $clean = 0;  my $clean = 0;
79  my $config = 'conf/config.yml';  my $config = 'conf/config.yml';
80  my $debug = 0;  my $debug = 0;
81  my $only_db_name;  my $only_filter;
82  my $force_set = 0;  my $force_set = 0;
83  my $stats = 0;  my $stats = 0;
84    my $validate_path;
85    
86  GetOptions(  GetOptions(
87          "limit=i" => \$limit,          "limit=i" => \$limit,
88          "offset=i" => \$offset,          "offset=i" => \$offset,
89          "clean" => \$clean,          "clean" => \$clean,
90          "one=s" => \$only_db_name,          "one=s" => \$only_filter,
91          "only=s" => \$only_db_name,          "only=s" => \$only_filter,
92          "config" => \$config,          "config" => \$config,
93          "debug" => \$debug,          "debug" => \$debug,
94          "force-set" => \$force_set,          "force-set" => \$force_set,
95          "stats" => \$stats,          "stats" => \$stats,
96            "validate=s" => \$validate_path,
97  );  );
98    
99  $config = LoadFile($config);  $config = LoadFile($config);
# Line 95  die "no databases in config file!\n" unl Line 105  die "no databases in config file!\n" unl
105  my $log = _new WebPAC::Common()->_get_logger();  my $log = _new WebPAC::Common()->_get_logger();
106  $log->info( "-" x 79 );  $log->info( "-" x 79 );
107    
108    my $validate;
109    $validate = new WebPAC::Validate(
110            path => $validate_path,
111    ) if ($validate_path);
112    
113  my $use_indexer = $config->{use_indexer} || 'hyperestraier';  my $use_indexer = $config->{use_indexer} || 'hyperestraier';
114  if ($stats) {  if ($stats) {
115          $log->debug("option --stats disables update of indexing engine...");          $log->debug("option --stats disables update of indexing engine...");
# Line 108  my $start_t = time(); Line 123  my $start_t = time();
123    
124  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
125    
126          next if ($only_db_name && $database !~ m/$only_db_name/i);          my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter);
127            next if ($only_database && $database !~ m/$only_database/i);
128    
129          my $indexer;          my $indexer;
130    
# Line 148  while (my ($database, $db_config) = each Line 164  while (my ($database, $db_config) = each
164          my $db_path = $config->{webpac}->{db_path} . '/' . $database;          my $db_path = $config->{webpac}->{db_path} . '/' . $database;
165    
166          if ($clean) {          if ($clean) {
167                  $log->info("creating new database $database in $db_path");                  $log->info("creating new database '$database' in $db_path");
168                  rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");                  rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");
169          } else {          } else {
170                  $log->debug("working on $database in $db_path");                  $log->info("working on database '$database' in $db_path");
171          }          }
172    
173          my $db = new WebPAC::Store(          my $db = new WebPAC::Store(
# Line 178  while (my ($database, $db_config) = each Line 194  while (my ($database, $db_config) = each
194    
195          foreach my $input (@inputs) {          foreach my $input (@inputs) {
196    
197                    next if ($only_input && ($input->{name} !~ m#$only_input#i && $input->{type} !~ m#$only_input#i));
198    
199                  my $type = lc($input->{type});                  my $type = lc($input->{type});
200    
201                  die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));                  die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));
202    
203                  my $lookup = new WebPAC::Lookup(                  my $lookup = new WebPAC::Lookup(
204                          lookup_file => $input->{lookup},                          lookup_file => $input->{lookup},
205                  );                  ) if ($input->{lookup});
206    
207                  my $input_module = $config->{webpac}->{inputs}->{$type};                  my $input_module = $config->{webpac}->{inputs}->{$type};
208    
209                  $log->info("working on input '$input->{path}' [$input->{type}] using $input_module lookup '$input->{lookup}'");                  $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module",
210                            $input->{lookup} ? "lookup '$input->{lookup}'" : ""
211                    );
212    
213                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
214                          module => $input_module,                          module => $input_module,
# Line 204  while (my ($database, $db_config) = each Line 224  while (my ($database, $db_config) = each
224                  my $maxmfn = $input_db->open(                  my $maxmfn = $input_db->open(
225                          path => $input->{path},                          path => $input->{path},
226                          code_page => $input->{encoding},        # database encoding                          code_page => $input->{encoding},        # database encoding
227                            %{ $input },
228                  );                  );
229    
230                  my $n = new WebPAC::Normalize::XML(                  my $n = new WebPAC::Normalize::XML(
231                  #       filter => { 'foo' => sub { shift } },                  #       filter => { 'foo' => sub { shift } },
232                          db => $db,                          db => $db,
233                          lookup_regex => $lookup->regex,                          lookup_regex => $lookup ? $lookup->regex : undef,
234                          lookup => $lookup,                          lookup => $lookup,
235                          prefix => $input->{name},                          prefix => $input->{name},
236                  );                  );
# Line 256  while (my ($database, $db_config) = each Line 277  while (my ($database, $db_config) = each
277                                  push @{ $row->{'000'} }, $pos;                                  push @{ $row->{'000'} }, $pos;
278                          }                          }
279    
280    
281                            if ($validate) {
282                                    my @errors = $validate->validate_errors( $row );
283                                    $log->error( "MFN $mfn validation errors:\n", join("\n", @errors) ) if (@errors);
284                            }
285    
286                                                                    
287                          my $ds;                          my $ds;
288                          if ($n) {                          if ($n) {
# Line 264  while (my ($database, $db_config) = each Line 291  while (my ($database, $db_config) = each
291                                  $ds = WebPAC::Normalize::Set::data_structure(                                  $ds = WebPAC::Normalize::Set::data_structure(
292                                          row => $row,                                          row => $row,
293                                          rules => $rules,                                          rules => $rules,
294                                          lookup => $lookup->lookup_hash,                                          lookup => $lookup ? $lookup->lookup_hash : undef,
295                                  );                                  );
296    
297                                  $db->save_ds(                                  $db->save_ds(
# Line 290  while (my ($database, $db_config) = each Line 317  while (my ($database, $db_config) = each
317          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));          eval { $indexer->finish } if ($indexer && $indexer->can('finish'));
318    
319          my $dt = time() - $start_t;          my $dt = time() - $start_t;
320          $log->info("$total_rows records indexed in " .          $log->info("$total_rows records ", $indexer ? "indexed " : "",
321                  sprintf("%.2f sec [%.2f rec/sec]",                  sprintf("in %.2f sec [%.2f rec/sec]",
322                          $dt, ($total_rows / $dt)                          $dt, ($total_rows / $dt)
323                  )                  )
324          );          );

Legend:
Removed from v.509  
changed lines
  Added in v.523

  ViewVC Help
Powered by ViewVC 1.1.26