8 |
use HyperEstraier; |
use HyperEstraier; |
9 |
use Text::Iconv; |
use Text::Iconv; |
10 |
use Data::Dumper; |
use Data::Dumper; |
11 |
use LWP::Simple; |
use LWP; |
12 |
use URI::Escape; |
use URI::Escape; |
13 |
|
|
14 |
=head1 NAME |
=head1 NAME |
17 |
|
|
18 |
=head1 VERSION |
=head1 VERSION |
19 |
|
|
20 |
Version 0.02 |
Version 0.03 |
21 |
|
|
22 |
=cut |
=cut |
23 |
|
|
24 |
our $VERSION = '0.02'; |
our $VERSION = '0.03'; |
25 |
|
|
26 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
27 |
|
|
81 |
|
|
82 |
my $log = $self->_get_logger; |
my $log = $self->_get_logger; |
83 |
|
|
84 |
$log->debug("self: ", sub { Dumper($self) }); |
#$log->debug("self: ", sub { Dumper($self) }); |
85 |
|
|
86 |
foreach my $p (qw/masterurl user passwd database/) { |
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 |
my $url = $self->{masterurl} . '/node/' . $self->{database}; |
my $url = $self->{masterurl} . '/node/' . $self->{database}; |
|
$url =~ s#//#/#g; |
|
91 |
$self->{url} = $url; |
$self->{url} = $url; |
92 |
|
|
93 |
$log->info("opening Hyper Estraier index $self->{url}"); |
$log->info("opening Hyper Estraier index $self->{url}"); |
94 |
|
|
95 |
my @nodes = $self->est_master( action => 'nodelist' ); |
my $nodes = $self->est_master( action => 'nodelist' ); |
96 |
|
|
97 |
if (! grep(/$self->{database}/, @nodes)) { |
$log->debug("nodes found: $nodes"); |
98 |
|
|
99 |
|
if ($nodes !~ m/^$self->{database}\t/sm) { |
100 |
$log->info("creating index $url"); |
$log->info("creating index $url"); |
101 |
$self->est_master( |
$self->est_master( |
102 |
action => 'nodeadd', |
action => 'nodeadd', |
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). |
153 |
} |
} |
154 |
|
|
155 |
my $type = $args->{'type'}; |
my $type = $args->{'type'}; |
156 |
my $mfn = $args->{'id'}; |
my $id = $args->{'id'}; |
157 |
|
|
158 |
my $uri = "file:///$type/$database/$mfn"; |
my $uri = "file:///$type/$database/$id"; |
159 |
$log->debug("creating $uri"); |
$log->debug("creating $uri"); |
160 |
|
|
161 |
my $doc = HyperEstraier::Document->new; |
my $doc = HyperEstraier::Document->new; |
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 |
} |
} |
214 |
nodedel => [ qw/name/ ], |
nodedel => [ qw/name/ ], |
215 |
}; |
}; |
216 |
|
|
217 |
|
sub est_ua { |
218 |
|
my $self = shift; |
219 |
|
|
220 |
|
return $self->{_master_ua} if ($self->{_master_ua}); |
221 |
|
|
222 |
|
$self->{_master_ua} = LWP::UserAgent->new( ) || sub { |
223 |
|
my $log = $self->_get_logger; |
224 |
|
$log->logdie("can't create LWP::UserAgent: $!"); |
225 |
|
}; |
226 |
|
|
227 |
|
$self->{_master_ua}->credentials('localhost:1978','Super User', $self->{user} => $self->{passwd}); |
228 |
|
|
229 |
|
return $self->{_master_ua}; |
230 |
|
} |
231 |
|
|
232 |
sub est_master { |
sub est_master { |
233 |
my $self = shift; |
my $self = shift; |
234 |
my $args = {@_}; |
my $args = {@_}; |
249 |
|
|
250 |
$log->debug("calling $url"); |
$log->debug("calling $url"); |
251 |
|
|
252 |
my $tsv = get($url); |
my $res = $self->est_ua()->get($url); |
253 |
|
|
254 |
if (! $tsv) { |
if ($res->is_success) { |
255 |
$log->warn("unable to call $url"); |
#$log->debug( $res->content ); |
256 |
|
return split(/\n/, $res->content) if wantarray; |
257 |
|
return $res->content; |
258 |
|
} else { |
259 |
|
$log->warn("unable to call $url: " . $res->status_line); |
260 |
return; |
return; |
261 |
} |
} |
262 |
|
|
|
return split(/\n/, $tsv); |
|
263 |
} |
} |
264 |
|
|
265 |
=head1 AUTHOR |
=head1 AUTHOR |