/[webpac2]/trunk/lib/WebPAC/Output/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Output/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 291 by dpavlin, Sun Dec 18 23:34:24 2005 UTC revision 345 by dpavlin, Sat Jan 7 02:21:18 2006 UTC
# Line 5  use strict; Line 5  use strict;
5    
6  use base qw/WebPAC::Common/;  use base qw/WebPAC::Common/;
7    
8  use HyperEstraier;  use Search::Estraier;
9  use Text::Iconv;  use Text::Iconv;
10  use Data::Dumper;  use Data::Dumper;
11  use LWP;  use LWP;
# Line 17  WebPAC::Output::Estraier - Create Hyper Line 17  WebPAC::Output::Estraier - Create Hyper
17    
18  =head1 VERSION  =head1 VERSION
19    
20  Version 0.07  Version 0.09
21    
22  =cut  =cut
23    
24  our $VERSION = '0.07';  our $VERSION = '0.09';
25    
26  =head1 SYNOPSIS  =head1 SYNOPSIS
27    
# Line 40  Connect to Hyper Estraier index using HT Line 40  Connect to Hyper Estraier index using HT
40          passwd => 'admin',          passwd => 'admin',
41          database => 'demo',          database => 'demo',
42          encoding => 'iso-8859-2',          encoding => 'iso-8859-2',
43            clean => 1,
44   );   );
45    
46  Options are:  Options are:
# Line 76  Name of database will be used to form UR Line 77  Name of database will be used to form UR
77    
78  sub new {  sub new {
79          my $class = shift;          my $class = shift;
80          my $self = {@_};          my $self = {@_};
81          bless($self, $class);          bless($self, $class);
82    
83          my $log = $self->_get_logger;          my $log = $self->_get_logger;
84    
# Line 90  sub new { Line 91  sub new {
91          my $url = $self->{masterurl} . '/node/' . $self->{database};          my $url = $self->{masterurl} . '/node/' . $self->{database};
92          $self->{url} = $url;          $self->{url} = $url;
93    
94          $log->info("opening Hyper Estraier index $self->{url}");          if ($self->{clean}) {
95                    $log->debug("nodedel $self->{database}");
96                    $self->master( action => 'nodedel', name => $self->{database} );
97            } else {
98                    $log->debug("opening index $self->{url}");
99            }
100    
101          my $nodes = $self->master( action => 'nodelist' );          my $nodes = $self->master( action => 'nodelist' );
102    
103          $log->debug("nodes found: $nodes");          $log->debug("nodes found: $nodes");
104    
105          if ($nodes !~ m/^$self->{database}\t/sm) {          if ($nodes !~ m/^$self->{database}\t/sm) {
106                  $log->info("creating index $url");                  $log->warn("creating index $url");
107                  $self->master(                  $self->master(
108                          action => 'nodeadd',                          action => 'nodeadd',
109                          name => $self->{database},                          name => $self->{database},
# Line 105  sub new { Line 111  sub new {
111                  ) || $log->logdie("can't create Hyper Estraier node $self->{database}");                  ) || $log->logdie("can't create Hyper Estraier node $self->{database}");
112          }          }
113    
114          $self->{'db'} = HyperEstraier::Node->new($self->{url});          $self->{db} = Search::Estraier::Node->new( debug => $self->{debug} );
115          $self->{'db'}->set_auth($self->{'user'}, $self->{passwd});          $self->{db}->set_url($self->{url});
116            $self->{db}->set_auth($self->{user}, $self->{passwd});
117    
118          my $encoding = $self->{'encoding'} || 'ISO-8859-2';          my $encoding = $self->{encoding} || 'ISO-8859-2';
119          $log->info("using encoding $encoding");          $log->info("using index $self->{url} with encoding $encoding");
120    
121          $self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or          $self->{iconv} = new Text::Iconv($encoding, 'UTF-8') or
122                  $log->logdie("can't create conversion from $encoding to UTF-8");                  $log->logdie("can't create conversion from $encoding to UTF-8");
123    
124          $self ? return $self : return undef;          $self ? return $self : return undef;
# Line 158  sub add { Line 165  sub add {
165          my $uri = "file:///$type/$database/$id";          my $uri = "file:///$type/$database/$id";
166          $log->debug("creating $uri");          $log->debug("creating $uri");
167    
168          my $doc = HyperEstraier::Document->new;          my $doc = Search::Estraier::Document->new;
169          $doc->add_attr('@uri', $self->{'iconv'}->convert($uri) );          $doc->add_attr('@uri', $self->{'iconv'}->convert($uri) );
170    
171          $log->debug("ds = ", sub { Dumper($args->{'ds'}) } );          $log->debug("ds = ", sub { Dumper($args->{'ds'}) } );
# Line 193  sub add { Line 200  sub add {
200          }          }
201    
202          $log->debug("adding ", sub { $doc->dump_draft } );          $log->debug("adding ", sub { $doc->dump_draft } );
203          $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());
204    
205          return 1;          return 1;
206  }  }
# Line 263  sub add_link { Line 270  sub add_link {
270    
271          $log->debug("got labels: ", join("|", @labels));          $log->debug("got labels: ", join("|", @labels));
272    
273          @labels = grep(/^$args->{to}/, @labels);          @labels = grep(/^$args->{to}\t/, @labels);
274            my $label = shift @labels;
275          my (undef,$label) = split(/\t/, shift @labels);          (undef,$label) = split(/\t/, $label) if ($label);
276    
277          if (! $label) {          if (! $label) {
278                  $log->warn("can't find label for $args->{to}, skipping link creaton");                  $log->warn("can't find label for $args->{to}, skipping link creaton");

Legend:
Removed from v.291  
changed lines
  Added in v.345

  ViewVC Help
Powered by ViewVC 1.1.26