/[Search-Estraier]/trunk/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 127 by dpavlin, Sat May 6 21:38:14 2006 UTC revision 128 by dpavlin, Mon May 8 12:00:43 2006 UTC
# Line 1389  sub search { Line 1389  sub search {
1389          );          );
1390          return if ($rv != 200);          return if ($rv != 200);
1391    
         my (@docs, $hints);  
   
         my @lines = split(/\n/, $resbody);  
         return unless (@lines);  
   
         my $border = $lines[0];  
         my $isend = 0;  
         my $lnum = 1;  
   
         while ( $lnum <= $#lines ) {  
                 my $line = $lines[$lnum];  
                 $lnum++;  
   
                 #warn "## $line\n";  
                 if ($line && $line =~ m/^\Q$border\E(:END)*$/) {  
                         $isend = $1;  
                         last;  
                 }  
   
                 if ($line =~ /\t/) {  
                         my ($k,$v) = split(/\t/, $line, 2);  
                         $hints->{$k} = $v;  
                 }  
         }  
   
         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$/);  
                 }  
   
         }  
   
         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 );  
 }  
   
 =head2 search_new  
   
 Better implementation of search by Robert Klep <robert@klep.name>  
   
 =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);  
   
1392          my @records     = split /--------\[.*?\]--------(?::END)?\r?\n/, $resbody;          my @records     = split /--------\[.*?\]--------(?::END)?\r?\n/, $resbody;
1393          my $hintsText   = splice @records, 0, 2; # starts with empty record          my $hintsText   = splice @records, 0, 2; # starts with empty record
1394          my $hints               = { $hintsText =~ m/^(.*?)\t(.*?)$/gsm };          my $hints               = { $hintsText =~ m/^(.*?)\t(.*?)$/gsm };
1395    
1396          # process records          # process records
1397          my $docs;          my $docs = [];
1398          foreach my $record (@records)          foreach my $record (@records)
1399          {          {
1400                  # split into keys and snippets                  # split into keys and snippets
# Line 1867  Hyper Estraier Ruby interface on which t Line 1761  Hyper Estraier Ruby interface on which t
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    

Legend:
Removed from v.127  
changed lines
  Added in v.128

  ViewVC Help
Powered by ViewVC 1.1.26