92 |
|
|
93 |
my $index_dir = $self->{'index_dir'}; |
my $index_dir = $self->{'index_dir'}; |
94 |
|
|
95 |
|
my $cwd; |
96 |
|
chomp($cwd = `pwd`); |
97 |
|
$self->{'cwd'} = $cwd || carp "can't get cwd!"; |
98 |
|
|
99 |
if ($index_dir !~ m#^/#) { |
if ($index_dir !~ m#^/#) { |
|
chomp(my $cwd = `pwd`); |
|
100 |
$index_dir = "$cwd/$index_dir"; |
$index_dir = "$cwd/$index_dir"; |
101 |
print STDERR "## full path to index_dir: $index_dir\n" if ($self->{'debug'}); |
print STDERR "## full path to index_dir: $index_dir\n" if ($self->{'debug'}); |
102 |
$self->{'index_dir'} = $index_dir; |
$self->{'index_dir'} = $index_dir; |
146 |
confess $self->{'search'}," binary is not SWISH++" unless ($s =~ m/^SWISH\+\+/); |
confess $self->{'search'}," binary is not SWISH++" unless ($s =~ m/^SWISH\+\+/); |
147 |
|
|
148 |
if ($i eq $s) { |
if ($i eq $s) { |
149 |
|
$i =~ s/^SWISH\+\+\s+// || confess "can't strip SWISH++ from version"; |
150 |
$self->{'version'} = $i; |
$self->{'version'} = $i; |
151 |
return 1; |
return 1; |
152 |
} else { |
} else { |
221 |
|
|
222 |
my $query = shift || return; |
my $query = shift || return; |
223 |
|
|
224 |
$self->_close_index; |
$self->finish_update; |
225 |
|
|
226 |
my @results; |
my @results; |
227 |
|
|
265 |
sub finish_update { |
sub finish_update { |
266 |
my $self = shift; |
my $self = shift; |
267 |
|
|
268 |
|
print STDERR "## finish_update\n" if ($self->{'debug'}); |
269 |
|
|
270 |
$self->_close_index; |
$self->_close_index; |
271 |
} |
} |
272 |
|
|
295 |
sub _init_indexer { |
sub _init_indexer { |
296 |
my $self = shift; |
my $self = shift; |
297 |
|
|
298 |
$self->{'tmp_dir'} = tempdir( CLEANUP => 1 ) || confess "can't create temporary directory: $!"; |
return if ($self->{'_index_fh'}); |
299 |
|
|
300 |
chdir $self->{'tmp_dir'} || confess "can't chdir to ".$self->{'tmp_dir'}.": $!"; |
my $tmp_dir = tempdir( CLEANUP => 1 ) || confess "can't create temporary directory: $!"; |
301 |
|
$self->{'tmp_dir'} = $tmp_dir; |
302 |
|
|
303 |
|
chdir $tmp_dir || confess "can't chdir to ".$tmp_dir.": $!"; |
304 |
|
|
305 |
|
print STDERR "## tmp_dir: $tmp_dir" if ($self->{'debug'}); |
306 |
|
|
307 |
my $opt = "-v " . ($self->{'debug'} || '0'); |
my $opt = "-v " . ($self->{'debug'} || '0'); |
308 |
|
|
315 |
|
|
316 |
my $open_cmd = '| '.$self->{'index'}.' '.$opt.' -e "html:*" -i '.$self->{'index_dir'}.'/index -'; |
my $open_cmd = '| '.$self->{'index'}.' '.$opt.' -e "html:*" -i '.$self->{'index_dir'}.'/index -'; |
317 |
|
|
318 |
print STDERR "## open index $open_cmd\n" if ($self->{'index'}); |
print STDERR "## init_indexer: $open_cmd\n" if ($self->{'debug'}); |
319 |
|
|
320 |
open($self->{'index_fh'}, $open_cmd) || confess "can't start index with $open_cmd: $!"; |
open($self->{'_index_fh'}, $open_cmd) || confess "can't start index with $open_cmd: $!"; |
321 |
|
|
322 |
|
chdir $self->{'cwd'} || confess "can't chdir to ".$self->{'cwd'}.": $!"; |
323 |
|
|
324 |
return $self->{'index_fh'}; |
return $self->{'_index_fh'}; |
325 |
} |
} |
326 |
|
|
327 |
=head2 _create_doc |
=head2 _create_doc |
348 |
my $arg = {@_}; |
my $arg = {@_}; |
349 |
|
|
350 |
# open indexer if needed |
# open indexer if needed |
351 |
$self->{'index_fh'} ||= $self->_init_indexer; |
$self->_init_indexer; |
352 |
|
|
353 |
my $path = $self->{'tmp_dir'} || confess "no tmp_dir?"; |
my $path = $self->{'tmp_dir'} || confess "no tmp_dir?"; |
354 |
|
$path .= '/' . $arg->{'path'}; |
355 |
|
|
356 |
|
print STDERR "## _create_doc: $path\n" if ($self->{'debug'}); |
357 |
|
|
358 |
open(TMP, '>', $arg->{'path'}) || die "can't create temp file ".$arg->{'path'}.": $!"; |
open(TMP, '>', $path) || die "can't create temp file $path: $!"; |
359 |
|
|
360 |
print TMP '<html><head>'; |
print TMP '<html><head>'; |
361 |
|
|
378 |
|
|
379 |
close(TMP) || confess "can't close tmp file ".$arg->{'path'}.": $!"; |
close(TMP) || confess "can't close tmp file ".$arg->{'path'}.": $!"; |
380 |
|
|
381 |
print { $self->{'index_fh'} } $arg->{'path'}."\n"; |
print { $self->{'_index_fh'} } $arg->{'path'}."\n"; |
382 |
} |
} |
383 |
|
|
384 |
=head2 _close_index |
=head2 _close_index |
394 |
sub _close_index { |
sub _close_index { |
395 |
my $self = shift; |
my $self = shift; |
396 |
|
|
397 |
return unless ($self->{'index_fh'}); |
return unless ($self->{'_index_fh'}); |
398 |
|
|
399 |
print STDERR "## close index\n" if ($self->{'debug'}); |
print STDERR "## close index\n" if ($self->{'debug'}); |
400 |
|
|
401 |
close($self->{'index_fh'}); |
close($self->{'_index_fh'}); |
402 |
undef $self->{'index_fh'}; |
undef $self->{'_index_fh'}; |
403 |
} |
} |
404 |
|
|
405 |
1; |
1; |