--- trunk/lib/WebPAC/Output/Estraier.pm 2006/02/19 13:14:26 400 +++ trunk/lib/WebPAC/Output/Estraier.pm 2006/02/19 16:36:42 401 @@ -6,7 +6,7 @@ use base qw/WebPAC::Common/; use Search::Estraier; -use Text::Iconv; +use Encode qw/from_to/; use Data::Dumper; use LWP; use URI::Escape; @@ -17,11 +17,11 @@ =head1 VERSION -Version 0.09 +Version 0.10 =cut -our $VERSION = '0.09'; +our $VERSION = '0.10'; =head1 SYNOPSIS @@ -39,6 +39,7 @@ user => 'admin', passwd => 'admin', database => 'demo', + label => 'node label', encoding => 'iso-8859-2', clean => 1, ); @@ -63,6 +64,10 @@ name of database from which data comes +=item label + +label for node (optional) + =item encoding character encoding of C if it's differenet than C @@ -88,6 +93,8 @@ $log->logdie("need $p") unless ($self->{$p}); } + $self->{encoding} ||= 'ISO-8859-2'; + my $url = $self->{masterurl} . '/node/' . $self->{database}; $self->{url} = $url; @@ -103,11 +110,12 @@ $log->debug("nodes found: $nodes"); if ($nodes !~ m/^$self->{database}\t/sm) { - $log->warn("creating index $url"); + my $label = $self->{label} || 'WebPAC ' . $self->{database}; + $log->warn("creating index $url ($label)"); $self->master( action => 'nodeadd', name => $self->{database}, - label => "WebPAC $self->{database}", + label => $self->convert( $label ), ) || $log->logdie("can't create Hyper Estraier node $self->{database}"); } @@ -115,11 +123,7 @@ $self->{db}->set_url($self->{url}); $self->{db}->set_auth($self->{user}, $self->{passwd}); - 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 - $log->logdie("can't create conversion from $encoding to UTF-8"); + $log->info("using index $self->{url} with encoding $self->{encoding}"); $self ? return $self : return undef; } @@ -166,7 +170,7 @@ $log->debug("creating $uri"); my $doc = Search::Estraier::Document->new; - $doc->add_attr('@uri', $self->{'iconv'}->convert($uri) ); + $doc->add_attr('@uri', $self->convert($uri) ); $log->debug("ds = ", sub { Dumper($args->{'ds'}) } ); @@ -185,7 +189,7 @@ next if (! $vals); - $vals = $self->{'iconv'}->convert( $vals ) or + $vals = $self->convert( $vals ) or $log->logdie("can't convert '$vals' to UTF-8"); $doc->add_attr( $tag, $vals ); @@ -194,7 +198,7 @@ my $text = $args->{'text'}; if ( $text ) { - $text = $self->{'iconv'}->convert( $text ) or + $text = $self->convert( $text ) or $log->logdie("can't convert '$text' to UTF-8"); $doc->add_text( $text ); } @@ -392,6 +396,20 @@ return $self->{_master_ua}; } +=head2 convert + + my $utf8_string = $self->convert('string in codepage'); + +=cut + +sub convert { + my $self = shift; + + my $text = shift || return; + from_to($text, $self->{encoding}, 'UTF-8'); + return $text; +} + =head1 AUTHOR Dobrica Pavlinusic, C<< >>