7 |
use Data::Dumper; |
use Data::Dumper; |
8 |
use lib './lib'; |
use lib './lib'; |
9 |
|
|
10 |
|
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::DB; |
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; |
use WebPAC::Output::Estraier 0.08; |
17 |
|
use YAML qw/LoadFile/; |
18 |
|
use Getopt::Long; |
19 |
|
use File::Path; |
20 |
|
use Time::HiRes qw/time/; |
21 |
|
|
22 |
my $limit = shift @ARGV; |
=head1 NAME |
23 |
|
|
24 |
my $abs_path = abs_path($0); |
run.pl - start WebPAC indexing |
|
$abs_path =~ s#/[^/]*$#/#; |
|
25 |
|
|
26 |
my $isis_file = '/data/isis_data/ps/LIBRI/LIBRI'; |
B<this command will probably go away. Don't get used to it!> |
27 |
|
|
28 |
my $lookup = new WebPAC::Lookup( |
Options: |
|
lookup_file => "$abs_path/conf/lookup/isis.pm", |
|
|
); |
|
29 |
|
|
30 |
my $isis = new WebPAC::Input::ISIS( |
=over 4 |
|
code_page => 'ISO-8859-2', # application encoding |
|
|
limit_mfn => $limit, |
|
|
); |
|
31 |
|
|
32 |
my $maxmfn = $isis->open( |
=item --offset 42 |
|
filename => $isis_file, |
|
|
code_page => '852', # database encoding |
|
|
); |
|
33 |
|
|
34 |
my $path = './db/'; |
start loading (all) databases at offset 42 |
35 |
|
|
36 |
my $db = new WebPAC::DB( |
=item --limit 100 |
|
path => $path, |
|
|
); |
|
37 |
|
|
38 |
my $n = new WebPAC::Normalize::XML( |
limit loading to 100 records |
|
# filter => { 'foo' => sub { shift } }, |
|
|
db => $db, |
|
|
lookup_regex => $lookup->regex, |
|
|
lookup => $lookup, |
|
|
); |
|
39 |
|
|
40 |
$n->open( |
=item --clean |
|
tag => 'isis', |
|
|
xml_file => "$abs_path/conf/normalize/isis_ffzg.xml", |
|
|
); |
|
41 |
|
|
42 |
my $out = new WebPAC::Output::TT( |
remove database and Hyper Estraier index before indexing |
43 |
include_path => "$abs_path/conf/output/tt", |
|
44 |
filters => { foo => sub { shift } }, |
=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 $est = new WebPAC::Output::Estraier( |
my $offset; |
57 |
url => 'http://localhost:1978/node/webpac2', |
my $limit; |
58 |
user => 'admin', |
|
59 |
passwd => 'admin', |
my $clean = 0; |
60 |
database => 'ps', |
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}); |
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} }) { |
83 |
|
|
84 |
for ( 0 ... $isis->size ) { |
next if ($one_db_name && $database !~ m/$one_db_name/i); |
85 |
|
|
86 |
my $row = $isis->fetch || next; |
my $log = _new WebPAC::Common()->_get_logger(); |
87 |
|
|
88 |
my $mfn = $row->{'000'}->[0] || die "can't find MFN"; |
# |
89 |
|
# open Hyper Estraier database |
90 |
|
# |
91 |
|
|
92 |
my $ds = $n->data_structure($row); |
my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration"); |
93 |
|
$est_config->{database} = $database; |
94 |
|
$est_config->{clean} = $clean; |
95 |
|
|
96 |
# print STDERR Dumper($row, $ds); |
my $est = new WebPAC::Output::Estraier( %{ $est_config } ); |
97 |
|
|
98 |
# my $html = $out->apply( |
# |
99 |
# template => 'html_ffzg.tt', |
# now WebPAC::Store |
100 |
# data => $ds, |
# |
101 |
# ); |
my $abs_path = abs_path($0); |
102 |
# |
$abs_path =~ s#/[^/]*$#/#; |
103 |
# # create test output |
|
104 |
# |
my $db_path = $config->{webpac}->{db_path} . '/' . $database; |
105 |
# my $file = sprintf('out/%02d.html', $mfn ); |
|
106 |
# open(my $fh, '>', $file) or die "can't open $file: $!"; |
if ($clean) { |
107 |
# print $fh $html; |
$log->info("creating new database $database in $db_path"); |
108 |
# close($fh); |
rmtree( $db_path ) || $log->warn("can't remove $db_path: $!"); |
109 |
# |
} else { |
110 |
# $html =~ s#\s*[\n\r]+\s*##gs; |
$log->info("working on $database in $db_path"); |
111 |
# |
} |
112 |
# print STDERR $html; |
|
113 |
|
my $db = new WebPAC::Store( |
114 |
$est->add( |
path => $db_path, |
115 |
id => $mfn, |
database => $database, |
116 |
ds => $ds, |
debug => $debug, |
|
type => 'search', |
|
117 |
); |
); |
118 |
|
|
|
$total_rows++; |
|
119 |
|
|
120 |
}; |
# |
121 |
|
# now, iterate through input formats |
122 |
|
# |
123 |
|
|
124 |
|
my @inputs; |
125 |
|
if (ref($db_config->{input}) eq 'ARRAY') { |
126 |
|
@inputs = @{ $db_config->{input} }; |
127 |
|
} elsif ($db_config->{input}) { |
128 |
|
push @inputs, $db_config->{input}; |
129 |
|
} else { |
130 |
|
$log->info("database $database doesn't have inputs defined"); |
131 |
|
} |
132 |
|
|
133 |
|
my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; |
134 |
|
|
135 |
|
foreach my $input (@inputs) { |
136 |
|
|
137 |
|
my $type = lc($input->{type}); |
138 |
|
|
139 |
|
die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); |
140 |
|
|
141 |
|
my $lookup = new WebPAC::Lookup( |
142 |
|
lookup_file => $input->{lookup}, |
143 |
|
); |
144 |
|
|
145 |
|
my $input_module = $config->{webpac}->{inputs}->{$type}; |
146 |
|
|
147 |
|
$log->info("working on input $input->{path} [$input->{type}] using $input_module"); |
148 |
|
|
149 |
|
my $input_db = new WebPAC::Input( |
150 |
|
module => $input_module, |
151 |
|
code_page => $config->{webpac}->{webpac_encoding}, |
152 |
|
limit => $limit || $input->{limit}, |
153 |
|
offset => $offset, |
154 |
|
lookup => $lookup, |
155 |
|
); |
156 |
|
$log->logdie("can't create input using $input_module") unless ($input); |
157 |
|
|
158 |
|
my $maxmfn = $input_db->open( |
159 |
|
path => $input->{path}, |
160 |
|
code_page => $input->{encoding}, # database encoding |
161 |
|
); |
162 |
|
|
163 |
|
my $n = new WebPAC::Normalize::XML( |
164 |
|
# filter => { 'foo' => sub { shift } }, |
165 |
|
db => $db, |
166 |
|
lookup_regex => $lookup->regex, |
167 |
|
lookup => $lookup, |
168 |
|
prefix => $input->{name}, |
169 |
|
); |
170 |
|
|
171 |
|
my $normalize_path = $input->{normalize}->{path}; |
172 |
|
|
173 |
|
if ($normalize_path =~ m/\.xml$/i) { |
174 |
|
$n->open( |
175 |
|
tag => $input->{normalize}->{tag}, |
176 |
|
xml_file => $input->{normalize}->{path}, |
177 |
|
); |
178 |
|
} elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) { |
179 |
|
$n->open_yaml( |
180 |
|
path => $normalize_path, |
181 |
|
tag => $input->{normalize}->{tag}, |
182 |
|
); |
183 |
|
} |
184 |
|
|
185 |
|
foreach my $pos ( 0 ... $input_db->size ) { |
186 |
|
|
187 |
|
my $row = $input_db->fetch || next; |
188 |
|
|
189 |
|
my $mfn = $row->{'000'}->[0]; |
190 |
|
|
191 |
|
if (! $mfn || $mfn !~ m#^\d+$#) { |
192 |
|
$log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); |
193 |
|
$mfn = $pos; |
194 |
|
push @{ $row->{'000'} }, $pos; |
195 |
|
} |
196 |
|
|
197 |
|
my $ds = $n->data_structure($row); |
198 |
|
|
199 |
|
$est->add( |
200 |
|
id => $input->{name} . "/" . $mfn, |
201 |
|
ds => $ds, |
202 |
|
type => $config->{hyperestraier}->{type}, |
203 |
|
); |
204 |
|
|
205 |
|
$total_rows++; |
206 |
|
} |
207 |
|
|
208 |
|
}; |
209 |
|
|
210 |
|
my $dt = time() - $start_t; |
211 |
|
$log->info("$total_rows records indexed in " . |
212 |
|
sprintf("%.2f sec [%.2f rec/sec]", |
213 |
|
$dt, ($total_rows / $dt) |
214 |
|
) |
215 |
|
); |
216 |
|
|
217 |
|
# |
218 |
|
# add Hyper Estraier links to other databases |
219 |
|
# |
220 |
|
if (ref($db_config->{links}) eq 'ARRAY') { |
221 |
|
foreach my $link (@{ $db_config->{links} }) { |
222 |
|
$log->info("adding link $database -> $link->{to} [$link->{credit}]"); |
223 |
|
$est->add_link( |
224 |
|
from => $database, |
225 |
|
to => $link->{to}, |
226 |
|
credit => $link->{credit}, |
227 |
|
); |
228 |
|
} |
229 |
|
} |
230 |
|
|
231 |
my $log = $lookup->_get_logger; |
} |
232 |
|
|
|
$log->info("$total_rows records indexed"); |
|