6 use File::Temp qw/tempdir/;
10 use WebPAC::Common 0.02;
12 use WebPAC::Input::ISIS;
13 use WebPAC::Store 0.03;
14 use WebPAC::Normalize::XML;
15 use WebPAC::Output::TT;
16 use WebPAC::Output::Estraier 0.05;
17 use YAML qw/LoadFile/;
20 my $limit = shift @ARGV;
22 my $config = LoadFile('conf/config.yml');
24 print "config = ",Dumper($config);
26 die "no databases in config file!\n" unless ($config->{databases});
30 while (my ($database, $db_config) = each %{ $config->{databases} }) {
32 my $log = _new WebPAC::Common()->_get_logger();
35 # open Hyper Estraier database
38 my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
39 $est_config->{database} = $database;
41 $log->info("using HyperEstraier URL $est_config->{masterurl}");
43 my $est = new WebPAC::Output::Estraier(
50 my $abs_path = abs_path($0);
51 $abs_path =~ s#/[^/]*$#/#;
53 my $db_path = $config->{webpac}->{db_path} . '/' . $database;
55 $log->info("working on $database in $db_path");
57 my $db = new WebPAC::Store(
59 database => $database,
65 # now, iterate through input formats
69 if (ref($db_config->{input}) eq 'ARRAY') {
70 @inputs = @{ $db_config->{input} };
71 } elsif ($db_config->{input}) {
72 push @inputs, $db_config->{input};
74 $log->info("database $database doesn't have inputs defined");
77 foreach my $input (@inputs) {
81 my $type = lc($input->{type});
83 die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
85 my $lookup = new WebPAC::Lookup(
86 lookup_file => $input->{lookup},
89 $log->info("working on input $input->{path} [$input->{type}]");
91 my $isis = new WebPAC::Input::ISIS(
92 code_page => $config->{webpac}->{webpac_encoding},
93 limit_mfn => $input->{limit},
97 my $maxmfn = $isis->open(
98 filename => $input->{path},
99 code_page => $input->{encoding}, # database encoding
102 my $n = new WebPAC::Normalize::XML(
103 # filter => { 'foo' => sub { shift } },
105 lookup_regex => $lookup->regex,
107 prefix => $input->{name},
111 tag => $input->{normalize}->{tag},
112 xml_file => $input->{normalize}->{path},
115 for ( 0 ... $isis->size ) {
117 my $row = $isis->fetch || next;
119 my $mfn = $row->{'000'}->[0] || die "can't find MFN";
121 my $ds = $n->data_structure($row);
124 id => $input->{name} . "#" . $mfn,
126 type => $config->{hyperestraier}->{type},
134 $log->info("$total_rows records indexed");
137 # add Hyper Estraier links to other databases
139 if (ref($db_config->{links}) eq 'ARRAY') {
140 foreach my $link (@{ $db_config->{links} }) {
141 $log->info("adding link $database -> $link->{to} [$link->{credit}]");
145 credit => $link->{credit},