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 |
|
|
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 |
|
=item --stats |
59 |
|
|
60 |
|
dump statistics about used fields and subfields in each input |
61 |
|
|
62 |
=back |
=back |
63 |
|
|
64 |
=cut |
=cut |
70 |
my $config = 'conf/config.yml'; |
my $config = 'conf/config.yml'; |
71 |
my $debug = 0; |
my $debug = 0; |
72 |
my $only_db_name; |
my $only_db_name; |
73 |
|
my $force_set = 0; |
74 |
|
my $stats = 0; |
75 |
|
|
76 |
GetOptions( |
GetOptions( |
77 |
"limit=i" => \$limit, |
"limit=i" => \$limit, |
81 |
"only=s" => \$only_db_name, |
"only=s" => \$only_db_name, |
82 |
"config" => \$config, |
"config" => \$config, |
83 |
"debug" => \$debug, |
"debug" => \$debug, |
84 |
|
"force-set" => \$force_set, |
85 |
|
"stats" => \$stats, |
86 |
); |
); |
87 |
|
|
88 |
$config = LoadFile($config); |
$config = LoadFile($config); |
120 |
|
|
121 |
# open KinoSearch |
# open KinoSearch |
122 |
use WebPAC::Output::KinoSearch; |
use WebPAC::Output::KinoSearch; |
123 |
|
$indexer_config->{clean} = 1 unless (-e $indexer_config->{index_path}); |
124 |
$indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } ); |
$indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } ); |
125 |
|
|
126 |
} else { |
} else { |
187 |
offset => $offset, |
offset => $offset, |
188 |
lookup => $lookup, |
lookup => $lookup, |
189 |
recode => $input->{recode}, |
recode => $input->{recode}, |
190 |
|
stats => $stats, |
191 |
); |
); |
192 |
$log->logdie("can't create input using $input_module") unless ($input); |
$log->logdie("can't create input using $input_module") unless ($input); |
193 |
|
|
204 |
prefix => $input->{name}, |
prefix => $input->{name}, |
205 |
); |
); |
206 |
|
|
207 |
|
my $rules; |
208 |
my $normalize_path = $input->{normalize}->{path}; |
my $normalize_path = $input->{normalize}->{path}; |
209 |
|
|
210 |
|
if ($force_set) { |
211 |
|
my $new_norm_path = $normalize_path; |
212 |
|
$new_norm_path =~ s/\.xml$/.pl/; |
213 |
|
if (-e $new_norm_path) { |
214 |
|
$log->debug("--force-set replaced $normalize_path with $new_norm_path"); |
215 |
|
$normalize_path = $new_norm_path; |
216 |
|
} else { |
217 |
|
$log->debug("--force-set failed on $new_norm_path, fallback to $normalize_path"); |
218 |
|
} |
219 |
|
} |
220 |
|
|
221 |
if ($normalize_path =~ m/\.xml$/i) { |
if ($normalize_path =~ m/\.xml$/i) { |
222 |
$n->open( |
$n->open( |
223 |
tag => $input->{normalize}->{tag}, |
tag => $input->{normalize}->{tag}, |
224 |
xml_file => $input->{normalize}->{path}, |
xml_file => $normalize_path, |
225 |
); |
); |
226 |
} elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) { |
} elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) { |
227 |
$n->open_yaml( |
$n->open_yaml( |
228 |
path => $normalize_path, |
path => $normalize_path, |
229 |
tag => $input->{normalize}->{tag}, |
tag => $input->{normalize}->{tag}, |
230 |
); |
); |
231 |
|
} elsif ($normalize_path =~ m/\.(?:pl)$/i) { |
232 |
|
$n = undef; |
233 |
|
$log->info("using WebPAC::Normalize::Set to process $normalize_path"); |
234 |
|
$rules = read_file( $normalize_path ) or die "can't open $normalize_path: $!"; |
235 |
} |
} |
236 |
|
|
237 |
foreach my $pos ( 0 ... $input_db->size ) { |
foreach my $pos ( 0 ... $input_db->size ) { |
246 |
push @{ $row->{'000'} }, $pos; |
push @{ $row->{'000'} }, $pos; |
247 |
} |
} |
248 |
|
|
249 |
my $ds = $n->data_structure($row); |
|
250 |
|
my $ds; |
251 |
|
if ($n) { |
252 |
|
$ds = $n->data_structure($row); |
253 |
|
} else { |
254 |
|
$ds = WebPAC::Normalize::Set::data_structure( |
255 |
|
row => $row, |
256 |
|
rules => $rules, |
257 |
|
lookup => $lookup->lookup_hash, |
258 |
|
); |
259 |
|
|
260 |
|
$db->save_ds( |
261 |
|
id => $mfn, |
262 |
|
ds => $ds, |
263 |
|
prefix => $input->{name}, |
264 |
|
) if ($ds); |
265 |
|
} |
266 |
|
|
267 |
$indexer->add( |
$indexer->add( |
268 |
id => $input->{name} . "/" . $mfn, |
id => $input->{name} . "/" . $mfn, |
273 |
$total_rows++; |
$total_rows++; |
274 |
} |
} |
275 |
|
|
276 |
|
$log->info("statistics of fields usage:\n", $input_db->stats) if ($stats); |
277 |
|
|
278 |
}; |
}; |
279 |
|
|
280 |
|
eval { $indexer->finish } if ($indexer->can('finish')); |
281 |
|
|
282 |
my $dt = time() - $start_t; |
my $dt = time() - $start_t; |
283 |
$log->info("$total_rows records indexed in " . |
$log->info("$total_rows records indexed in " . |
284 |
sprintf("%.2f sec [%.2f rec/sec]", |
sprintf("%.2f sec [%.2f rec/sec]", |