/[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 423 by dpavlin, Wed Mar 22 00:18:56 2006 UTC revision 509 by dpavlin, Mon May 15 17:23:38 2006 UTC
# Line 12  use WebPAC::Lookup; Line 12  use WebPAC::Lookup;
12  use WebPAC::Input 0.03;  use WebPAC::Input 0.03;
13  use WebPAC::Store 0.03;  use WebPAC::Store 0.03;
14  use WebPAC::Normalize::XML;  use WebPAC::Normalize::XML;
15    use WebPAC::Normalize::Set;
16  use WebPAC::Output::TT;  use WebPAC::Output::TT;
 use WebPAC::Output::Estraier '0.10';  
17  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
18  use Getopt::Long;  use Getopt::Long;
19  use File::Path;  use File::Path;
20  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
21    use File::Slurp;
22    
23  =head1 NAME  =head1 NAME
24    
# Line 49  reindex just single database (legacy nam Line 50  reindex just single database (legacy nam
50    
51  path to YAML configuration file  path to YAML configuration file
52    
53    =item --force-set
54    
55    force conversion C<< normalize->path >> in C<config.yml> from
56    C<.xml> to C<.pl>
57    
58    =item --stats
59    
60    disable indexing and dump statistics about field and subfield
61    usage for each input
62    
63  =back  =back
64    
65  =cut  =cut
# Line 60  my $clean = 0; Line 71  my $clean = 0;
71  my $config = 'conf/config.yml';  my $config = 'conf/config.yml';
72  my $debug = 0;  my $debug = 0;
73  my $only_db_name;  my $only_db_name;
74    my $force_set = 0;
75    my $stats = 0;
76    
77  GetOptions(  GetOptions(
78          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 69  GetOptions( Line 82  GetOptions(
82          "only=s" => \$only_db_name,          "only=s" => \$only_db_name,
83          "config" => \$config,          "config" => \$config,
84          "debug" => \$debug,          "debug" => \$debug,
85            "force-set" => \$force_set,
86            "stats" => \$stats,
87  );  );
88    
89  $config = LoadFile($config);  $config = LoadFile($config);
# Line 77  print "config = ",Dumper($config) if ($d Line 92  print "config = ",Dumper($config) if ($d
92    
93  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->{databases});
94    
95    my $log = _new WebPAC::Common()->_get_logger();
96    $log->info( "-" x 79 );
97    
98    my $use_indexer = $config->{use_indexer} || 'hyperestraier';
99    if ($stats) {
100            $log->debug("option --stats disables update of indexing engine...");
101            $use_indexer = undef;
102    } else {
103            $log->info("using $use_indexer indexing engine...");
104    }
105    
106  my $total_rows = 0;  my $total_rows = 0;
107  my $start_t = time();  my $start_t = time();
108    
# Line 84  while (my ($database, $db_config) = each Line 110  while (my ($database, $db_config) = each
110    
111          next if ($only_db_name && $database !~ m/$only_db_name/i);          next if ($only_db_name && $database !~ m/$only_db_name/i);
112    
113          my $log = _new WebPAC::Common()->_get_logger();          my $indexer;
114    
115          #          if ($use_indexer) {
116          # open Hyper Estraier database                  my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");
117          #                  $indexer_config->{database} = $database;
118                    $indexer_config->{clean} = $clean;
119                    $indexer_config->{label} = $db_config->{name};
120    
121                    if ($use_indexer eq 'hyperestraier') {
122    
123                            # open Hyper Estraier database
124                            use WebPAC::Output::Estraier '0.10';
125                            $indexer = new WebPAC::Output::Estraier( %{ $indexer_config } );
126                    
127                    } elsif ($use_indexer eq 'kinosearch') {
128    
129                            # open KinoSearch
130                            use WebPAC::Output::KinoSearch;
131                            $indexer_config->{clean} = 1 unless (-e $indexer_config->{index_path});
132                            $indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } );
133    
134                    } else {
135                            $log->logdie("unknown use_indexer: $use_indexer");
136                    }
137    
138          my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");                  $log->logide("can't continue without valid indexer") unless ($indexer);
139          $est_config->{database} = $database;          }
         $est_config->{clean} = $clean;  
         $est_config->{label} = $db_config->{name};  
140    
         my $est = new WebPAC::Output::Estraier( %{ $est_config } );  
