9 |
|
|
10 |
use WebPAC::Common 0.02; |
use WebPAC::Common 0.02; |
11 |
use WebPAC::Lookup; |
use WebPAC::Lookup; |
12 |
use WebPAC::Input::ISIS 0.02; |
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::Output::TT; |
use WebPAC::Output::TT; |
16 |
use WebPAC::Output::Estraier 0.05; |
use WebPAC::Output::Estraier '0.10'; |
17 |
use YAML qw/LoadFile/; |
use YAML qw/LoadFile/; |
18 |
use LWP::Simple; |
use Getopt::Long; |
19 |
|
use File::Path; |
20 |
|
use Time::HiRes qw/time/; |
21 |
|
|
22 |
my $limit = shift @ARGV; |
=head1 NAME |
23 |
|
|
24 |
my $config = LoadFile('conf/config.yml'); |
run.pl - start WebPAC indexing |
25 |
|
|
26 |
print "config = ",Dumper($config); |
B<this command will probably go away. Don't get used to it!> |
27 |
|
|
28 |
|
Options: |
29 |
|
|
30 |
|
=over 4 |
31 |
|
|
32 |
|
=item --offset 42 |
33 |
|
|
34 |
|
start loading (all) databases at offset 42 |
35 |
|
|
36 |
|
=item --limit 100 |
37 |
|
|
38 |
|
limit loading to 100 records |
39 |
|
|
40 |
|
=item --clean |
41 |
|
|
42 |
|
remove database and Hyper Estraier index before indexing |
43 |
|
|
44 |
|
=item --one=database_name |
45 |
|
|
46 |
|
reindex just single database |
47 |
|
|
48 |
|
=item --config conf/config.yml |
49 |
|
|
50 |
|
path to YAML configuration file |
51 |
|
|
52 |
|
=back |
53 |
|
|
54 |
|
=cut |
55 |
|
|
56 |
|
my $offset; |
57 |
|
my $limit; |
58 |
|
|
59 |
|
my $clean = 0; |
60 |
|
my $config = 'conf/config.yml'; |
61 |
|
my $debug = 0; |
62 |
|
my $one_db_name; |
63 |
|
|
64 |
|
GetOptions( |
65 |
|
"limit=i" => \$limit, |
66 |
|
"offset=i" => \$offset, |
67 |
|
"clean" => \$clean, |
68 |
|
"one=s" => \$one_db_name, |
69 |
|
"config" => \$config, |
70 |
|
"debug" => \$debug, |
71 |
|
); |
72 |
|
|
73 |
|
$config = LoadFile($config); |
74 |
|
|
75 |
|
print "config = ",Dumper($config) if ($debug); |
76 |
|
|
77 |
die "no databases in config file!\n" unless ($config->{databases}); |
die "no databases in config file!\n" unless ($config->{databases}); |
78 |
|
|
79 |
my $total_rows = 0; |
my $total_rows = 0; |
80 |
|
my $start_t = time(); |
81 |
|
|
82 |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
while (my ($database, $db_config) = each %{ $config->{databases} }) { |
83 |
|
|
84 |
|
next if ($one_db_name && $database !~ m/$one_db_name/i); |
85 |
|
|
86 |
my $log = _new WebPAC::Common()->_get_logger(); |
my $log = _new WebPAC::Common()->_get_logger(); |
87 |
|
|
88 |
# |
# |
91 |
|
|
92 |
my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); |
my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); |
93 |
$est_config->{database} = $database; |
$est_config->{database} = $database; |
94 |
|
$est_config->{clean} = $clean; |
95 |
|
$est_config->{label} = $db_config->{name}; |
96 |
|
|
97 |
$log->info("using HyperEstraier URL $est_config->{masterurl}"); |
my $est = new WebPAC::Output::Estraier( %{ $est_config } ); |
|
|
|
|
my $est = new WebPAC::Output::Estraier( |
|
|
%{ $est_config }, |
|
|
); |
|
98 |
|
|
99 |
# |
# |
100 |
# now WebPAC::Store |
# now WebPAC::Store |
104 |
|
|
105 |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
106 |
|
|
107 |
$log->info("working on $database in $db_path"); |
if ($clean) { |
108 |
|
$log->info("creating new database $database in $db_path"); |
109 |
|
rmtree( $db_path ) || $log->warn("can't remove $db_path: $!"); |
110 |
|
} else { |
111 |
|
$log->debug("working on $database in $db_path"); |
112 |
|
} |
113 |
|
|
114 |
my $db = new WebPAC::Store( |
my $db = new WebPAC::Store( |
115 |
path => $db_path, |
path => $db_path, |
116 |
database => $database, |
database => $database, |
117 |
debug => 1, |
debug => $debug, |
118 |
); |
); |
119 |
|
|
120 |
|
|
145 |
|
|
146 |
my $input_module = $config->{webpac}->{inputs}->{$type}; |
my $input_module = $config->{webpac}->{inputs}->{$type}; |
147 |
|
|
148 |
$log->info("working on input $input->{path} [$input->{type}] using $input_module"); |
$log->info("working on input '$input->{path}' [$input->{type}] using $input_module lookup '$input->{lookup}'"); |
|
|
|
|
sub new_input { |
|
|
my $name = shift; |
|
|
my $args = shift; |
|
|
new $name->($args); |
|
|
} |
|
149 |
|
|
150 |
my $input = new_input($input_module,{ |
my $input_db = new WebPAC::Input( |
151 |
|
module => $input_module, |
152 |
code_page => $config->{webpac}->{webpac_encoding}, |
code_page => $config->{webpac}->{webpac_encoding}, |
153 |
limit_mfn => $input->{limit}, |
limit => $limit || $input->{limit}, |
154 |
|
offset => $offset, |
155 |
lookup => $lookup, |
lookup => $lookup, |
156 |
}); |
); |
157 |
$log->logdie("can't create input using $input_module") unless ($input); |
$log->logdie("can't create input using $input_module") unless ($input); |
158 |
|
|
159 |
my $maxmfn = $input->open( |
my $maxmfn = $input_db->open( |
160 |
path => $input->{path}, |
path => $input->{path}, |
161 |
code_page => $input->{encoding}, # database encoding |
code_page => $input->{encoding}, # database encoding |
162 |
); |
); |
183 |
); |
); |
184 |
} |
} |
185 |
|
|
186 |
for ( 0 ... $input->size ) { |
foreach my $pos ( 0 ... $input_db->size ) { |
187 |
|
|
188 |
|
my $row = $input_db->fetch || next; |
189 |
|
|
190 |
my $row = $input->fetch || next; |
my $mfn = $row->{'000'}->[0]; |
191 |
|
|
192 |
my $mfn = $row->{'000'}->[0] || die "can't find MFN"; |
if (! $mfn || $mfn !~ m#^\d+$#) { |
193 |
|
$log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); |
194 |
|
$mfn = $pos; |
195 |
|
push @{ $row->{'000'} }, $pos; |
196 |
|
} |
197 |
|
|
198 |
my $ds = $n->data_structure($row); |
my $ds = $n->data_structure($row); |
199 |
|
|
200 |
$est->add( |
$est->add( |
201 |
id => $input->{name} . "#" . $mfn, |
id => $input->{name} . "/" . $mfn, |
202 |
ds => $ds, |
ds => $ds, |
203 |
type => $config->{hyperestraier}->{type}, |
type => $config->{hyperestraier}->{type}, |
204 |
); |
); |
208 |
|
|
209 |
}; |
}; |
210 |
|
|
211 |
$log->info("$total_rows records indexed"); |
my $dt = time() - $start_t; |
212 |
|
$log->info("$total_rows records indexed in " . |
213 |
|
sprintf("%.2f sec [%.2f rec/sec]", |
214 |
|
$dt, ($total_rows / $dt) |
215 |
|
) |
216 |
|
); |
217 |
|
|
218 |
# |
# |
219 |
# add Hyper Estraier links to other databases |
# add Hyper Estraier links to other databases |