/[Search-Estraier]/trunk/lib/Search/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/lib/Search/Estraier.pm

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

revision 111 by dpavlin, Tue Feb 21 15:41:57 2006 UTC revision 128 by dpavlin, Mon May 8 12:00:43 2006 UTC
# Line 4  use 5.008; Line 4  use 5.008;
4  use strict;  use strict;
5  use warnings;  use warnings;
6    
7  our $VERSION = '0.04_3';  our $VERSION = '0.06_1';
8    
9  =head1 NAME  =head1 NAME
10    
# Line 599  sub options { Line 599  sub options {
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/;
# Line 1360  sub search { Line 1389  sub search {
1389          );          );
1390          return if ($rv != 200);          return if ($rv != 200);
1391    
1392          my (@docs, $hints);          my @records     = split /--------\[.*?\]--------(?::END)?\r?\n/, $resbody;
1393            my $hintsText   = splice @records, 0, 2; # starts with empty record
1394          my @lines = split(/\n/, $resbody);          my $hints               = { $hintsText =~ m/^(.*?)\t(.*?)$/gsm };
1395          return unless (@lines);  
1396            # process records
1397          my $border = $lines[0];          my $docs = [];
1398          my $isend = 0;          foreach my $record (@records)
1399          my $lnum = 1;          {
1400                    # split into keys and snippets
1401          while ( $lnum <= $#lines ) {                  my ($keys, $snippet) = $record =~ m/^(.*?)\n\n(.*?)$/s;
1402                  my $line = $lines[$lnum];  
1403                  $lnum++;                  # create document hash
1404                    my $doc                         = { $keys =~ m/^(.*?)=(.*?)$/gsm };
1405                  #warn "## $line\n";                  $doc->{'@keywords'}     = $doc->{keywords};
1406                  if ($line && $line =~ m/^\Q$border\E(:END)*$/) {                  ($doc->{keywords})      = $keys =~ m/^%VECTOR\t(.*?)$/gm;
1407                          $isend = $1;                  $doc->{snippet}         = $snippet;
1408                          last;  
1409                  }                  push @$docs, new Search::Estraier::ResultDocument(
1410                            attrs           => $doc,
1411                  if ($line =~ /\t/) {                          uri             => $doc->{'@uri'},
1412                          my ($k,$v) = split(/\t/, $line, 2);                          snippet         => $snippet,
1413                          $hints->{$k} = $v;                          keywords        => $doc->{'keywords'},
1414                  }                  );
1415          }          }
1416    
1417          my $snum = $lnum;          return new Search::Estraier::NodeResult( docs => $docs, hints => $hints );
   
         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 );  
1418  }  }
1419    
1420    
# Line 1490  sub cond_to_query { Line 1463  sub cond_to_query {
1463          push @args, 'wwidth=' . $self->{wwidth};          push @args, 'wwidth=' . $self->{wwidth};
1464          push @args, 'hwidth=' . $self->{hwidth};          push @args, 'hwidth=' . $self->{hwidth};
1465          push @args, 'awidth=' . $self->{awidth};          push @args, 'awidth=' . $self->{awidth};
1466            push @args, 'skip=' . $self->{skip} if ($self->{skip});
1467    
1468          return join('&', @args);          return join('&', @args);
1469  }  }
# Line 1787  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.111  
changed lines
  Added in v.128

  ViewVC Help
Powered by ViewVC 1.1.26