/[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 301 by dpavlin, Mon Dec 19 21:26:04 2005 UTC revision 431 by dpavlin, Mon Apr 17 15:10:04 2006 UTC
# Line 13  use WebPAC::Input 0.03; Line 13  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::Output::TT;  use WebPAC::Output::TT;
 use WebPAC::Output::Estraier 0.05;  
16  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
17  use Getopt::Long;  use Getopt::Long;
18  use File::Path;  use File::Path;
19    use Time::HiRes qw/time/;
20    
21  =head1 NAME  =head1 NAME
22    
# Line 40  limit loading to 100 records Line 40  limit loading to 100 records
40    
41  remove database and Hyper Estraier index before indexing  remove database and Hyper Estraier index before indexing
42    
43    =item --only=database_name
44    
45    reindex just single database (legacy name is --one)
46    
47  =item --config conf/config.yml  =item --config conf/config.yml
48    
49  path to YAML configuration file  path to YAML configuration file
# Line 54  my $limit; Line 58  my $limit;
58  my $clean = 0;  my $clean = 0;
59  my $config = 'conf/config.yml';  my $config = 'conf/config.yml';
60  my $debug = 0;  my $debug = 0;
61    my $only_db_name;
62    
63  GetOptions(  GetOptions(
64          "limit=i" => \$limit,          "limit=i" => \$limit,
65          "offset=i" => \$offset,          "offset=i" => \$offset,
66          "clean" => \$clean,          "clean" => \$clean,
67            "one=s" => \$only_db_name,
68            "only=s" => \$only_db_name,
69          "config" => \$config,          "config" => \$config,
70          "debug" => \$debug,          "debug" => \$debug,
71  );  );
# Line 69  print "config = ",Dumper($config) if ($d Line 76  print "config = ",Dumper($config) if ($d
76    
77  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->{databases});
78    
79    my $log = _new WebPAC::Common()->_get_logger();
80    
81    my $use_indexer = $config->{use_indexer} || 'hyperestraier';
82    $log->info("using $use_indexer indexing engine...");
83    
84  my $total_rows = 0;  my $total_rows = 0;
85    my $start_t = time();
86    
87  while (my ($database, $db_config) = each %{ $config->{databases} }) {  while (my ($database, $db_config) = each %{ $config->{databases} }) {
88    
89          my $log = _new WebPAC::Common()->_get_logger();          next if ($only_db_name && $database !~ m/$only_db_name/i);
   
         #  
         # open Hyper Estraier database  
         #  
90    
91          my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");          my $indexer;
         $est_config->{database} = $database;  
92    
93          my $est = new WebPAC::Output::Estraier(          my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");
94                  %{ $est_config },          $indexer_config->{database} = $database;
95          );          $indexer_config->{clean} = $clean;
96            $indexer_config->{label} = $db_config->{name};
97    
98            if ($use_indexer eq 'hyperestraier') {
99    
100                    # open Hyper Estraier database
101                    use WebPAC::Output::Estraier '0.10';
102                    $indexer = new WebPAC::Output::Estraier( %{ $indexer_config } );
103            
104            } elsif ($use_indexer eq 'kinosearch') {
105    
106                    # open KinoSearch
107                    use WebPAC::Output::KinoSearch;
108                    $indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } );
109    
110          if ($clean) {          } else {
111                  $log->warn("creating new empty index $database");                  $log->logdie("unknown use_indexer: $use_indexer");
                 $est->master( action => 'nodedel', name => $database );  
                 $est->master( action => 'nodeadd', name => $database, label => $database );  
112          }          }
113    
114            $log->logide("can't continue without valid indexer") unless ($indexer);
115    
116          #          #
117          # now WebPAC::Store          # now WebPAC::Store
118          #          #
# Line 104  while (my ($database, $db_config) = each Line 125  while (my ($database, $db_config) = each
125                  $log->info("creating new database $database in $db_path");                  $log->info("creating new database $database in $db_path");
126                  rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");                  rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");
127          } else {          } else {
128                  $log->info("working on $database in $db_path");                  $log->debug("working on $database in $db_path");
129          }          }
130    
131          my $db = new WebPAC::Store(          my $db = new WebPAC::Store(
# Line 141  while (my ($database, $db_config) = each Line 162  while (my ($database, $db_config) = each
162    
163                  my $input_module = $config->{webpac}->{inputs}->{$type};                  my $input_module = $config->{webpac}->{inputs}->{$type};
164    
165                  $log->info("working on input $input->{path} [$input->{type}] using $input_module");                  $log->info("working on input '$input->{path}' [$input->{type}] using $input_module lookup '$input->{lookup}'");
166    
167                  my $input_db = new WebPAC::Input(                  my $input_db = new WebPAC::Input(
168                          module => $input_module,                          module => $input_module,
# Line 149  while (my ($database, $db_config) = each Line 170  while (my ($database, $db_config) = each
170                          limit => $limit || $input->{limit},                          limit => $limit || $input->{limit},
171                          offset => $offset,                          offset => $offset,
172                          lookup => $lookup,                          lookup => $lookup,
173                            recode => $input->{recode},
174                  );                  );
175                  $log->logdie("can't create input using $input_module") unless ($input);                  $log->logdie("can't create input using $input_module") unless ($input);
176    
# Line 193  while (my ($database, $db_config) = each Line 215  while (my ($database, $db_config) = each
215    
216                          my $ds = $n->data_structure($row);                          my $ds = $n->data_structure($row);
217    
218                          $est->add(                          $indexer->add(
219                                  id => $input->{name} . "/" . $mfn,                                  id => $input->{name} . "/" . $mfn,
220                                  ds => $ds,                                  ds => $ds,
221                                  type => $config->{hyperestraier}->{type},                                  type => $config->{$use_indexer}->{type},
222                          );                          );
223    
224                          $total_rows++;                          $total_rows++;
# Line 204  while (my ($database, $db_config) = each Line 226  while (my ($database, $db_config) = each
226    
227          };          };
228    
229          $log->info("$total_rows records indexed");          my $dt = time() - $start_t;
230            $log->info("$total_rows records indexed in " .
231                    sprintf("%.2f sec [%.2f rec/sec]",
232                            $dt, ($total_rows / $dt)
233                    )
234            );
235    
236          #          #
237          # add Hyper Estraier links to other databases          # add Hyper Estraier links to other databases
238          #          #
239          if (ref($db_config->{links}) eq 'ARRAY') {          if (ref($db_config->{links}) eq 'ARRAY') {
240                  foreach my $link (@{ $db_config->{links} }) {                  foreach my $link (@{ $db_config->{links} }) {
241                          $log->info("adding link $database -> $link->{to} [$link->{credit}]");                          if ($use_indexer eq 'hyperestraier') {
242                          $est->add_link(                                  $log->info("adding link $database -> $link->{to} [$link->{credit}]");
243                                  from => $database,                                  $indexer->add_link(
244                                  to => $link->{to},                                          from => $database,
245                                  credit => $link->{credit},                                          to => $link->{to},
246                          );                                          credit => $link->{credit},
247                                    );
248                            } else {
249                                    $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");
250                            }
251                  }                  }
252          }          }
253    

Legend:
Removed from v.301  
changed lines
  Added in v.431

  ViewVC Help
Powered by ViewVC 1.1.26