6 use File::Temp qw/tempdir/;
10 use WebPAC::Common 0.02;
12 use WebPAC::Input 0.03;
13 use WebPAC::Store 0.03;
14 use WebPAC::Normalize::XML;
15 use WebPAC::Output::TT;
16 use WebPAC::Output::Estraier '0.10';
17 use YAML qw/LoadFile/;
20 use Time::HiRes qw/time/;
24 run.pl - start WebPAC indexing
26 B<this command will probably go away. Don't get used to it!>
34 start loading (all) databases at offset 42
38 limit loading to 100 records
42 remove database and Hyper Estraier index before indexing
44 =item --one=database_name
46 reindex just single database
48 =item --config conf/config.yml
50 path to YAML configuration file
60 my $config = 'conf/config.yml';
66 "offset=i" => \$offset,
68 "one=s" => \$one_db_name,
73 $config = LoadFile($config);
75 print "config = ",Dumper($config) if ($debug);
77 die "no databases in config file!\n" unless ($config->{databases});
82 while (my ($database, $db_config) = each %{ $config->{databases} }) {
84 next if ($one_db_name && $database !~ m/$one_db_name/i);
86 my $log = _new WebPAC::Common()->_get_logger();
89 # open Hyper Estraier database
92 my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
93 $est_config->{database} = $database;
94 $est_config->{clean} = $clean;
95 $est_config->{label} = $db_config->{name};
97 my $est = new WebPAC::Output::Estraier( %{ $est_config } );
102 my $abs_path = abs_path($0);
103 $abs_path =~ s#/[^/]*$#/#;
105 my $db_path = $config->{webpac}->{db_path} . '/' . $database;
108 $log->info("creating new database $database in $db_path");
109 rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");
111 $log->debug("working on $database in $db_path");
114 my $db = new WebPAC::Store(
116 database => $database,
122 # now, iterate through input formats
126 if (ref($db_config->{input}) eq 'ARRAY') {
127 @inputs = @{ $db_config->{input} };
128 } elsif ($db_config->{input}) {
129 push @inputs, $db_config->{input};
131 $log->info("database $database doesn't have inputs defined");
134 my @supported_inputs = keys %{ $config->{webpac}->{inputs} };
136 foreach my $input (@inputs) {
138 my $type = lc($input->{type});
140 die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));
142 my $lookup = new WebPAC::Lookup(
143 lookup_file => $input->{lookup},
146 my $input_module = $config->{webpac}->{inputs}->{$type};
148 $log->info("working on input '$input->{path}' [$input->{type}] using $input_module lookup '$input->{lookup}'");
150 my $input_db = new WebPAC::Input(
151 module => $input_module,
152 code_page => $config->{webpac}->{webpac_encoding},
153 limit => $limit || $input->{limit},
156 recode => $input->{recode},
158 $log->logdie("can't create input using $input_module") unless ($input);
160 my $maxmfn = $input_db->open(
161 path => $input->{path},
162 code_page => $input->{encoding}, # database encoding
165 my $n = new WebPAC::Normalize::XML(
166 # filter => { 'foo' => sub { shift } },
168 lookup_regex => $lookup->regex,
170 prefix => $input->{name},
173 my $normalize_path = $input->{normalize}->{path};
175 if ($normalize_path =~ m/\.xml$/i) {
177 tag => $input->{normalize}->{tag},
178 xml_file => $input->{normalize}->{path},
180 } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {
182 path => $normalize_path,
183 tag => $input->{normalize}->{tag},
187 foreach my $pos ( 0 ... $input_db->size ) {
189 my $row = $input_db->fetch || next;
191 my $mfn = $row->{'000'}->[0];
193 if (! $mfn || $mfn !~ m#^\d+$#) {
194 $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos");
196 push @{ $row->{'000'} }, $pos;
199 my $ds = $n->data_structure($row);
202 id => $input->{name} . "/" . $mfn,
204 type => $config->{hyperestraier}->{type},
212 my $dt = time() - $start_t;
213 $log->info("$total_rows records indexed in " .
214 sprintf("%.2f sec [%.2f rec/sec]",
215 $dt, ($total_rows / $dt)
220 # add Hyper Estraier links to other databases
222 if (ref($db_config->{links}) eq 'ARRAY') {
223 foreach my $link (@{ $db_config->{links} }) {
224 $log->info("adding link $database -> $link->{to} [$link->{credit}]");
228 credit => $link->{credit},