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; |
17 |
|
|
18 |
=head1 VERSION |
=head1 VERSION |
19 |
|
|
20 |
Version 0.05 |
Version 0.09 |
21 |
|
|
22 |
=cut |
=cut |
23 |
|
|
24 |
our $VERSION = '0.05'; |
our $VERSION = '0.09'; |
25 |
|
|
26 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
27 |
|
|
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: |
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 |
|
|
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}, |
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; |
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'}) } ); |
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 |
} |
} |
246 |
validate => 'master', |
validate => 'master', |
247 |
rest_url => $self->{masterurl} . '/master?action=' . $action , |
rest_url => $self->{masterurl} . '/master?action=' . $action , |
248 |
action => $action, |
action => $action, |
249 |
|
%{ $args }, |
250 |
); |
); |
251 |
} |
} |
252 |
|
|
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"); |
330 |
$del = '&'; |
$del = '&'; |
331 |
} |
} |
332 |
|
|
333 |
if ($url_args) { |
$url .= $url_args if ($url_args); |
|
$url_args =~ s#^\&#?# if ($url =~ m#\?#); |
|
|
$url .= $url_args; |
|
|
} |
|
334 |
|
|
335 |
$log->debug("calling $url"); |
$log->debug("calling $url"); |
336 |
|
|