8 |
|
|
9 |
use WebPAC::Common 0.02; |
use WebPAC::Common 0.02; |
10 |
use WebPAC::Lookup 0.03; |
use WebPAC::Lookup 0.03; |
11 |
use WebPAC::Input 0.07; |
use WebPAC::Input 0.11; |
12 |
use WebPAC::Store 0.03; |
use WebPAC::Store 0.03; |
13 |
use WebPAC::Normalize 0.11; |
use WebPAC::Normalize 0.11; |
14 |
use WebPAC::Output::TT; |
use WebPAC::Output::TT; |
93 |
|
|
94 |
Create just links |
Create just links |
95 |
|
|
96 |
|
=item --merge |
97 |
|
|
98 |
|
Create merged index of databases which have links |
99 |
|
|
100 |
=back |
=back |
101 |
|
|
102 |
=cut |
=cut |
115 |
my $marc_dump = 0; |
my $marc_dump = 0; |
116 |
my $parallel = 0; |
my $parallel = 0; |
117 |
my $only_links = 0; |
my $only_links = 0; |
118 |
|
my $merge = 0; |
119 |
|
|
120 |
|
my $log = _new WebPAC::Common()->_get_logger(); |
121 |
|
|
122 |
|
my $hostname = `hostname`; |
123 |
|
chomp($hostname); |
124 |
|
$hostname =~ s/\..+$//; |
125 |
|
if (-e "conf/$hostname.yml") { |
126 |
|
$config = "conf/$hostname.yml"; |
127 |
|
$log->info("using host configuration file: $config"); |
128 |
|
} |
129 |
|
|
130 |
GetOptions( |
GetOptions( |
131 |
"limit=i" => \$limit, |
"limit=i" => \$limit, |
143 |
"marc-dump!" => \$marc_dump, |
"marc-dump!" => \$marc_dump, |
144 |
"parallel=i" => \$parallel, |
"parallel=i" => \$parallel, |
145 |
"only-links!" => \$only_links, |
"only-links!" => \$only_links, |
146 |
|
"merge" => \$merge, |
147 |
); |
); |
148 |
|
|
149 |
$config = LoadFile($config); |
$config = LoadFile($config); |
150 |
|
|
151 |
print "config = ",dump($config) if ($debug); |
#print "config = ",dump($config) if ($debug); |
152 |
|
|
153 |
die "no databases in config file!\n" unless ($config->{databases}); |
die "no databases in config file!\n" unless ($config->{databases}); |
154 |
|
|
|
my $log = _new WebPAC::Common()->_get_logger(); |
|
155 |
$log->info( "-" x 79 ); |
$log->info( "-" x 79 ); |
156 |
|
|
157 |
|
|
158 |
|
my $estcmd_fh; |
159 |
|
my $estcmd_path = './estcmd-merge.sh'; |
160 |
|
if ($merge) { |
161 |
|
open($estcmd_fh, '>', $estcmd_path) || $log->logdie("can't open $estcmd_path: $!"); |
162 |
|
print $estcmd_fh 'cd /data/estraier/_node/ || exit 1',$/; |
163 |
|
print $estcmd_fh 'sudo /etc/init.d/hyperestraier stop',$/; |
164 |
|
$log->info("created merge batch file $estcmd_path"); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
my $validate; |
my $validate; |
169 |
$validate = new WebPAC::Validate( |
$validate = new WebPAC::Validate( |
170 |
path => $validate_path, |
path => $validate_path, |
171 |
) if ($validate_path); |
) if ($validate_path); |
172 |
|
|
173 |
|
|
174 |
my $use_indexer = $config->{use_indexer} || 'hyperestraier'; |
my $use_indexer = $config->{use_indexer} || 'hyperestraier'; |
175 |
if ($stats) { |
if ($stats) { |
176 |
$log->debug("option --stats disables update of indexing engine..."); |
$log->debug("option --stats disables update of indexing engine..."); |
213 |
$indexer_config->{clean} = $clean; |
$indexer_config->{clean} = $clean; |
214 |
$indexer_config->{label} = $db_config->{name}; |
$indexer_config->{label} = $db_config->{name}; |
215 |
|
|
216 |
|
# force clean if database has links |
217 |
|
$indexer_config->{clean} = 1 if ($db_config->{links}); |
218 |
|
|
219 |
if ($use_indexer eq 'hyperestraier') { |
if ($use_indexer eq 'hyperestraier') { |
220 |
|
|
221 |
# open Hyper Estraier database |
# open Hyper Estraier database |
243 |
if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) { |
if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) { |
244 |
foreach my $link (@{ $db_config->{links} }) { |
foreach my $link (@{ $db_config->{links} }) { |
245 |
if ($use_indexer eq 'hyperestraier') { |
if ($use_indexer eq 'hyperestraier') { |
246 |
$log->info("saving link $database -> $link->{to} [$link->{credit}]"); |
if ($merge) { |
247 |
push @links, sub { |
print $estcmd_fh 'sudo -u www-data estcmd merge ' . $database . ' ' . $link->{to},$/; |
248 |
$log->info("adding link $database -> $link->{to} [$link->{credit}]"); |
} else { |
249 |
$indexer->add_link( |
$log->info("saving link $database -> $link->{to} [$link->{credit}]"); |
250 |
from => $database, |
push @links, sub { |
251 |
to => $link->{to}, |
$log->info("adding link $database -> $link->{to} [$link->{credit}]"); |
252 |
credit => $link->{credit}, |
$indexer->add_link( |
253 |
); |
from => $database, |
254 |
}; |
to => $link->{to}, |
255 |
|
credit => $link->{credit}, |
256 |
|
); |
257 |
|
}; |
258 |
|
} |
259 |
} else { |
} else { |
260 |
$log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]"); |
$log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]"); |
261 |
} |
} |
474 |
$log->info("all parallel processes finished"); |
$log->info("all parallel processes finished"); |
475 |
} |
} |
476 |
|
|
477 |
|
# |
478 |
foreach my $link (@links) { |
# handle links or merge after indexing |
479 |
$log->logdie("coderef in link ", Dumper($link), " is ", ref($link), " and not CODE") unless (ref($link) eq 'CODE'); |
# |
480 |
$link->(); |
|
481 |
|
if ($merge) { |
482 |
|
print $estcmd_fh 'sudo /etc/init.d/hyperestraier start',$/; |
483 |
|
close($estcmd_fh); |
484 |
|
chmod 0700, $estcmd_path || $log->warn("can't chmod 0700 $estcmd_path: $!"); |
485 |
|
system $estcmd_path; |
486 |
|
} else { |
487 |
|
foreach my $link (@links) { |
488 |
|
$log->logdie("coderef in link ", Dumper($link), " is ", ref($link), " and not CODE") unless (ref($link) eq 'CODE'); |
489 |
|
$link->(); |
490 |
|
} |
491 |
} |
} |
|
|
|