4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
7 |
our $VERSION = '0.04_2'; |
our $VERSION = '0.06_1'; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
599 |
} |
} |
600 |
|
|
601 |
|
|
602 |
|
=head2 set_skip |
603 |
|
|
604 |
|
Set number of skipped documents from beginning of results |
605 |
|
|
606 |
|
$cond->set_skip(42); |
607 |
|
|
608 |
|
Similar to C<offset> in RDBMS. |
609 |
|
|
610 |
|
=cut |
611 |
|
|
612 |
|
sub set_skip { |
613 |
|
my $self = shift; |
614 |
|
$self->{skip} = shift; |
615 |
|
} |
616 |
|
|
617 |
|
=head2 skip |
618 |
|
|
619 |
|
Return skip for this condition. |
620 |
|
|
621 |
|
print $cond->skip; |
622 |
|
|
623 |
|
=cut |
624 |
|
|
625 |
|
sub skip { |
626 |
|
my $self = shift; |
627 |
|
return $self->{skip}; |
628 |
|
} |
629 |
|
|
630 |
|
|
631 |
package Search::Estraier::ResultDocument; |
package Search::Estraier::ResultDocument; |
632 |
|
|
633 |
use Carp qw/croak/; |
use Carp qw/croak/; |
872 |
|
|
873 |
my $node = new Search::HyperEstraier::Node( |
my $node = new Search::HyperEstraier::Node( |
874 |
url => 'http://localhost:1978/node/test', |
url => 'http://localhost:1978/node/test', |
875 |
|
user => 'admin', |
876 |
|
passwd => 'admin' |
877 |
debug => 1, |
debug => 1, |
878 |
croak_on_error => 1 |
croak_on_error => 1 |
879 |
); |
); |
886 |
|
|
887 |
URL to node |
URL to node |
888 |
|
|
889 |
|
=item user |
890 |
|
|
891 |
|
specify username for node server authentication |
892 |
|
|
893 |
|
=item passwd |
894 |
|
|
895 |
|
password for authentication |
896 |
|
|
897 |
=item debug |
=item debug |
898 |
|
|
899 |
dumps a B<lot> of debugging output |
dumps a B<lot> of debugging output |
913 |
my $self = { |
my $self = { |
914 |
pxport => -1, |
pxport => -1, |
915 |
timeout => 0, # this used to be -1 |
timeout => 0, # this used to be -1 |
|
dnum => -1, |
|
|
wnum => -1, |
|
|
size => -1.0, |
|
916 |
wwidth => 480, |
wwidth => 480, |
917 |
hwidth => 96, |
hwidth => 96, |
918 |
awidth => 96, |
awidth => 96, |
919 |
status => -1, |
status => -1, |
920 |
}; |
}; |
921 |
|
|
922 |
bless($self, $class); |
bless($self, $class); |
923 |
|
|
924 |
if ($#_ == 0) { |
if ($#_ == 0) { |
925 |
$self->{url} = shift; |
$self->{url} = shift; |
926 |
} else { |
} else { |
|
my $args = {@_}; |
|
|
|
|
927 |
%$self = ( %$self, @_ ); |
%$self = ( %$self, @_ ); |
928 |
|
|
929 |
|
$self->set_auth( $self->{user}, $self->{passwd} ) if ($self->{user}); |
930 |
|
|
931 |
warn "## Node debug on\n" if ($self->{debug}); |
warn "## Node debug on\n" if ($self->{debug}); |
932 |
} |
} |
933 |
|
|
934 |
|
$self->{inform} = { |
935 |
|
dnum => -1, |
936 |
|
wnum => -1, |
937 |
|
size => -1.0, |
938 |
|
}; |
939 |
|
|
940 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
941 |
} |
} |
942 |
|
|
1313 |
|
|
1314 |
sub name { |
sub name { |
1315 |
my $self = shift; |
my $self = shift; |
1316 |
$self->_set_info unless ($self->{name}); |
$self->_set_info unless ($self->{inform}->{name}); |
1317 |
return $self->{name}; |
return $self->{inform}->{name}; |
1318 |
} |
} |
1319 |
|
|
1320 |
|
|
1326 |
|
|
1327 |
sub label { |
sub label { |
1328 |
my $self = shift; |
my $self = shift; |
1329 |
$self->_set_info unless ($self->{label}); |
$self->_set_info unless ($self->{inform}->{label}); |
1330 |
return $self->{label}; |
return $self->{inform}->{label}; |
1331 |
} |
} |
1332 |
|
|
1333 |
|
|
1339 |
|
|
1340 |
sub doc_num { |
sub doc_num { |
1341 |
my $self = shift; |
my $self = shift; |
1342 |
$self->_set_info if ($self->{dnum} < 0); |
$self->_set_info if ($self->{inform}->{dnum} < 0); |
1343 |
return $self->{dnum}; |
return $self->{inform}->{dnum}; |
1344 |
} |
} |
1345 |
|
|
1346 |
|
|
1352 |
|
|
1353 |
sub word_num { |
sub word_num { |
1354 |
my $self = shift; |
my $self = shift; |
1355 |
$self->_set_info if ($self->{wnum} < 0); |
$self->_set_info if ($self->{inform}->{wnum} < 0); |
1356 |
return $self->{wnum}; |
return $self->{inform}->{wnum}; |
1357 |
} |
} |
1358 |
|
|
1359 |
|
|
1365 |
|
|
1366 |
sub size { |
sub size { |
1367 |
my $self = shift; |
my $self = shift; |
1368 |
$self->_set_info if ($self->{size} < 0); |
$self->_set_info if ($self->{inform}->{size} < 0); |
1369 |
return $self->{size}; |
return $self->{inform}->{size}; |
1370 |
} |
} |
1371 |
|
|
1372 |
|
|
1399 |
); |
); |
1400 |
return if ($rv != 200); |
return if ($rv != 200); |
1401 |
|
|
1402 |
my (@docs, $hints); |
my @records = split /--------\[.*?\]--------(?::END)?\r?\n/, $resbody; |
1403 |
|
my $hintsText = splice @records, 0, 2; # starts with empty record |
1404 |
my @lines = split(/\n/, $resbody); |
my $hints = { $hintsText =~ m/^(.*?)\t(.*?)$/gsm }; |
1405 |
return unless (@lines); |
|
1406 |
|
# process records |
1407 |
my $border = $lines[0]; |
my $docs = []; |
1408 |
my $isend = 0; |
foreach my $record (@records) |
1409 |
my $lnum = 1; |
{ |
1410 |
|
# split into keys and snippets |
1411 |
while ( $lnum <= $#lines ) { |
my ($keys, $snippet) = $record =~ m/^(.*?)\n\n(.*?)$/s; |
1412 |
my $line = $lines[$lnum]; |
|
1413 |
$lnum++; |
# create document hash |
1414 |
|
my $doc = { $keys =~ m/^(.*?)=(.*?)$/gsm }; |
1415 |
#warn "## $line\n"; |
$doc->{'@keywords'} = $doc->{keywords}; |
1416 |
if ($line && $line =~ m/^\Q$border\E(:END)*$/) { |
($doc->{keywords}) = $keys =~ m/^%VECTOR\t(.*?)$/gm; |
1417 |
$isend = $1; |
$doc->{snippet} = $snippet; |
1418 |
last; |
|
1419 |
} |
push @$docs, new Search::Estraier::ResultDocument( |
1420 |
|
attrs => $doc, |
1421 |
if ($line =~ /\t/) { |
uri => $doc->{'@uri'}, |
1422 |
my ($k,$v) = split(/\t/, $line, 2); |
snippet => $snippet, |
1423 |
$hints->{$k} = $v; |
keywords => $doc->{'keywords'}, |
1424 |
} |
); |
|
} |
|
|
|
|
|
my $snum = $lnum; |
|
|
|
|
|
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$/); |
|
|
} |
|
|
|
|
1425 |
} |
} |
1426 |
|
|
1427 |
if (! $isend) { |
return new Search::Estraier::NodeResult( docs => $docs, hints => $hints ); |
|
warn "received result doesn't have :END\n$resbody"; |
|
|
return; |
|
|
} |
|
|
|
|
|
#warn Dumper(\@docs, $hints); |
|
|
|
|
|
return new Search::Estraier::NodeResult( docs => \@docs, hints => $hints ); |
|
1428 |
} |
} |
1429 |
|
|
1430 |
|
|
1473 |
push @args, 'wwidth=' . $self->{wwidth}; |
push @args, 'wwidth=' . $self->{wwidth}; |
1474 |
push @args, 'hwidth=' . $self->{hwidth}; |
push @args, 'hwidth=' . $self->{hwidth}; |
1475 |
push @args, 'awidth=' . $self->{awidth}; |
push @args, 'awidth=' . $self->{awidth}; |
1476 |
|
push @args, 'skip=' . $self->{skip} if ($self->{skip}); |
1477 |
|
|
1478 |
return join('&', @args); |
return join('&', @args); |
1479 |
} |
} |
1668 |
|
|
1669 |
sub admins { |
sub admins { |
1670 |
my $self = shift; |
my $self = shift; |
1671 |
$self->_set_info unless ($self->{name}); |
$self->_set_info unless ($self->{inform}->{name}); |
1672 |
return $self->{admins}; |
return $self->{inform}->{admins}; |
1673 |
} |
} |
1674 |
|
|
1675 |
=head2 guests |
=head2 guests |
1682 |
|
|
1683 |
sub guests { |
sub guests { |
1684 |
my $self = shift; |
my $self = shift; |
1685 |
$self->_set_info unless ($self->{name}); |
$self->_set_info unless ($self->{inform}->{name}); |
1686 |
return $self->{guests}; |
return $self->{inform}->{guests}; |
1687 |
} |
} |
1688 |
|
|
1689 |
=head2 links |
=head2 links |
1696 |
|
|
1697 |
sub links { |
sub links { |
1698 |
my $self = shift; |
my $self = shift; |
1699 |
$self->_set_info unless ($self->{name}); |
$self->_set_info unless ($self->{inform}->{name}); |
1700 |
return $self->{links}; |
return $self->{inform}->{links}; |
1701 |
} |
} |
1702 |
|
|
1703 |
|
|
1729 |
return if ($rv != 200 || !$resbody); |
return if ($rv != 200 || !$resbody); |
1730 |
|
|
1731 |
my @lines = split(/[\r\n]/,$resbody); |
my @lines = split(/[\r\n]/,$resbody); |
1732 |
|
|
1733 |
( $self->{name}, $self->{label}, $self->{dnum}, $self->{wnum}, $self->{size} ) = |
$self->{inform} = {}; |
1734 |
split(/\t/, shift @lines, 5); |
|
1735 |
|
( $self->{inform}->{name}, $self->{inform}->{label}, $self->{inform}->{dnum}, |
1736 |
|
$self->{inform}->{wnum}, $self->{inform}->{size} ) = split(/\t/, shift @lines, 5); |
1737 |
|
|
1738 |
return $resbody unless (@lines); |
return $resbody unless (@lines); |
1739 |
|
|
1740 |
shift @lines; |
shift @lines; |
1741 |
|
|
1742 |
while(my $admin = shift @lines) { |
while(my $admin = shift @lines) { |
1743 |
push @{$self->{admins}}, $admin; |
push @{$self->{inform}->{admins}}, $admin; |
1744 |
} |
} |
1745 |
|
|
1746 |
while(my $guest = shift @lines) { |
while(my $guest = shift @lines) { |
1747 |
push @{$self->{guests}}, $guest; |
push @{$self->{inform}->{guests}}, $guest; |
1748 |
} |
} |
1749 |
|
|
1750 |
while(my $link = shift @lines) { |
while(my $link = shift @lines) { |
1751 |
push @{$self->{links}}, $link; |
push @{$self->{inform}->{links}}, $link; |
1752 |
} |
} |
1753 |
|
|
1754 |
return $resbody; |
return $resbody; |
1771 |
|
|
1772 |
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
1773 |
|
|
1774 |
|
Robert Klep E<lt>robert@klep.nameE<gt> contributed refactored search code |
1775 |
|
|
1776 |
=head1 COPYRIGHT AND LICENSE |
=head1 COPYRIGHT AND LICENSE |
1777 |
|
|