--- trunk/Estraier.pm 2006/05/03 14:25:40 125 +++ trunk/Estraier.pm 2006/05/06 21:38:14 126 @@ -4,7 +4,7 @@ use strict; use warnings; -our $VERSION = '0.05'; +our $VERSION = '0.06_1'; =head1 NAME @@ -1473,6 +1473,56 @@ return new Search::Estraier::NodeResult( docs => \@docs, hints => $hints ); } +=head2 search_new + +Better implementation of search by Robert Klep + +=cut + +sub search_new { + my $self = shift; + my ($cond, $depth) = @_; + return unless ($cond && defined($depth) && $self->{url}); + croak "cond mush be Search::Estraier::Condition, not '$cond->isa'" unless ($cond->isa('Search::Estraier::Condition')); + croak "depth needs number, not '$depth'" unless ($depth =~ m/^\d+$/); + + my $resbody; + + my $rv = $self->shuttle_url( $self->{url} . '/search', + 'application/x-www-form-urlencoded', + $self->cond_to_query( $cond, $depth ), + \$resbody, + ); + return if ($rv != 200); + + my @records = split /--------\[.*?\]--------(?::END)?\r?\n/, $resbody; + my $hintsText = splice @records, 0, 2; # starts with empty record + my $hints = { $hintsText =~ m/^(.*?)\t(.*?)$/gsm }; + + # process records + my $docs; + foreach my $record (@records) + { + # split into keys and snippets + my ($keys, $snippet) = $record =~ m/^(.*?)\n\n(.*?)$/s; + + # create document hash + my $doc = { $keys =~ m/^(.*?)=(.*?)$/gsm }; + $doc->{'@keywords'} = $doc->{keywords}; + ($doc->{keywords}) = $keys =~ m/^%VECTOR\t(.*?)$/gm; + $doc->{snippet} = $snippet; + + push @$docs, new Search::Estraier::ResultDocument( + attrs => $doc, + uri => $doc->{'@uri'}, + snippet => $snippet, + keywords => $doc->{'keywords'}, + ); + } + + return new Search::Estraier::NodeResult( docs => $docs, hints => $hints ); +} + =head2 cond_to_query