11 |
use LWP; |
use LWP; |
12 |
use URI::Escape; |
use URI::Escape; |
13 |
use List::Util qw/first/; |
use List::Util qw/first/; |
14 |
|
use File::Path; |
15 |
|
|
16 |
$Estraier::DEBUG = 1; |
$Estraier::DEBUG = 1; |
17 |
|
|
22 |
|
|
23 |
=head1 VERSION |
=head1 VERSION |
24 |
|
|
25 |
Version 0.1 |
Version 0.2 |
26 |
|
|
27 |
=cut |
=cut |
28 |
|
|
29 |
our $VERSION = '0.1'; |
our $VERSION = '0.2'; |
30 |
|
|
31 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
32 |
|
|
93 |
$self->{label} ||= "WebPAC $self->{database}"; |
$self->{label} ||= "WebPAC $self->{database}"; |
94 |
|
|
95 |
my $path = 'casket'; |
my $path = 'casket'; |
96 |
|
$path =~ s!/+$!!; |
97 |
|
|
98 |
|
$path .= '/' . $self->{database}; |
99 |
|
|
100 |
|
$self->{path} = $path; |
101 |
|
|
102 |
|
$path .= '.tmp'; |
103 |
|
if (-e $path) { |
104 |
|
rmtree($path) || $log->logdie("can't remove old temporary directory $path: $!"); |
105 |
|
} |
106 |
|
mkpath($path) || $log->logdie("can't create new temporary directory $path: $!"); |
107 |
|
|
108 |
my $db = new Database(); |
my $db = new Database(); |
109 |
unless($db->open($path, Database::DBWRITER | Database::DBCREAT)) { |
unless($db->open($path, Database::DBWRITER | Database::DBCREAT)) { |
163 |
|
|
164 |
# store type and database name |
# store type and database name |
165 |
$doc->add_attr('_database', $database ); |
$doc->add_attr('_database', $database ); |
166 |
|
$doc->add_hidden_text('_database:' . $database); |
167 |
$doc->add_attr('_type', $type ); |
$doc->add_attr('_type', $type ); |
168 |
|
|
169 |
$log->debug("ds = ", sub { Dumper($args->{'ds'}) } ); |
$log->debug("ds = ", sub { Dumper($args->{'ds'}) } ); |
179 |
|
|
180 |
foreach my $tag (@tags) { |
foreach my $tag (@tags) { |
181 |
|
|
182 |
|
$log->debug("$tag :: $type == ",Dumper( $args->{'ds'}->{$tag}->{$type} ) ); |
183 |
|
|
184 |
my $vals = join(" ", @{ $args->{'ds'}->{$tag}->{$type} }); |
my $vals = join(" ", @{ $args->{'ds'}->{$tag}->{$type} }); |
185 |
|
|
186 |
next if (! $vals); |
next if (! $vals); |
202 |
} |
} |
203 |
|
|
204 |
$log->debug("adding ", sub { $doc->dump_draft } ); |
$log->debug("adding ", sub { $doc->dump_draft } ); |
205 |
$self->{'db'}->put_doc($doc, Database::PDCLEAN) || $log->warn("can't add document $uri with draft " . $doc->dump_draft . " to node " . $self->{path} . " status: " . $self->{db}->status()); |
$self->{'db'}->put_doc($doc, Database::PDCLEAN) || $log->warn("can't add document $uri with draft " . $doc->dump_draft . " to node " . $self->{path} . " status: " . $self->{db}->error()); |
206 |
|
|
207 |
return 1; |
return 1; |
208 |
} |
} |
254 |
} |
} |
255 |
|
|
256 |
|
|
257 |
|
=head2 finish |
258 |
|
|
259 |
|
Close index and rename of to final path |
260 |
|
|
261 |
|
$est->finish; |
262 |
|
|
263 |
|
=cut |
264 |
|
|
265 |
|
sub finish { |
266 |
|
my $self = shift; |
267 |
|
|
268 |
|
my $log = $self->_get_logger; |
269 |
|
$log->info("closing Hyper Estraier index make it current..."); |
270 |
|
|
271 |
|
$self->{db}->close || $log->logdie("can't close index"); |
272 |
|
|
273 |
|
my $path = $self->{path} || $log->logdie("no path?"); |
274 |
|
|
275 |
|
if (-e $path) { |
276 |
|
$log->warn("removing old $path"); |
277 |
|
rmtree($path) || $log->logdie("can't remove old temporary directory $path: $!"); |
278 |
|
} |
279 |
|
|
280 |
|
rename $path . '.tmp', $path || $log->logdie("can't rename ${path}.tmp -> $path: $!"); |
281 |
|
|
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
=head2 convert |
=head2 convert |
286 |
|
|
287 |
my $utf8_string = $self->convert('string in codepage'); |
my $utf8_string = $self->convert('string in codepage'); |