/[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 416 by dpavlin, Sun Feb 26 23:21:50 2006 UTC revision 504 by dpavlin, Sun May 14 22:24:18 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 41  limit loading to 100 records Line 42  limit loading to 100 records
42    
43  remove database and Hyper Estraier index before indexing  remove database and Hyper Estraier index before indexing
44    
45  =item --one=database_name  =item --only=database_name
46    
47  reindex just single database  reindex just single database (legacy name is --one)
48    
49  =item --config conf/config.yml  =item --config conf/config.yml
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 $limit; Line 65  my $limit;
65  my $clean = 0;  my $clean = 0;
66  my $config = 'conf/config.yml';  my $config = 'conf/config.yml';
67  my $debug = 0;  my $debug = 0;
68  my $one_db_name;  my $only_db_name;
69    my $force_set = 0;
70    
71  GetOptions(  GetOptions(
72          "limit=i" => \$limit,          "limit=i" => \$limit,
73          "offset=i" => \$offset,          "offset=i" => \$offset,
74          "clean" => \$clean,          "clean" => \$clean,
75          "one=s" => \$one_db_name,          "one=s" => \$only_db_name,
76            "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 76  print "config = ",Dumper($config) if ($d Line 85  print "config = ",Dumper($config) if ($d
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';
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();
95    
96  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
97    
98          next if ($one_db_name && $database !~ m/$one_db_name/i);          next if ($only_db_name && $database !~ m/$only_db_name/i);
99    
100          my $log = _new WebPAC::Common()->_get_logger();          my $indexer;
101    
102          #          my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");
103          # open Hyper Estraier database          $indexer_config->{database} = $database;
104          #          $indexer_config->{clean} = $clean;
105            $indexer_config->{label} = $db_config->{name};
106    
107            if ($use_indexer eq 'hyperestraier') {
108    
109                    # open Hyper Estraier database
110                    use WebPAC::Output::Estraier '0.10';
111                    $indexer = new WebPAC::Output::Estraier( %{ $indexer_config } );
112            
113            } elsif ($use_indexer eq 'kinosearch') {
114    
115                    # open KinoSearch
116                    use WebPAC::Output::KinoSearch;
117                    $indexer_config->{clean} = 1 unless (-e $indexer_config->{index_path});
118                    $indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } );
119    
120          my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");          } else {
121          $est_config->{database} = $database;                  $log->logdie("unknown use_indexer: $use_indexer");
122          $est_config->{clean} = $clean;          }
         $est_config->{label} = $db_config->{name};  
123    
124          my $est = new WebPAC::Output::Estraier( %{ $est_config } );          $log->logide("can't continue without valid indexer") unless ($indexer);
125    
126          #          #
127          # now WebPAC::Store          # now WebPAC::Store
# Line 170  while (my ($database, $db_config) = each Line 197  while (my ($database, $db_config) = each
197                          prefix => $input->{name},                          prefix => $input->{name},
198                  );                  );
199    
200                    my $rules;
201                  my $normalize_path = $input->{normalize}->{path};                  my $normalize_path = $input->{normalize}->{path};
202    
203                    if ($force_set) {
204                            my $new_norm_path = $normalize_path;
205                            $new_norm_path =~ s/\.xml$/.pl/;
206                            if (-e $new_norm_path) {
207                                    $log->debug("--force-set replaced $normalize_path with $new_norm_path");
208                                    $normalize_path = $new_norm_path;
209                            } else {
210                                    $log->debug("--force-set failed on $new_norm_path, fallback to $normalize_path");
211                            }
212                    }
213    
214                  if ($normalize_path =~ m/\.xml$/i) {                  if ($normalize_path =~ m/\.xml$/i) {
215                          $n->open(                          $n->open(
216                                  tag => $input->{normalize}->{tag},                                  tag => $input->{normalize}->{tag},
217                                  xml_file => $input->{normalize}->{path},                                  xml_file => $normalize_path,
218                          );                          );
219                  } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {                  } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {
220                          $n->open_yaml(                          $n->open_yaml(
221                                  path => $normalize_path,                                  path => $normalize_path,
222                                  tag => $input->{normalize}->{tag},                                  tag => $input->{normalize}->{tag},
223                          );                          );
224                    } elsif ($normalize_path =~ m/\.(?:pl)$/i) {
225                            $n = undef;
226                            $log->info("using WebPAC::Normalize::Set to process $normalize_path");
227                            $rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!";
228                  }                  }
229    
230                  foreach my $pos ( 0 ... $input_db->size ) {                  foreach my $pos ( 0 ... $input_db->size ) {
# Line 196  while (my ($database, $db_config) = each Line 239  while (my ($database, $db_config) = each
239                                  push @{ $row->{'000'} }, $pos;                                  push @{ $row->{'000'} }, $pos;
240                          }                          }
241    
242                          my $ds = $n->data_structure($row);                          my $ds = $n ? $n->data_structure($row) :
243                                    WebPAC::Normalize::Set::data_structure(
244                                            row => $row,
245                                            rules => $rules,
246                                            lookup => $lookup->lookup_hash,
247                                    );
248    
249                          $est->add(                          $indexer->add(
250                                  id => $input->{name} . "/" . $mfn,                                  id => $input->{name} . "/" . $mfn,
251                                  ds => $ds,                                  ds => $ds,
252                                  type => $config->{hyperestraier}->{type},                                  type => $config->{$use_indexer}->{type},
253                          );                          );
254    
255                          $total_rows++;                          $total_rows++;
# Line 209  while (my ($database, $db_config) = each Line 257  while (my ($database, $db_config) = each
257    
258          };          };
259    
260            eval { $indexer->finish } if ($indexer->can('finish'));
261    
262          my $dt = time() - $start_t;          my $dt = time() - $start_t;
263          $log->info("$total_rows records indexed in " .          $log->info("$total_rows records indexed in " .
264                  sprintf("%.2f sec [%.2f rec/sec]",                  sprintf("%.2f sec [%.2f rec/sec]",
# Line 221  while (my ($database, $db_config) = each Line 271  while (my ($database, $db_config) = each
271          #          #
272          if (ref($db_config->{links}) eq 'ARRAY') {          if (ref($db_config->{links}) eq 'ARRAY') {
273                  foreach my $link (@{ $db_config->{links} }) {                  foreach my $link (@{ $db_config->{links} }) {
274                          $log->info("adding link $database -> $link->{to} [$link->{credit}]");                          if ($use_indexer eq 'hyperestraier') {
275                          $est->add_link(                                  $log->info("adding link $database -> $link->{to} [$link->{credit}]");
276                                  from => $database,                                  $indexer->add_link(
277                                  to => $link->{to},                                          from => $database,
278                                  credit => $link->{credit},                                          to => $link->{to},
279                          );                                          credit => $link->{credit},
280                                    );
281                            } else {
282                                    $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");
283                            }
284                  }                  }
285          }          }
286    

Legend:
Removed from v.416  
changed lines
  Added in v.504

  ViewVC Help
Powered by ViewVC 1.1.26