4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
7 |
our $VERSION = '0.04_1'; |
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/; |
818 |
return $self->{hints}->{$key}; |
return $self->{hints}->{$key}; |
819 |
} |
} |
820 |
|
|
821 |
=head2 hits |
=head2 hints |
822 |
|
|
823 |
More perlish version of C<hint>. This one returns hash. |
More perlish version of C<hint>. This one returns hash. |
824 |
|
|
903 |
my $self = { |
my $self = { |
904 |
pxport => -1, |
pxport => -1, |
905 |
timeout => 0, # this used to be -1 |
timeout => 0, # this used to be -1 |
|
dnum => -1, |
|
|
wnum => -1, |
|
|
size => -1.0, |
|
906 |
wwidth => 480, |
wwidth => 480, |
907 |
hwidth => 96, |
hwidth => 96, |
908 |
awidth => 96, |
awidth => 96, |
909 |
status => -1, |
status => -1, |
910 |
}; |
}; |
911 |
|
|
912 |
bless($self, $class); |
bless($self, $class); |
913 |
|
|
914 |
if ($#_ == 0) { |
if ($#_ == 0) { |
921 |
warn "## Node debug on\n" if ($self->{debug}); |
warn "## Node debug on\n" if ($self->{debug}); |
922 |
} |
} |
923 |
|
|
924 |
|
$self->{inform} = { |
925 |
|
dnum => -1, |
926 |
|
wnum => -1, |
927 |
|
size => -1.0, |
928 |
|
}; |
929 |
|
|
930 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
931 |
} |
} |
932 |
|
|
1303 |
|
|
1304 |
sub name { |
sub name { |
1305 |
my $self = shift; |
my $self = shift; |
1306 |
$self->_set_info unless ($self->{name}); |
$self->_set_info unless ($self->{inform}->{name}); |
1307 |
return $self->{name}; |
return $self->{inform}->{name}; |
1308 |
} |
} |
1309 |
|
|
1310 |
|
|
1316 |
|
|
1317 |
sub label { |
sub label { |
1318 |
my $self = shift; |
my $self = shift; |
1319 |
$self->_set_info unless ($self->{label}); |
$self->_set_info unless ($self->{inform}->{label}); |
1320 |
return $self->{label}; |
return $self->{inform}->{label}; |
1321 |
} |
} |
1322 |
|
|
1323 |
|
|
1329 |
|
|
1330 |
sub doc_num { |
sub doc_num { |
1331 |
my $self = shift; |
my $self = shift; |
1332 |
$self->_set_info if ($self->{dnum} < 0); |
$self->_set_info if ($self->{inform}->{dnum} < 0); |
1333 |
return $self->{dnum}; |
return $self->{inform}->{dnum}; |
1334 |
} |
} |
1335 |
|
|
1336 |
|
|
1342 |
|
|
1343 |
sub word_num { |
sub word_num { |
1344 |
my $self = shift; |
my $self = shift; |
1345 |
$self->_set_info if ($self->{wnum} < 0); |
$self->_set_info if ($self->{inform}->{wnum} < 0); |
1346 |
return $self->{wnum}; |
return $self->{inform}->{wnum}; |
1347 |
} |
} |
1348 |
|
|
1349 |
|
|
1355 |
|
|
1356 |
sub size { |
sub size { |
1357 |
my $self = shift; |
my $self = shift; |
1358 |
$self->_set_info if ($self->{size} < 0); |
$self->_set_info if ($self->{inform}->{size} < 0); |
1359 |
return $self->{size}; |
return $self->{inform}->{size}; |
1360 |
} |
} |
1361 |
|
|
1362 |
|
|
1473 |
return new Search::Estraier::NodeResult( docs => \@docs, hints => $hints ); |
return new Search::Estraier::NodeResult( docs => \@docs, hints => $hints ); |
1474 |
} |
} |
1475 |
|
|
1476 |
|
=head2 search_new |
1477 |
|
|
1478 |
|
Better implementation of search by Robert Klep <robert@klep.name> |
1479 |
|
|
1480 |
|
=cut |
1481 |
|
|
1482 |
|
sub search_new { |
1483 |
|
my $self = shift; |
1484 |
|
my ($cond, $depth) = @_; |
1485 |
|
return unless ($cond && defined($depth) && $self->{url}); |
1486 |
|
croak "cond mush be Search::Estraier::Condition, not '$cond->isa'" unless ($cond->isa('Search::Estraier::Condition')); |
1487 |
|
croak "depth needs number, not '$depth'" unless ($depth =~ m/^\d+$/); |
1488 |
|
|
1489 |
|
my $resbody; |
1490 |
|
|
1491 |
|
my $rv = $self->shuttle_url( $self->{url} . '/search', |
1492 |
|
'application/x-www-form-urlencoded', |
1493 |
|
$self->cond_to_query( $cond, $depth ), |
1494 |
|
\$resbody, |
1495 |
|
); |
1496 |
|
return if ($rv != 200); |
1497 |
|
|
1498 |
|
my @records = split /--------\[.*?\]--------(?::END)?\r?\n/, $resbody; |
1499 |
|
my $hintsText = splice @records, 0, 2; # starts with empty record |
1500 |
|
my $hints = { $hintsText =~ m/^(.*?)\t(.*?)$/gsm }; |
1501 |
|
|
1502 |
|
# process records |
1503 |
|
my $docs; |
1504 |
|
foreach my $record (@records) |
1505 |
|
{ |
1506 |
|
# split into keys and snippets |
1507 |
|
my ($keys, $snippet) = $record =~ m/^(.*?)\n\n(.*?)$/s; |
1508 |
|
|
1509 |
|
# create document hash |
1510 |
|
my $doc = { $keys =~ m/^(.*?)=(.*?)$/gsm }; |
1511 |
|
$doc->{'@keywords'} = $doc->{keywords}; |
1512 |
|
($doc->{keywords}) = $keys =~ m/^%VECTOR\t(.*?)$/gm; |
1513 |
|
$doc->{snippet} = $snippet; |
1514 |
|
|
1515 |
|
push @$docs, new Search::Estraier::ResultDocument( |
1516 |
|
attrs => $doc, |
1517 |
|
uri => $doc->{'@uri'}, |
1518 |
|
snippet => $snippet, |
1519 |
|
keywords => $doc->{'keywords'}, |
1520 |
|
); |
1521 |
|
} |
1522 |
|
|
1523 |
|
return new Search::Estraier::NodeResult( docs => $docs, hints => $hints ); |
1524 |
|
} |
1525 |
|
|
1526 |
|
|
1527 |
=head2 cond_to_query |
=head2 cond_to_query |
1528 |
|
|
1569 |
push @args, 'wwidth=' . $self->{wwidth}; |
push @args, 'wwidth=' . $self->{wwidth}; |
1570 |
push @args, 'hwidth=' . $self->{hwidth}; |
push @args, 'hwidth=' . $self->{hwidth}; |
1571 |
push @args, 'awidth=' . $self->{awidth}; |
push @args, 'awidth=' . $self->{awidth}; |
1572 |
|
push @args, 'skip=' . $self->{skip} if ($self->{skip}); |
1573 |
|
|
1574 |
return join('&', @args); |
return join('&', @args); |
1575 |
} |
} |
1743 |
my $reqbody = 'url=' . uri_escape($url) . '&label=' . uri_escape($label); |
my $reqbody = 'url=' . uri_escape($url) . '&label=' . uri_escape($label); |
1744 |
$reqbody .= '&credit=' . $credit if ($credit > 0); |
$reqbody .= '&credit=' . $credit if ($credit > 0); |
1745 |
|
|
1746 |
$self->shuttle_url( $self->{url} . '/_set_link', |
if ($self->shuttle_url( $self->{url} . '/_set_link', |
1747 |
'application/x-www-form-urlencoded', |
'application/x-www-form-urlencoded', |
1748 |
$reqbody, |
$reqbody, |
1749 |
undef |
undef |
1750 |
) == 200; |
) == 200) { |
1751 |
|
# refresh node info after adding link |
1752 |
|
$self->_set_info; |
1753 |
|
return 1; |
1754 |
|
} |
1755 |
|
} |
1756 |
|
|
1757 |
|
=head2 admins |
1758 |
|
|
1759 |
|
my @admins = @{ $node->admins }; |
1760 |
|
|
1761 |
|
Return array of users with admin rights on node |
1762 |
|
|
1763 |
|
=cut |
1764 |
|
|
1765 |
|
sub admins { |
1766 |
|
my $self = shift; |
1767 |
|
$self->_set_info unless ($self->{inform}->{name}); |
1768 |
|
return $self->{inform}->{admins}; |
1769 |
|
} |
1770 |
|
|
1771 |
|
=head2 guests |
1772 |
|
|
1773 |
|
my @guests = @{ $node->guests }; |
1774 |
|
|
1775 |
|
Return array of users with guest rights on node |
1776 |
|
|
1777 |
|
=cut |
1778 |
|
|
1779 |
|
sub guests { |
1780 |
|
my $self = shift; |
1781 |
|
$self->_set_info unless ($self->{inform}->{name}); |
1782 |
|
return $self->{inform}->{guests}; |
1783 |
|
} |
1784 |
|
|
1785 |
|
=head2 links |
1786 |
|
|
1787 |
|
my $links = @{ $node->links }; |
1788 |
|
|
1789 |
|
Return array of links for this node |
1790 |
|
|
1791 |
|
=cut |
1792 |
|
|
1793 |
|
sub links { |
1794 |
|
my $self = shift; |
1795 |
|
$self->_set_info unless ($self->{inform}->{name}); |
1796 |
|
return $self->{inform}->{links}; |
1797 |
} |
} |
1798 |
|
|
1799 |
|
|
1824 |
|
|
1825 |
return if ($rv != 200 || !$resbody); |
return if ($rv != 200 || !$resbody); |
1826 |
|
|
1827 |
# it seems that response can have multiple line endings |
my @lines = split(/[\r\n]/,$resbody); |
1828 |
$resbody =~ s/[\r\n]+$//; |
|
1829 |
|
$self->{inform} = {}; |
1830 |
|
|
1831 |
|
( $self->{inform}->{name}, $self->{inform}->{label}, $self->{inform}->{dnum}, |
1832 |
|
$self->{inform}->{wnum}, $self->{inform}->{size} ) = split(/\t/, shift @lines, 5); |
1833 |
|
|
1834 |
|
return $resbody unless (@lines); |
1835 |
|
|
1836 |
|
shift @lines; |
1837 |
|
|
1838 |
|
while(my $admin = shift @lines) { |
1839 |
|
push @{$self->{inform}->{admins}}, $admin; |
1840 |
|
} |
1841 |
|
|
1842 |
|
while(my $guest = shift @lines) { |
1843 |
|
push @{$self->{inform}->{guests}}, $guest; |
1844 |
|
} |
1845 |
|
|
1846 |
|
while(my $link = shift @lines) { |
1847 |
|
push @{$self->{inform}->{links}}, $link; |
1848 |
|
} |
1849 |
|
|
1850 |
( $self->{name}, $self->{label}, $self->{dnum}, $self->{wnum}, $self->{size} ) = |
return $resbody; |
|
split(/\t/, $resbody, 5); |
|
1851 |
|
|
1852 |
} |
} |
1853 |
|
|