9 |
|
|
10 |
use WebPAC::Common 0.02; |
use WebPAC::Common 0.02; |
11 |
use WebPAC::Lookup; |
use WebPAC::Lookup; |
12 |
use WebPAC::Input::ISIS; |
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.08; |
17 |
use YAML qw/LoadFile/; |
use YAML qw/LoadFile/; |
18 |
use LWP::Simple; |
use Getopt::Long; |
19 |
|
use File::Path; |
20 |
|
|
21 |
my $limit = shift @ARGV; |
=head1 NAME |
22 |
|
|
23 |
my $config = LoadFile('conf/config.yml'); |
run.pl - start WebPAC indexing |
24 |
|
|
25 |
print "config = ",Dumper($config); |
B<this command will probably go away. Don't get used to it!> |
26 |
|
|
27 |
|
Options: |
28 |
|
|
29 |
|
=over 4 |
30 |
|
|
31 |
|
=item --offset 42 |
32 |
|
|
33 |
|
start loading (all) databases at offset 42 |
34 |
|
|
35 |
|
=item --limit 100 |
36 |
|
|
37 |
|
limit loading to 100 records |
38 |
|
|
39 |
|
=item --clean |
40 |
|
|
41 |
|
remove database and Hyper Estraier index before indexing |
42 |
|
|
43 |
|
=item --config conf/config.yml |
44 |
|
|
45 |
|
path to YAML configuration file |
46 |
|
|
47 |
|
=back |
48 |
|
|
49 |
|
=cut |
50 |
|
|
51 |
|
my $offset; |
52 |
|
my $limit; |
53 |
|
|
54 |
|
my $clean = 0; |
55 |
|
my $config = 'conf/config.yml'; |
56 |
|
my $debug = 0; |
57 |
|
|
58 |
|
GetOptions( |
59 |
|
"limit=i" => \$limit, |
60 |
|
"offset=i" => \$offset, |
61 |
|
"clean" => \$clean, |
62 |
|
"config" => \$config, |
63 |
|
"debug" => \$debug, |
64 |
|
); |
65 |
|
|
66 |
|
$config = LoadFile($config); |
67 |
|
|
68 |
|
print "config = ",Dumper($config) if ($debug); |
69 |
|
|
70 |
die "no databases in config file!\n" unless ($config->{databases}); |
die "no databases in config file!\n" unless ($config->{databases}); |
71 |
|
|
81 |
|
|
82 |
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"); |
83 |
$est_config->{database} = $database; |
$est_config->{database} = $database; |
84 |
|
$est_config->{clean} = $clean; |
85 |
|
|
86 |
$log->info("using HyperEstraier URL $est_config->{masterurl}"); |
my $est = new WebPAC::Output::Estraier( %{ $est_config } ); |
|
|
|
|
my $est = new WebPAC::Output::Estraier( |
|
|
%{ $est_config }, |
|
|
); |
|
87 |
|
|
88 |
# |
# |
89 |
# now WebPAC::Store |
# now WebPAC::Store |
93 |
|
|
94 |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
95 |
|
|
96 |
$log->info("working on $database in $db_path"); |
if ($clean) { |
97 |
|
$log->info("creating new database $database in $db_path"); |
98 |
|
rmtree( $db_path ) || $log->warn("can't remove $db_path: $!"); |
99 |
|
} else { |
100 |
|
$log->info("working on $database in $db_path"); |
101 |
|
} |
102 |
|
|
103 |
my $db = new WebPAC::Store( |
my $db = new WebPAC::Store( |
104 |
path => $db_path, |
path => $db_path, |
105 |
database => $database, |
database => $database, |
106 |
debug => 1, |
debug => $debug, |
107 |
); |
); |
108 |
|
|
109 |
|
|
120 |
$log->info("database $database doesn't have inputs defined"); |
$log->info("database $database doesn't have inputs defined"); |
121 |
} |
} |
122 |
|
|
123 |
|
my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; |
124 |
|
|
125 |
foreach my $input (@inputs) { |
foreach my $input (@inputs) { |
126 |
|
|
127 |
my $type = lc($input->{type}); |
my $type = lc($input->{type}); |
128 |
|
|
129 |
die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis'); |
die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); |
130 |
|
|
131 |
my $lookup = new WebPAC::Lookup( |
my $lookup = new WebPAC::Lookup( |
132 |
lookup_file => $input->{lookup}, |
lookup_file => $input->{lookup}, |
133 |
); |
); |
134 |
|
|
135 |
$log->info("working on input $input->{path} [$input->{type}]"); |
my $input_module = $config->{webpac}->{inputs}->{$type}; |
136 |
|
|
137 |
|
$log->info("working on input $input->{path} [$input->{type}] using $input_module"); |
138 |
|
|
139 |
my $isis = new WebPAC::Input::ISIS( |
my $input_db = new WebPAC::Input( |
140 |
|
module => $input_module, |
141 |
code_page => $config->{webpac}->{webpac_encoding}, |
code_page => $config->{webpac}->{webpac_encoding}, |
142 |
limit_mfn => $input->{limit}, |
limit => $limit || $input->{limit}, |
143 |
|
offset => $offset, |
144 |
lookup => $lookup, |
lookup => $lookup, |
145 |
); |
); |
146 |
|
$log->logdie("can't create input using $input_module") unless ($input); |
147 |
|
|
148 |
my $maxmfn = $isis->open( |
my $maxmfn = $input_db->open( |
149 |
filename => $input->{path}, |
path => $input->{path}, |
150 |
code_page => $input->{encoding}, # database encoding |
code_page => $input->{encoding}, # database encoding |
151 |
); |
); |
152 |
|
|
172 |
); |
); |
173 |
} |
} |
174 |
|
|
175 |
for ( 0 ... $isis->size ) { |
foreach my $pos ( 0 ... $input_db->size ) { |
176 |
|
|
177 |
|
my $row = $input_db->fetch || next; |
178 |
|
|
179 |
my $row = $isis->fetch || next; |
my $mfn = $row->{'000'}->[0]; |
180 |
|
|
181 |
my $mfn = $row->{'000'}->[0] || die "can't find MFN"; |
if (! $mfn || $mfn !~ m#^\d+$#) { |
182 |
|
$log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); |
183 |
|
$mfn = $pos; |
184 |
|
push @{ $row->{'000'} }, $pos; |
185 |
|
} |
186 |
|
|
187 |
my $ds = $n->data_structure($row); |
my $ds = $n->data_structure($row); |
188 |
|
|
189 |
$est->add( |
$est->add( |
190 |
id => $input->{name} . "#" . $mfn, |
id => $input->{name} . "/" . $mfn, |
191 |
ds => $ds, |
ds => $ds, |
192 |
type => $config->{hyperestraier}->{type}, |
type => $config->{hyperestraier}->{type}, |
193 |
); |
); |