141    
142          #          #
143          # now WebPAC::Store          # now WebPAC::Store
# Line 155  while (my ($database, $db_config) = each Line 197  while (my ($database, $db_config) = each
197                          offset => $offset,                          offset => $offset,
198                          lookup => $lookup,                          lookup => $lookup,
199                          recode => $input->{recode},                          recode => $input->{recode},
200                            stats => $stats,
201                  );                  );
202                  $log->logdie("can't create input using $input_module") unless ($input);                  $log->logdie("can't create input using $input_module") unless ($input);
203    
# Line 171  while (my ($database, $db_config) = each Line 214  while (my ($database, $db_config) = each
214                          prefix => $input->{name},                          prefix => $input->{name},
215                  );                  );
216    
217                    my $rules;
218                  my $normalize_path = $input->{normalize}->{path};                  my $normalize_path = $input->{normalize}->{path};
219    
220                    if ($force_set) {
221                            my $new_norm_path = $normalize_path;
222                            $new_norm_path =~ s/\.xml$/.pl/;
223                            if (-e $new_norm_path) {
224                                    $log->debug("--force-set replaced $normalize_path with $new_norm_path");
225                                    $normalize_path = $new_norm_path;
226                            } else {
227                                    $log->debug("--force-set failed on $new_norm_path, fallback to $normalize_path");
228                            }
229                    }
230    
231                  if ($normalize_path =~ m/\.xml$/i) {                  if ($normalize_path =~ m/\.xml$/i) {
232                          $n->open(                          $n->open(
233                                  tag => $input->{normalize}->{tag},                                  tag => $input->{normalize}->{tag},
234                                  xml_file => $input->{normalize}->{path},                                  xml_file => $normalize_path,
235                          );                          );
236                  } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {                  } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {
237                          $n->open_yaml(                          $n->open_yaml(
238                                  path => $normalize_path,                                  path => $normalize_path,
239                                  tag => $input->{normalize}->{tag},                                  tag => $input->{normalize}->{tag},
240                          );                          );
241                    } elsif ($normalize_path =~ m/\.(?:pl)$/i) {
242                            $n = undef;
243                            $log->info("using WebPAC::Normalize::Set to process $normalize_path");
244                            $rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!";
245                  }                  }
246    
247                  foreach my $pos ( 0 ... $input_db->size ) {                  foreach my $pos ( 0 ... $input_db->size ) {
# Line 197  while (my ($database, $db_config) = each Line 256  while (my ($database, $db_config) = each
256                                  push @{ $row->{'000'} }, $pos;                                  push @{ $row->{'000'} }, $pos;
257                          }                          }
258    
259                          my $ds = $n->data_structure($row);                                  
260                            my $ds;
261                            if ($n) {
262                                    $ds = $n->data_structure($row);
263                            } else {
264                                    $ds = WebPAC::Normalize::Set::data_structure(
265                                            row => $row,
266                                            rules => $rules,
267                                            lookup => $lookup->lookup_hash,
268                                    );
269    
270                                    $db->save_ds(
271                                            id => $mfn,
272                                            ds => $ds,
273                                            prefix => $input->{name},
274                                    ) if ($ds && !$stats);
275                            }
276    
277                          $est->add(                          $indexer->add(
278                                  id => $input->{name} . "/" . $mfn,                                  id => $input->{name} . "/" . $mfn,
279                                  ds => $ds,                                  ds => $ds,
280                                  type => $config->{hyperestraier}->{type},                                  type => $config->{$use_indexer}->{type},
281                          );                          ) if ($indexer);
282    
283                          $total_rows++;                          $total_rows++;
284                  }                  }
285    
286                    $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats);
287    
288          };          };
289    
290            eval { $indexer->finish } if ($indexer && $indexer->can('finish'));
291    
292          my $dt = time() - $start_t;          my $dt = time() - $start_t;
293          $log->info("$total_rows records indexed in " .          $log->info("$total_rows records indexed in " .
294                  sprintf("%.2f sec [%.2f rec/sec]",                  sprintf("%.2f sec [%.2f rec/sec]",
# Line 222  while (my ($database, $db_config) = each Line 301  while (my ($database, $db_config) = each
301          #          #
302          if (ref($db_config->{links}) eq 'ARRAY') {          if (ref($db_config->{links}) eq 'ARRAY') {
303                  foreach my $link (@{ $db_config->{links} }) {                  foreach my $link (@{ $db_config->{links} }) {
304                          $log->info("adding link $database -> $link->{to} [$link->{credit}]");                          if ($use_indexer eq 'hyperestraier') {
305                          $est->add_link(                                  $log->info("adding link $database -> $link->{to} [$link->{credit}]");
306                                  from => $database,                                  $indexer->add_link(
307                                  to => $link->{to},                                          from => $database,
308                                  credit => $link->{credit},                                          to => $link->{to},
309                          );                                          credit => $link->{credit},
310                                    );
311                            } else {
312                                    $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");
313                            }
314                  }                  }
315          }          }
316    

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

  ViewVC Help
Powered by ViewVC 1.1.26