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 --only=database_name
46 reindex just single database (legacy name is --one)
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" => \$only_db_name,
69 "only=s" => \$only_db_name,
74 $config = LoadFile($config);
76 print "config = ",Dumper($config) if ($debug);
78 die "no databases in config file!\n" unless ($config->{databases});
83 while (my ($database, $db_config) = each %{ $config->{databases} }) {
85 next if ($only_db_name && $database !~ m/$only_db_name/i);
87 my $log = _new WebPAC::Common()->_get_logger();
90 # open Hyper Estraier database
93 my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
94 $est_config->{database} = $database;
95 $est_config->{clean} = $clean;
96 $est_config->{label} = $db_config->{name};
98 my $est = new WebPAC::Output::Estraier( %{ $est_config } );
103 my $abs_path = abs_path($0);
104 $abs_path =~ s#/[^/]*$#/#;
106 my $db_path = $config->{webpac}->{db_path} . '/' . $database;
109 $log->info("creating new database $database in $db_path");
110 rmtree( $db_path ) || $log->warn("can't remove $db_path: $!");
112 $log->debug("working on $database in $db_path");
115 my $db = new WebPAC::Store(
117 database => $database,
123 # now, iterate through input formats
127 if (ref($db_config->{input}) eq 'ARRAY') {
128 @inputs = @{ $db_config->{input} };
129 } elsif ($db_config->{input}) {
130 push @inputs, $db_config->{input};
132 $log->info("database $database doesn't have inputs defined");
135 my @supported_inputs = keys %{ $config->{webpac}->{inputs} };
137 foreach my $input (@inputs) {
139 my $type = lc($input->{type});
141 die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs));
143 my $lookup = new WebPAC::Lookup(
144 lookup_file => $input->{lookup},
147 my $input_module = $config->{webpac}->{inputs}->{$type};
149 $log->info("working on input '$input->{path}' [$input->{type}] using $input_module lookup '$input->{lookup}'");
151 my $input_db = new WebPAC::Input(
152 module => $input_module,
153 code_page => $config->{webpac}->{webpac_encoding},
154 limit => $limit || $input->{limit},
157 recode => $input->{recode},
159 $log->logdie("can't create input using $input_module") unless ($input);
161 my $maxmfn = $input_db->open(
162 path => $input->{path},
163 code_page => $input->{encoding}, # database encoding
166 my $n = new WebPAC::Normalize::XML(
167 # filter => { 'foo' => sub { shift } },
169 lookup_regex => $lookup->regex,
171 prefix => $input->{name},
174 my $normalize_path = $input->{normalize}->{path};
176 if ($normalize_path =~ m/\.xml$/i) {
178 tag => $input->{normalize}->{tag},
179 xml_file => $input->{normalize}->{path},
181 } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) {
183 path => $normalize_path,
184 tag => $input->{normalize}->{tag},
188 foreach my $pos ( 0 ... $input_db->size ) {
190 my $row = $input_db->fetch || next;
192 my $mfn = $row->{'000'}->[0];
194 if (! $mfn || $mfn !~ m#^\d+$#) {
195 $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos");
197 push @{ $row->{'000'} }, $pos;
200 my $ds = $n->data_structure($row);
203 id => $input->{name} . "/" . $mfn,
205 type => $config->{hyperestraier}->{type},
213 my $dt = time() - $start_t;
214 $log->info("$total_rows records indexed in " .
215 sprintf("%.2f sec [%.2f rec/sec]",
216 $dt, ($total_rows / $dt)
221 # add Hyper Estraier links to other databases
223 if (ref($db_config->{links}) eq 'ARRAY') {
224 foreach my $link (@{ $db_config->{links} }) {
225 $log->info("adding link $database -> $link->{to} [$link->{credit}]");
229 credit => $link->{credit},