r466@llin: dpavlin | 2006-02-19 17:45:26 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 19 Feb 2006 16:36:42 +0000 (16:36 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 19 Feb 2006 16:36:42 +0000 (16:36 +0000)
 create label from database name, move from Text::Iconv to Encode

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@401 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Output/Estraier.pm
run.pl

index 2cc2713..4d08bd0 100644 (file)
@@ -6,7 +6,7 @@ use strict;
 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 @@ WebPAC::Output::Estraier - Create Hyper Estraier full text index
 
 =head1 VERSION
 
-Version 0.09
+Version 0.10
 
 =cut
 
-our $VERSION = '0.09';
+our $VERSION = '0.10';
 
 =head1 SYNOPSIS
 
@@ -39,6 +39,7 @@ Connect to Hyper Estraier index using HTTP
        user => 'admin',
        passwd => 'admin',
        database => 'demo',
+       label => 'node label',
        encoding => 'iso-8859-2',
        clean => 1,
  );
@@ -63,6 +64,10 @@ password for user
 
 name of database from which data comes
 
+=item label
+
+label for node (optional)
+
 =item encoding
 
 character encoding of C<data_structure> if it's differenet than C<ISO-8859-2>
@@ -88,6 +93,8 @@ sub new {
                $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 @@ sub new {
        $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 @@ sub new {
        $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 @@ sub add {
        $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 @@ sub add {
 
                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 @@ sub add {
 
        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 @@ sub est_ua {
        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<< <dpavlin@rot13.org> >>
diff --git a/run.pl b/run.pl
index c0820af..b4e7ae5 100755 (executable)
--- a/run.pl
+++ b/run.pl
@@ -13,7 +13,7 @@ use WebPAC::Input 0.03;
 use WebPAC::Store 0.03;
 use WebPAC::Normalize::XML;
 use WebPAC::Output::TT;
-use WebPAC::Output::Estraier 0.08;
+use WebPAC::Output::Estraier '0.10';
 use YAML qw/LoadFile/;
 use Getopt::Long;
 use File::Path;
@@ -92,6 +92,7 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) {
        my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
        $est_config->{database} = $database;
        $est_config->{clean} = $clean;
+       $est_config->{label} = $db_config->{name};
 
        my $est = new WebPAC::Output::Estraier( %{ $est_config } );