42 |
|
|
43 |
remove database and Hyper Estraier index before indexing |
remove database and Hyper Estraier index before indexing |
44 |
|
|
45 |
=item --only=database_name |
=item --only=database_name/input_filter |
46 |
|
|
47 |
reindex just single database (legacy name is --one) |
reindex just single database (legacy name is --one) |
48 |
|
|
49 |
|
C</input_filter> is optional part which can be C<name> |
50 |
|
or C<type> from input |
51 |
|
|
52 |
=item --config conf/config.yml |
=item --config conf/config.yml |
53 |
|
|
54 |
path to YAML configuration file |
path to YAML configuration file |
55 |
|
|
56 |
=item --force-set |
=item --force-set |
57 |
|
|
58 |
force conversion C<normalize->path> in C<config.yml> from |
force conversion C<< normalize->path >> in C<config.yml> from |
59 |
C<.xml> to C<.pl> |
C<.xml> to C<.pl> |
60 |
|
|
61 |
|
=item --stats |
62 |
|
|
63 |
|
disable indexing and dump statistics about field and subfield |
64 |
|
usage for each input |
65 |
|
|
66 |
=back |
=back |
67 |
|
|
68 |
=cut |
=cut |
73 |
my $clean = 0; |
my $clean = 0; |
74 |
my $config = 'conf/config.yml'; |
my $config = 'conf/config.yml'; |
75 |
my $debug = 0; |
my $debug = 0; |
76 |
my $only_db_name; |
my $only_filter; |
77 |
my $force_set = 0; |
my $force_set = 0; |
78 |
|
my $stats = 0; |
79 |
|
|
80 |
GetOptions( |
GetOptions( |
81 |
"limit=i" => \$limit, |
"limit=i" => \$limit, |
82 |
"offset=i" => \$offset, |
"offset=i" => \$offset, |
83 |
"clean" => \$clean, |
"clean" => \$clean, |
84 |
"one=s" => \$only_db_name, |
"one=s" => \$only_filter, |
85 |
"only=s" => \$only_db_name, |
"only=s" => \$only_filter, |
86 |
"config" => \$config, |
"config" => \$config, |
87 |
"debug" => \$debug, |
"debug" => \$debug, |
88 |
"force-set" => \$force_set, |
"force-set" => \$force_set, |
89 |
|
"stats" => \$stats, |
90 |
); |
); |
91 |
|
|
92 |
$config = LoadFile($config); |
$config = LoadFile($config); |
96 |
die "no databases in config file!\n" unless ($config->{databases}); |
die "no databases in config file!\n" unless ($config->{databases}); |
97 |
|
|
98 |
my $log = _new WebPAC::Common()->_get_logger(); |
my $log = _new WebPAC::Common()->_get_logger(); |
99 |
|
$log->info( "-" x 79 ); |
100 |
|
|
101 |
my $use_indexer = $config->{use_indexer} || 'hyperestraier'; |
my $use_indexer = $config->{use_indexer} || 'hyperestraier'; |
102 |
$log->info("using $use_indexer indexing engine..."); |
if ($stats) { |
103 |
|
$log->debug("option --stats disables update of indexing engine..."); |
104 |
|
$use_indexer = undef; |
105 |
|
} else { |
106 |
|
$log->info("using $use_indexer indexing engine..."); |
107 |
|
} |
108 |
|
|
109 |
my $total_rows = 0; |
my $total_rows = 0; |
110 |
my $start_t = time(); |
my $start_t = time(); |
111 |
|
|
112 |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
113 |
|
|
114 |
next if ($only_db_name && $database !~ m/$only_db_name/i); |
my ($only_database,$only_input) = split(m#/#, $only_filter); |
115 |
|
next if ($only_database && $database !~ m/$only_database/i); |
116 |
|
|
117 |
my $indexer; |
my $indexer; |
118 |
|
|
119 |
my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration"); |
if ($use_indexer) { |
120 |
$indexer_config->{database} = $database; |
my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration"); |
121 |
$indexer_config->{clean} = $clean; |
$indexer_config->{database} = $database; |
122 |
$indexer_config->{label} = $db_config->{name}; |
$indexer_config->{clean} = $clean; |
123 |
|
$indexer_config->{label} = $db_config->{name}; |
124 |
# important: clean database just once! |
|
125 |
$clean = 0; |
if ($use_indexer eq 'hyperestraier') { |
126 |
|
|
127 |
if ($use_indexer eq 'hyperestraier') { |
# open Hyper Estraier database |
128 |
|
use WebPAC::Output::Estraier '0.10'; |
129 |
# open Hyper Estraier database |
$indexer = new WebPAC::Output::Estraier( %{ $indexer_config } ); |
130 |
use WebPAC::Output::Estraier '0.10'; |
|
131 |
$indexer = new WebPAC::Output::Estraier( %{ $indexer_config } ); |
} elsif ($use_indexer eq 'kinosearch') { |
132 |
|
|
133 |
} elsif ($use_indexer eq 'kinosearch') { |
# open KinoSearch |
134 |
|
use WebPAC::Output::KinoSearch; |
135 |
# open KinoSearch |
$indexer_config->{clean} = 1 unless (-e $indexer_config->{index_path}); |
136 |
use WebPAC::Output::KinoSearch; |
$indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } ); |
|
$indexer_config->{clean} = 1 unless (-e $indexer_config->{index_path}); |
|
|
$indexer = new WebPAC::Output::KinoSearch( %{ $indexer_config } ); |
|
137 |
|
|
138 |
} else { |
} else { |
139 |
$log->logdie("unknown use_indexer: $use_indexer"); |
$log->logdie("unknown use_indexer: $use_indexer"); |
140 |
|
} |
141 |
|
|
142 |
|
$log->logide("can't continue without valid indexer") unless ($indexer); |
143 |
} |
} |
144 |
|
|
|
$log->logide("can't continue without valid indexer") unless ($indexer); |
|
145 |
|
|
146 |
# |
# |
147 |
# now WebPAC::Store |
# now WebPAC::Store |
152 |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
153 |
|
|
154 |
if ($clean) { |
if ($clean) { |
155 |
$log->info("creating new database $database in $db_path"); |
$log->info("creating new database '$database' in $db_path"); |
156 |
rmtree( $db_path ) || $log->warn("can't remove $db_path: $!"); |
rmtree( $db_path ) || $log->warn("can't remove $db_path: $!"); |
157 |
} else { |
} else { |
158 |
$log->debug("working on $database in $db_path"); |
$log->info("working on database '$database' in $db_path"); |
159 |
} |
} |
160 |
|
|
161 |
my $db = new WebPAC::Store( |
my $db = new WebPAC::Store( |
182 |
|
|
183 |
foreach my $input (@inputs) { |
foreach my $input (@inputs) { |
184 |
|
|
185 |
|
next if ($only_input && $input->{name} =~ m#$only_input#i || $input->{type} =~ m#$only_input#i); |
186 |
|
|
187 |
my $type = lc($input->{type}); |
my $type = lc($input->{type}); |
188 |
|
|
189 |
die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); |
die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); |
194 |
|
|
195 |
my $input_module = $config->{webpac}->{inputs}->{$type}; |
my $input_module = $config->{webpac}->{inputs}->{$type}; |
196 |
|
|
197 |
$log->info("working on input '$input->{path}' [$input->{type}] using $input_module lookup '$input->{lookup}'"); |
$log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module lookup '$input->{lookup}'"); |
198 |
|
|
199 |
my $input_db = new WebPAC::Input( |
my $input_db = new WebPAC::Input( |
200 |
module => $input_module, |
module => $input_module, |
203 |
offset => $offset, |
offset => $offset, |
204 |
lookup => $lookup, |
lookup => $lookup, |
205 |
recode => $input->{recode}, |
recode => $input->{recode}, |
206 |
|
stats => $stats, |
207 |
); |
); |
208 |
$log->logdie("can't create input using $input_module") unless ($input); |
$log->logdie("can't create input using $input_module") unless ($input); |
209 |
|
|
227 |
my $new_norm_path = $normalize_path; |
my $new_norm_path = $normalize_path; |
228 |
$new_norm_path =~ s/\.xml$/.pl/; |
$new_norm_path =~ s/\.xml$/.pl/; |
229 |
if (-e $new_norm_path) { |
if (-e $new_norm_path) { |
230 |
$log->info("--force-set replaced $normalize_path with $new_norm_path"); |
$log->debug("--force-set replaced $normalize_path with $new_norm_path"); |
231 |
$normalize_path = $new_norm_path; |
$normalize_path = $new_norm_path; |
232 |
} else { |
} else { |
233 |
$log->warn("--force-set failed on $new_norm_path, fallback to $normalize_path"); |
$log->debug("--force-set failed on $new_norm_path, fallback to $normalize_path"); |
234 |
} |
} |
235 |
} |
} |
236 |
|
|
262 |
push @{ $row->{'000'} }, $pos; |
push @{ $row->{'000'} }, $pos; |
263 |
} |
} |
264 |
|
|
265 |
my $ds = $n ? $n->data_structure($row) : |
|
266 |
WebPAC::Normalize::Set::data_structure( |
my $ds; |
267 |
|
if ($n) { |
268 |
|
$ds = $n->data_structure($row); |
269 |
|
} else { |
270 |
|
$ds = WebPAC::Normalize::Set::data_structure( |
271 |
row => $row, |
row => $row, |
272 |
rules => $rules, |
rules => $rules, |
273 |
lookup => $lookup->lookup_hash, |
lookup => $lookup->lookup_hash, |
274 |
); |
); |
275 |
|
|
276 |
|
$db->save_ds( |
277 |
|
id => $mfn, |
278 |
|
ds => $ds, |
279 |
|
prefix => $input->{name}, |
280 |
|
) if ($ds && !$stats); |
281 |
|
} |
282 |
|
|
283 |
$indexer->add( |
$indexer->add( |
284 |
id => $input->{name} . "/" . $mfn, |
id => $input->{name} . "/" . $mfn, |
285 |
ds => $ds, |
ds => $ds, |
286 |
type => $config->{$use_indexer}->{type}, |
type => $config->{$use_indexer}->{type}, |
287 |
); |
) if ($indexer); |
288 |
|
|
289 |
$total_rows++; |
$total_rows++; |
290 |
} |
} |
291 |
|
|
292 |
|
$log->info("statistics of fields usage:\n", $input_db->stats) if ($stats); |
293 |
|
|
294 |
}; |
}; |
295 |
|
|
296 |
eval { $indexer->finish } if ($indexer->can('finish')); |
eval { $indexer->finish } if ($indexer && $indexer->can('finish')); |
297 |
|
|
298 |
my $dt = time() - $start_t; |
my $dt = time() - $start_t; |
299 |
$log->info("$total_rows records indexed in " . |
$log->info("$total_rows records ", $indexer ? "indexed " : "", |
300 |
sprintf("%.2f sec [%.2f rec/sec]", |
sprintf("in %.2f sec [%.2f rec/sec]", |
301 |
$dt, ($total_rows / $dt) |
$dt, ($total_rows / $dt) |
302 |
) |
) |
303 |
); |
); |