8 |
use HyperEstraier; |
use HyperEstraier; |
9 |
use Text::Iconv; |
use Text::Iconv; |
10 |
use Data::Dumper; |
use Data::Dumper; |
11 |
|
use LWP; |
12 |
|
use URI::Escape; |
13 |
|
|
14 |
=head1 NAME |
=head1 NAME |
15 |
|
|
17 |
|
|
18 |
=head1 VERSION |
=head1 VERSION |
19 |
|
|
20 |
Version 0.01 |
Version 0.03 |
21 |
|
|
22 |
=cut |
=cut |
23 |
|
|
24 |
our $VERSION = '0.01'; |
our $VERSION = '0.03'; |
25 |
|
|
26 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
27 |
|
|
35 |
Connect to Hyper Estraier index using HTTP |
Connect to Hyper Estraier index using HTTP |
36 |
|
|
37 |
my $est = new WebPAC::Output::Estraier( |
my $est = new WebPAC::Output::Estraier( |
38 |
url => 'http://localhost:1978/node/webpac2', |
masterurl => 'http://localhost:1978/', |
39 |
user => 'admin', |
user => 'admin', |
40 |
passwd => 'admin', |
passwd => 'admin', |
41 |
database => 'demo', |
database => 'demo', |
46 |
|
|
47 |
=over 4 |
=over 4 |
48 |
|
|
49 |
=item url |
=item masterurl |
50 |
|
|
51 |
URI to C<estmaster> node |
URI to C<estmaster> node |
52 |
|
|
81 |
|
|
82 |
my $log = $self->_get_logger; |
my $log = $self->_get_logger; |
83 |
|
|
84 |
foreach my $p (qw/url user passwd/) { |
#$log->debug("self: ", sub { Dumper($self) }); |
85 |
|
|
86 |
|
foreach my $p (qw/masterurl user passwd database/) { |
87 |
$log->logdie("need $p") unless ($self->{$p}); |
$log->logdie("need $p") unless ($self->{$p}); |
88 |
} |
} |
89 |
|
|
90 |
$log->info("opening Hyper Estraier index $self->{'url'}"); |
my $url = $self->{masterurl} . '/node/' . $self->{database}; |
91 |
|
$self->{url} = $url; |
92 |
|
|
93 |
|
$log->info("opening Hyper Estraier index $self->{url}"); |
94 |
|
|
95 |
|
my $nodes = $self->est_master( action => 'nodelist' ); |
96 |
|
|
97 |
|
$log->debug("nodes found: $nodes"); |
98 |
|
|
99 |
$self->{'db'} = HyperEstraier::Node->new($self->{'url'}); |
if ($nodes !~ m/^$self->{database}\t/sm) { |
100 |
$self->{'db'}->set_auth($self->{'user'}, $self->{'passwd'}); |
$log->info("creating index $url"); |
101 |
|
$self->est_master( |
102 |
|
action => 'nodeadd', |
103 |
|
name => $self->{database}, |
104 |
|
label => "WebPAC $self->{database}", |
105 |
|
) || $log->logdie("can't create Hyper Estraier node $self->{database}"); |
106 |
|
} |
107 |
|
|
108 |
|
$self->{'db'} = HyperEstraier::Node->new($self->{url}); |
109 |
|
$self->{'db'}->set_auth($self->{'user'}, $self->{passwd}); |
110 |
|
|
111 |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
112 |
$log->info("using encoding $encoding"); |
$log->info("using encoding $encoding"); |
126 |
id => 42, |
id => 42, |
127 |
ds => $ds, |
ds => $ds, |
128 |
type => 'display', |
type => 'display', |
|
url_prefix => 'database name', |
|
129 |
text => 'optional text from which snippet is created', |
text => 'optional text from which snippet is created', |
130 |
); |
); |
131 |
|
|
132 |
This function will create entries in index using following URI format: |
This function will create entries in index using following URI format: |
133 |
|
|
134 |
C<file:///database%20name/000> |
C<file:///type/database%20name/000> |
135 |
|
|
136 |
Each tag in C<data_structure> with specified C<type> will create one |
Each tag in C<data_structure> with specified C<type> will create one |
137 |
attribute and corresponding hidden text (used for search). |
attribute and corresponding hidden text (used for search). |
193 |
} |
} |
194 |
|
|
195 |
$log->debug("adding ", sub { $doc->dump_draft } ); |
$log->debug("adding ", sub { $doc->dump_draft } ); |
196 |
$self->{'db'}->put_doc($doc) || $log->logdie("can't add document $uri to index"); |
$self->{'db'}->put_doc($doc) || $log->logdie("can't add document $uri to node " . $self->{url} . " status: " . $self->{db}->status()); |
197 |
|
|
198 |
return 1; |
return 1; |
199 |
} |
} |
200 |
|
|
201 |
|
=head2 est_master |
202 |
|
|
203 |
|
Issue administrative commands to C<estmaster> process and receive response |
204 |
|
as array of lines |
205 |
|
|
206 |
|
my $nodelist = $self->est_master( action => nodelist ); |
207 |
|
|
208 |
|
=cut |
209 |
|
|
210 |
|
my $estmaster_actions = { |
211 |
|
userdel => [ qw/name/ ], |
212 |
|
nodelist => [], |
213 |
|
nodeadd => [ qw/name label/ ], |
214 |
|
nodedel => [ qw/name/ ], |
215 |
|
}; |
216 |
|
|
217 |
|
sub est_master { |
218 |
|
my $self = shift; |
219 |
|
my $args = {@_}; |
220 |
|
my $log = $self->_get_logger; |
221 |
|
|
222 |
|
$log->debug(Dumper($args)); |
223 |
|
|
224 |
|
my $action = $args->{action} || $log->logconfess("no action specified"); |
225 |
|
|
226 |
|
$log->logdie("action '$action' isn't supported") unless ($estmaster_actions->{$action}); |
227 |
|
|
228 |
|
my $url = $self->{masterurl} . '/master?action=' . $action; |
229 |
|
|
230 |
|
foreach my $arg (@{ $estmaster_actions->{$action} }) { |
231 |
|
$log->logdie("missing parametar $arg for action $action") unless ($args->{$arg}); |
232 |
|
$url .= '&' . $arg . '=' . uri_escape( $args->{$arg} ); |
233 |
|
} |
234 |
|
|
235 |
|
$log->debug("calling $url"); |
236 |
|
|
237 |
|
if (! $self->{_master_ua}) { |
238 |
|
$self->{_master_ua} = LWP::UserAgent->new( ) || $log->logdie("can't create LWP::UserAgent: $!"); |
239 |
|
$self->{_master_ua}->credentials('localhost:1978','Super User', $self->{user} => $self->{passwd}); |
240 |
|
} |
241 |
|
|
242 |
|
my $res = $self->{_master_ua}->get($url); |
243 |
|
|
244 |
|
if ($res->is_success) { |
245 |
|
#$log->debug( $res->content ); |
246 |
|
return split(/\n/, $res->content) if wantarray; |
247 |
|
return $res->content; |
248 |
|
} else { |
249 |
|
$log->warn("unable to call $url: " . $res->status_line); |
250 |
|
#$log->debug(Dumper($res, $self->{'_master_ua'})); |
251 |
|
return; |
252 |
|
} |
253 |
|
|
254 |
|
} |
255 |
|
|
256 |
=head1 AUTHOR |
=head1 AUTHOR |
257 |
|
|
258 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |