use HyperEstraier;
use Text::Iconv;
use Data::Dumper;
+use LWP::Simple;
+use URI::Escape;
=head1 NAME
=head1 VERSION
-Version 0.01
+Version 0.02
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 SYNOPSIS
Connect to Hyper Estraier index using HTTP
my $est = new WebPAC::Output::Estraier(
- url => 'http://localhost:1978/node/webpac2',
+ masterurl => 'http://localhost:1978/',
user => 'admin',
passwd => 'admin',
database => 'demo',
=over 4
-=item url
+=item masterurl
URI to C<estmaster> node
my $log = $self->_get_logger;
- foreach my $p (qw/url user passwd/) {
+ $log->debug("self: ", sub { Dumper($self) });
+
+ foreach my $p (qw/masterurl user passwd database/) {
$log->logdie("need $p") unless ($self->{$p});
}
- $log->info("opening Hyper Estraier index $self->{'url'}");
+ my $url = $self->{masterurl} . '/node/' . $self->{database};
+ $url =~ s#//#/#g;
+ $self->{url} = $url;
+
+ $log->info("opening Hyper Estraier index $self->{url}");
- $self->{'db'} = HyperEstraier::Node->new($self->{'url'});
- $self->{'db'}->set_auth($self->{'user'}, $self->{'passwd'});
+ my @nodes = $self->est_master( action => 'nodelist' );
+
+ if (! grep(/$self->{database}/, @nodes)) {
+ $log->info("creating index $url");
+ $self->est_master(
+ action => 'nodeadd',
+ name => $self->{database},
+ label => "WebPAC $self->{database}",
+ ) || $log->logdie("can't create Hyper Estraier node $self->{database}");
+ }
+
+ $self->{'db'} = HyperEstraier::Node->new($self->{url});
+ $self->{'db'}->set_auth($self->{'user'}, $self->{passwd});
my $encoding = $self->{'encoding'} || 'ISO-8859-2';
$log->info("using encoding $encoding");
return 1;
}
+=head2 est_master
+
+Issue administrative commands to C<estmaster> process and receive response
+as array of lines
+
+ my $nodelist = $self->est_master( action => nodelist );
+
+=cut
+
+my $estmaster_actions = {
+ userdel => [ qw/name/ ],
+ nodelist => [],
+ nodeadd => [ qw/name label/ ],
+ nodedel => [ qw/name/ ],
+};
+
+sub est_master {
+ my $self = shift;
+ my $args = {@_};
+ my $log = $self->_get_logger;
+
+ $log->debug(Dumper($args));
+
+ my $action = $args->{action} || $log->logconfess("no action specified");
+
+ $log->logdie("action '$action' isn't supported") unless ($estmaster_actions->{$action});
+
+ my $url = $self->{masterurl} . '/master?action=' . $action;
+
+ foreach my $arg (@{ $estmaster_actions->{$action} }) {
+ $log->logdie("missing parametar $arg for action $action") unless ($args->{$arg});
+ $url .= '&' . $arg . '=' . uri_escape( $args->{$arg} );
+ }
+
+ $log->debug("calling $url");
+
+ my $tsv = get($url);
+
+ if (! $tsv) {
+ $log->warn("unable to call $url");
+ return;
+ }
+
+ return split(/\n/, $tsv);
+}
+
=head1 AUTHOR
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
use WebPAC::Store 0.03;
use WebPAC::Normalize::XML;
use WebPAC::Output::TT;
-use WebPAC::Output::Estraier;
+use WebPAC::Output::Estraier 0.02;
use YAML qw/LoadFile/;
+use LWP::Simple;
my $limit = shift @ARGV;
print "config = ",Dumper($config);
-my $type = lc($config->{input}->{type});
+die "no databases in config file!\n" unless ($config->{databases});
-die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
+while (my ($database, $db_config) = each %{ $config->{databases} }) {
-my $abs_path = abs_path($0);
-$abs_path =~ s#/[^/]*$#/#;
+ my $type = lc($db_config->{input}->{type});
-my $lookup = new WebPAC::Lookup(
- lookup_file => $config->{input}->{lookup},
-);
+ die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
+ my $abs_path = abs_path($0);
+ $abs_path =~ s#/[^/]*$#/#;
+ my $lookup = new WebPAC::Lookup(
+ lookup_file => $db_config->{input}->{lookup},
+ );
+
+ my $db_path = $config->{webpac}->{db_path} . '/' . $database;
+
+
+ my $log = $lookup->_get_logger;
+ $log->info("working on $database in $db_path");
+
+ my $isis = new WebPAC::Input::ISIS(
+ code_page => $config->{webpac}->{webpac_encoding},
+ limit_mfn => $db_config->{input}->{limit},
+ );
+
+ my $maxmfn = $isis->open(
+ filename => $db_config->{input}->{path},
+ code_page => $db_config->{input}->{encoding}, # database encoding
+ );
-my $isis = new WebPAC::Input::ISIS(
- code_page => $config->{webpac}->{webpac_encoding},
- limit_mfn => $config->{input}->{limit},
-);
+ my $path = './db/';
-my $maxmfn = $isis->open(
- filename => $config->{input}->{path},
- code_page => $config->{input}->{encoding}, # database encoding
-);
+ my $db = new WebPAC::Store(
+ path => $db_path,
+ );
-my $path = './db/';
+ my $n = new WebPAC::Normalize::XML(
+ # filter => { 'foo' => sub { shift } },
+ db => $db,
+ lookup_regex => $lookup->regex,
+ lookup => $lookup,
+ );
-my $db = new WebPAC::Store(
- path => $config->{webpac}->{db_path},
-);
+ $n->open(
+ tag => $db_config->{normalize}->{tag},
+ xml_file => $db_config->{normalize}->{path},
+ );
-my $n = new WebPAC::Normalize::XML(
-# filter => { 'foo' => sub { shift } },
- db => $db,
- lookup_regex => $lookup->regex,
- lookup => $lookup,
-);
+ my $out = new WebPAC::Output::TT(
+ include_path => $config->{webpac}->{template_path},
+ filters => { foo => sub { shift } },
+ );
-$n->open(
- tag => $config->{normalize}->{tag},
- xml_file => $config->{normalize}->{path},
-);
+ my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
+ $est_config->{database} = $database;
-my $out = new WebPAC::Output::TT(
- include_path => $config->{webpac}->{template_path},
- filters => { foo => sub { shift } },
-);
+ $log->info("using HyperEstraier URL $est_config->{url}");
-my $est = new WebPAC::Output::Estraier(
- %{ $config->{hyperestraier} }
-);
+ my $est = new WebPAC::Output::Estraier(
+ %{ $est_config },
+ );
-my $total_rows = 0;
+ my $total_rows = 0;
-for ( 0 ... $isis->size ) {
+ for ( 0 ... $isis->size ) {
- my $row = $isis->fetch || next;
+ my $row = $isis->fetch || next;
- my $mfn = $row->{'000'}->[0] || die "can't find MFN";
+ my $mfn = $row->{'000'}->[0] || die "can't find MFN";
- my $ds = $n->data_structure($row);
+ my $ds = $n->data_structure($row);
-# print STDERR Dumper($row, $ds);
+ # print STDERR Dumper($row, $ds);
-# my $html = $out->apply(
-# template => 'html_ffzg.tt',
-# data => $ds,
-# );
-#
-# # create test output
-#
-# my $file = sprintf('out/%02d.html', $mfn );
-# open(my $fh, '>', $file) or die "can't open $file: $!";
-# print $fh $html;
-# close($fh);
-#
-# $html =~ s#\s*[\n\r]+\s*##gs;
-#
-# print STDERR $html;
+ # my $html = $out->apply(
+ # template => 'html_ffzg.tt',
+ # data => $ds,
+ # );
+ #
+ # # create test output
+ #
+ # my $file = sprintf('out/%02d.html', $mfn );
+ # open(my $fh, '>', $file) or die "can't open $file: $!";
+ # print $fh $html;
+ # close($fh);
+ #
+ # $html =~ s#\s*[\n\r]+\s*##gs;
+ #
+ # print STDERR $html;
- $est->add(
- id => $mfn,
- ds => $ds,
- type => $config->{hyperestraier}->{type},
- );
+ $est->add(
+ id => $mfn,
+ ds => $ds,
+ type => $config->{hyperestraier}->{type},
+ );
- $total_rows++;
+ $total_rows++;
-};
+ };
-my $log = $lookup->_get_logger;
+ $log->info("$total_rows records indexed");
+}
-$log->info("$total_rows records indexed");