/[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 430 by dpavlin, Mon Apr 17 15:09:54 2006 UTC revision 493 by dpavlin, Sun May 14 13:42:48 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;
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 48  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  =back  =back
59    
60  =cut  =cut
# Line 59  my $clean = 0; Line 66  my $clean = 0;
66  my $config = 'conf/config.yml';  my $config = 'conf/config.yml';
67  my $debug = 0;  my $debug = 0;
68  my $only_db_name;  my $only_db_name;
69    my $force_set = 0;
70    
71  GetOptions(  GetOptions(
72          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 68  GetOptions( Line 76  GetOptions(
76          "only=s" => \$only_db_name,          "only=s" => \$only_db_name,
77          "config" => \$config,          "config" => \$config,
78          "debug" => \$debug,          "debug" => \$debug,
79            "force-set" => \$force_set,
80  );  );
81    
82  $config = LoadFile($config);  $config = LoadFile($config);
# Line 75  $config = LoadFile($config); Line 84  $config = LoadFile($config);
84  print "config = ",Dumper($config) if ($debug);  print "config = ",Dumper($config) if ($debug);
85    
86  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->{databases});
87    
88    my $log = _new WebPAC::Common()->_get_logger();
89    
90  my $use_indexer = $config->{use_indexer} || 'hyperestraier';  my $use_indexer = $config->{use_indexer} || 'hyperestraier';
91    $log->info("using $use_indexer indexing engine...");
92    
93  my $total_rows = 0;  my $total_rows = 0;
94  my $start_t = time();  my $start_t = time();
# Line 84  while (my ($database, $db_config) = each Line 97  while (my ($database, $db_config) = each
97    
98          next if ($only_db_name && $database !~ m/$only_db_name/i);          next if ($only_db_name && $database !~ m/$only_db_name/i);
99    
         my $log = _new WebPAC::Common()->_get_logger();  
   
100          my $indexer;          my $indexer;
101    
102            my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");
103            $indexer_config->{database} = $database;
104            $indexer_config->{clean} = $clean;
105            $indexer_config->{label} = $db_config->{name};
106    
107            # important: clean database just once!
108            $clean = 0;
109    
110          if ($use_indexer eq 'hyperestraier') {          if ($use_indexer eq 'hyperestraier') {
111    
                 #  
112                  # open Hyper Estraier database                  # open Hyper Estraier database
                 #  
   
113                  use WebPAC::Output::Estraier '0.10';                  use WebPAC::Output::Estraier '0.10';
114                  my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");                  $indexer = new WebPAC::Output::Estraier( %{ $indexer_config } );
115                  $est_config->{database} = $database;          
116                  $est_config->{clean} = $clean;          } elsif ($use_indexer eq 'kinosearch') {
117                  $est_config->{label} = $db_config->{name};  
118                    # open KinoSearch
119                    use WebPAC::Output::KinoSearch;
120                    $indexer_config->{clean} = 1 unless (-e $indexer_config->{index_path});
121                    $indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } );
122    
                 $indexer = new WebPAC::Output::Estraier( %{ $est_config } );  
123          } else {          } else {
124                  $log->logdie("unknown use_indexer: $use_indexer");                  $log->logdie("unknown use_indexer: $use_indexer");
125          }          }
# Line 181  while (my ($database, $db_config) = each Line 200  while (my ($database, $db_config) = each
200                          prefix => $input->{name},                          prefix => $input->{name},
201                  );                  );
202    
203                    my $rules;
204                  my $normalize_path = $input->{normalize}->{path};                  my $normalize_path = $input->{normalize}->{path};
205    
206                    if ($force_set) {
207                            my $new_norm_path = $normalize_path;
208                            $new_norm_path =~ s/\.xml$/.pl/;
209                            if (-e $new_norm_path) {
210                                    $log->debug("--force-set replaced $normalize_path with $new_norm_path");
211                                    $normalize_path = $new_norm_path;
212                            } else {
213                                    $log->debug("--force-set failed on $new_norm_path, fallback to $normalize_path");
214                            }
215                    }
216    
217                  if ($normalize_path =~ m/\.xml$/i) {                  if ($normalize_path =~ m/\.xml$/i) {
218                          $n->open(                          $n->open(
219                                  tag => $input->{normalize}->{tag},                                  tag => $input->{normalize}->{tag},
220                                  xml_file => $input->{normalize}->{path},                                  xml_file => $normalize_path,
221                          );                          );
222                  } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {                  } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {
223                          $n->open_yaml(                          $n->open_yaml(
224                                  path => $normalize_path,                                  path => $normalize_path,
225                                  tag => $input->{normalize}->{tag},                                  tag => $input->{normalize}->{tag},
226                          );                          );
227                    } elsif ($normalize_path =~ m/\.(?:pl)$/i) {
228                            $n = undef;
229                            $log->info("using WebPAC::Normalize::Set to process $normalize_path");
230                            $rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!";
231                  }                  }
232    
233                  foreach my $pos ( 0 ... $input_db->size ) {                  foreach my $pos ( 0 ... $input_db->size ) {
# Line 207  while (my ($database, $db_config) = each Line 242  while (my ($database, $db_config) = each
242                                  push @{ $row->{'000'} }, $pos;                                  push @{ $row->{'000'} }, $pos;
243                          }                          }
244    
245                          my $ds = $n->data_structure($row);                          my $ds = $n ? $n->data_structure($row) :
246                                    WebPAC::Normalize::Set::data_structure(
247                                            row => $row,
248                                            rules => $rules,
249                                            lookup => $lookup->lookup_hash,
250                                    );
251    
252                          $indexer->add(                          $indexer->add(
253                                  id => $input->{name} . "/" . $mfn,                                  id => $input->{name} . "/" . $mfn,
# Line 220  while (my ($database, $db_config) = each Line 260  while (my ($database, $db_config) = each
260    
261          };          };
262    
263            eval { $indexer->finish } if ($indexer->can('finish'));
264    
265          my $dt = time() - $start_t;          my $dt = time() - $start_t;
266          $log->info("$total_rows records indexed in " .          $log->info("$total_rows records indexed in " .
267                  sprintf("%.2f sec [%.2f rec/sec]",                  sprintf("%.2f sec [%.2f rec/sec]",
# Line 227  while (my ($database, $db_config) = each Line 269  while (my ($database, $db_config) = each
269                  )                  )
270          );          );
271    
272          if ($use_indexer eq 'hyperestraier') {          #
273                  #          # add Hyper Estraier links to other databases
274                  # add Hyper Estraier links to other databases          #
275                  #          if (ref($db_config->{links}) eq 'ARRAY') {
276                  if (ref($db_config->{links}) eq 'ARRAY') {                  foreach my $link (@{ $db_config->{links} }) {
277                          foreach my $link (@{ $db_config->{links} }) {                          if ($use_indexer eq 'hyperestraier') {
278                                  $log->info("adding link $database -> $link->{to} [$link->{credit}]");                                  $log->info("adding link $database -> $link->{to} [$link->{credit}]");
279                                  $indexer->add_link(                                  $indexer->add_link(
280                                          from => $database,                                          from => $database,
281                                          to => $link->{to},                                          to => $link->{to},
282                                          credit => $link->{credit},                                          credit => $link->{credit},
283                                  );                                  );
284                            } else {
285                                    $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");
286                          }                          }
287                  }                  }
         } else {  
                 $log->warn("links not implemented for $use_indexer");  
288          }          }
289    
290  }  }

Legend:
Removed from v.430  
changed lines
  Added in v.493

  ViewVC Help
Powered by ViewVC 1.1.26