4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
7 |
our $VERSION = '0.05_1'; |
our $VERSION = '0.06_1'; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
1389 |
); |
); |
1390 |
return if ($rv != 200); |
return if ($rv != 200); |
1391 |
|
|
1392 |
my (@docs, $hints); |
my @records = split /--------\[.*?\]--------(?::END)?\r?\n/, $resbody; |
1393 |
|
my $hintsText = splice @records, 0, 2; # starts with empty record |
1394 |
my @lines = split(/\n/, $resbody); |
my $hints = { $hintsText =~ m/^(.*?)\t(.*?)$/gsm }; |
1395 |
return unless (@lines); |
|
1396 |
|
# process records |
1397 |
my $border = $lines[0]; |
my $docs = []; |
1398 |
my $isend = 0; |
foreach my $record (@records) |
1399 |
my $lnum = 1; |
{ |
1400 |
|
# split into keys and snippets |
1401 |
while ( $lnum <= $#lines ) { |
my ($keys, $snippet) = $record =~ m/^(.*?)\n\n(.*?)$/s; |
1402 |
my $line = $lines[$lnum]; |
|
1403 |
$lnum++; |
# create document hash |
1404 |
|
my $doc = { $keys =~ m/^(.*?)=(.*?)$/gsm }; |
1405 |
#warn "## $line\n"; |
$doc->{'@keywords'} = $doc->{keywords}; |
1406 |
if ($line && $line =~ m/^\Q$border\E(:END)*$/) { |
($doc->{keywords}) = $keys =~ m/^%VECTOR\t(.*?)$/gm; |
1407 |
$isend = $1; |
$doc->{snippet} = $snippet; |
1408 |
last; |
|
1409 |
} |
push @$docs, new Search::Estraier::ResultDocument( |
1410 |
|
attrs => $doc, |
1411 |
if ($line =~ /\t/) { |
uri => $doc->{'@uri'}, |
1412 |
my ($k,$v) = split(/\t/, $line, 2); |
snippet => $snippet, |
1413 |
$hints->{$k} = $v; |
keywords => $doc->{'keywords'}, |
1414 |
} |
); |
1415 |
} |
} |
1416 |
|
|
1417 |
my $snum = $lnum; |
return new Search::Estraier::NodeResult( docs => $docs, hints => $hints ); |
|
|
|
|
while( ! $isend && $lnum <= $#lines ) { |
|
|
my $line = $lines[$lnum]; |
|
|
#warn "# $lnum: $line\n"; |
|
|
$lnum++; |
|
|
|
|
|
if ($line && $line =~ m/^\Q$border\E/) { |
|
|
if ($lnum > $snum) { |
|
|
my $rdattrs; |
|
|
my $rdvector; |
|
|
my $rdsnippet; |
|
|
|
|
|
my $rlnum = $snum; |
|
|
while ($rlnum < $lnum - 1 ) { |
|
|
#my $rdline = $self->_s($lines[$rlnum]); |
|
|
my $rdline = $lines[$rlnum]; |
|
|
$rlnum++; |
|
|
last unless ($rdline); |
|
|
if ($rdline =~ /^%/) { |
|
|
$rdvector = $1 if ($rdline =~ /^%VECTOR\t(.+)$/); |
|
|
} elsif($rdline =~ /=/) { |
|
|
$rdattrs->{$1} = $2 if ($rdline =~ /^(.+)=(.+)$/); |
|
|
} else { |
|
|
confess "invalid format of response"; |
|
|
} |
|
|
} |
|
|
while($rlnum < $lnum - 1) { |
|
|
my $rdline = $lines[$rlnum]; |
|
|
$rlnum++; |
|
|
$rdsnippet .= "$rdline\n"; |
|
|
} |
|
|
#warn Dumper($rdvector, $rdattrs, $rdsnippet); |
|
|
if (my $rduri = $rdattrs->{'@uri'}) { |
|
|
push @docs, new Search::Estraier::ResultDocument( |
|
|
uri => $rduri, |
|
|
attrs => $rdattrs, |
|
|
snippet => $rdsnippet, |
|
|
keywords => $rdvector, |
|
|
); |
|
|
} |
|
|
} |
|
|
$snum = $lnum; |
|
|
#warn "### $line\n"; |
|
|
$isend = 1 if ($line =~ /:END$/); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (! $isend) { |
|
|
warn "received result doesn't have :END\n$resbody"; |
|
|
return; |
|
|
} |
|
|
|
|
|
#warn Dumper(\@docs, $hints); |
|
|
|
|
|
return new Search::Estraier::NodeResult( docs => \@docs, hints => $hints ); |
|
1418 |
} |
} |
1419 |
|
|
1420 |
|
|
1761 |
|
|
1762 |
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
1763 |
|
|
1764 |
|
Robert Klep E<lt>robert@klep.nameE<gt> contributed refactored search code |
1765 |
|
|
1766 |
=head1 COPYRIGHT AND LICENSE |
=head1 COPYRIGHT AND LICENSE |
1767 |
|
|