--- trunk/lib/WebPAC/Output/Estraier.pm 2005/12/16 16:00:24 262 +++ trunk/lib/WebPAC/Output/Estraier.pm 2006/01/08 22:21:19 374 @@ -5,7 +5,7 @@ use base qw/WebPAC::Common/; -use HyperEstraier; +use Search::Estraier; use Text::Iconv; use Data::Dumper; use LWP; @@ -17,11 +17,11 @@ =head1 VERSION -Version 0.05 +Version 0.09 =cut -our $VERSION = '0.05'; +our $VERSION = '0.09'; =head1 SYNOPSIS @@ -40,6 +40,7 @@ passwd => 'admin', database => 'demo', encoding => 'iso-8859-2', + clean => 1, ); Options are: @@ -76,8 +77,8 @@ sub new { my $class = shift; - my $self = {@_}; - bless($self, $class); + my $self = {@_}; + bless($self, $class); my $log = $self->_get_logger; @@ -90,14 +91,19 @@ my $url = $self->{masterurl} . '/node/' . $self->{database}; $self->{url} = $url; - $log->info("opening Hyper Estraier index $self->{url}"); + if ($self->{clean}) { + $log->debug("nodedel $self->{database}"); + $self->master( action => 'nodedel', name => $self->{database} ); + } else { + $log->debug("opening index $self->{url}"); + } my $nodes = $self->master( action => 'nodelist' ); $log->debug("nodes found: $nodes"); if ($nodes !~ m/^$self->{database}\t/sm) { - $log->info("creating index $url"); + $log->warn("creating index $url"); $self->master( action => 'nodeadd', name => $self->{database}, @@ -105,13 +111,14 @@ ) || $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}); + $self->{db} = Search::Estraier::Node->new( debug => $self->{debug} ); + $self->{db}->set_url($self->{url}); + $self->{db}->set_auth($self->{user}, $self->{passwd}); - my $encoding = $self->{'encoding'} || 'ISO-8859-2'; - $log->info("using encoding $encoding"); + my $encoding = $self->{encoding} || 'ISO-8859-2'; + $log->info("using index $self->{url} with encoding $encoding"); - $self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or + $self->{iconv} = new Text::Iconv($encoding, 'UTF-8') or $log->logdie("can't create conversion from $encoding to UTF-8"); $self ? return $self : return undef; @@ -158,7 +165,7 @@ my $uri = "file:///$type/$database/$id"; $log->debug("creating $uri"); - my $doc = HyperEstraier::Document->new; + my $doc = Search::Estraier::Document->new; $doc->add_attr('@uri', $self->{'iconv'}->convert($uri) ); $log->debug("ds = ", sub { Dumper($args->{'ds'}) } ); @@ -176,7 +183,7 @@ my $vals = join(" ", @{ $args->{'ds'}->{$tag}->{$type} }); - $log->logconfess("no values for $tag/$type") unless ($vals); + next if (! $vals); $vals = $self->{'iconv'}->convert( $vals ) or $log->logdie("can't convert '$vals' to UTF-8"); @@ -193,7 +200,7 @@ } $log->debug("adding ", sub { $doc->dump_draft } ); - $self->{'db'}->put_doc($doc) || $log->logdie("can't add document $uri to node " . $self->{url} . " status: " . $self->{db}->status()); + $self->{'db'}->put_doc($doc) || $log->warn("can't add document $uri with draft " . $doc->dump_draft . " to node " . $self->{url} . " status: " . $self->{db}->status()); return 1; } @@ -239,6 +246,7 @@ validate => 'master', rest_url => $self->{masterurl} . '/master?action=' . $action , action => $action, + %{ $args }, ); } @@ -262,9 +270,9 @@ $log->debug("got labels: ", join("|", @labels)); - @labels = grep(/^$args->{to}/, @labels); - - my (undef,$label) = split(/\t/, shift @labels); + @labels = grep(/^$args->{to}\t/, @labels); + my $label = shift @labels; + (undef,$label) = split(/\t/, $label) if ($label); if (! $label) { $log->warn("can't find label for $args->{to}, skipping link creaton"); @@ -322,10 +330,7 @@ $del = '&'; } - if ($url_args) { - $url_args =~ s#^\&#?# if ($url =~ m#\?#); - $url .= $url_args; - } + $url .= $url_args if ($url_args); $log->debug("calling $url");