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 |
|
|
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 |
|
|