/[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 43 by dpavlin, Fri Jan 6 00:04:28 2006 UTC revision 44 by dpavlin, Fri Jan 6 01:12:10 2006 UTC
# Line 688  sub hint { Line 688  sub hint {
688    
689  package Search::Estraier::Node;  package Search::Estraier::Node;
690    
691  use Carp qw/carp croak/;  use Carp qw/carp croak confess/;
692  use URI;  use URI;
693  use MIME::Base64;  use MIME::Base64;
694  use IO::Socket::INET;  use IO::Socket::INET;
# Line 910  sub get_doc { Line 910  sub get_doc {
910          return $self->_fetch_doc( id => $id );          return $self->_fetch_doc( id => $id );
911  }  }
912    
913    
914  =head2 get_doc_by_uri  =head2 get_doc_by_uri
915    
916  Retreive document  Retreive document
# Line 926  sub get_doc_by_uri { Line 927  sub get_doc_by_uri {
927          return $self->_fetch_doc( uri => $uri );          return $self->_fetch_doc( uri => $uri );
928  }  }
929    
930    
931    =head2 etch_doc
932    
933    Exctract document keywords
934    
935      my $keywords = $node->etch_doc( document_id ) or die "can't etch document";
936    
937    =cut
938    
939    sub erch_doc {
940            my $self = shift;
941            my $id = shift || return;
942            return $self->_fetch_doc( id => $id, etch => 1 );
943    }
944    
945    =head2 etch_doc_by_uri
946    
947    Retreive document
948    
949      my $keywords = $node->etch_doc_by_uri( 'file:///document_uri' ) or die "can't etch document";
950    
951    Return true on success or false on failture.
952    
953    =cut
954    
955    sub etch_doc_by_uri {
956            my $self = shift;
957            my $uri = shift || return;
958            return $self->_fetch_doc( uri => $uri, etch => 1 );
959    }
960    
961    
962  =head2 _fetch_doc  =head2 _fetch_doc
963    
964  Private function used for implementation of C<get_doc> and C<get_doc_by_uri>.  Private function used for implementing of C<get_doc>, C<get_doc_by_uri>,
965    C<etch_doc>, C<etch_doc_by_uri>.
966    
967   my $doc = $node->fetch_doc( id => 42 );   my $doc = $node->fetch_doc( id => 42, etch => 1 );
968   my $doc = $node->fetch_doc( uri => 'file://uri/42' );   my $doc = $node->fetch_doc( uri => 'file://uri/42' );
969    
970  =cut  =cut
971    
972  sub _fetch_doc {  sub _fetch_doc {
973          my $self = shift;          my $self = shift;
974          my ($name,$val) = @_;          my $a = {@_};
975          return unless ($name && defined($val) && $self->{url});          return unless ( ($a->{id} || $a->{uri}) && $self->{url} );
976          if ($name eq 'id') {  
977                  croak "id must be numberm not '$val'" unless ($val =~ m/^\d+$/);          my ($arg, $resbody);
978    
979            my $path = '/get_doc';
980            $path = '/etch_doc' if ($a->{etch});
981    
982            if ($a->{id}) {
983                    croak "id must be numberm not '$a->{id}'" unless ($a->{id} =~ m/^\d+$/);
984                    $arg = 'id=' . $a->{id};
985            } elsif ($a->{uri}) {
986                    $arg = 'uri=' . $a->{uri};
987            } else {
988                    confess "unhandled argument. Need id or uri.";
989          }          }
990          my $rv = $self->shuttle_url( $self->{url} . '/get_doc',  
991            my $rv = $self->shuttle_url( $self->{url} . $path,
992                  'application/x-www-form-urlencoded',                  'application/x-www-form-urlencoded',
993                  "$name=$val",                  $arg,
994                  my $draft,                  $resbody,
995          );          );
996    
997          return if ($rv != 200);          return if ($rv != 200);
998          return new Search::Estraier::Document($draft);  
999            if ($a->{etch}) {
1000                    $self->{kwords} = {};
1001                    return +{} unless ($resbody);
1002                    foreach my $l (split(/\n/, $resbody)) {
1003                            my ($k,$v) = split(/\t/, $l, 2);
1004                            $self->{kwords}->{$k} = $v if ($v);
1005                    }
1006                    return $self->{kwords};
1007            } else {
1008                    return new Search::Estraier::Document($resbody);
1009            }
1010  }  }
1011    
1012    

Legend:
Removed from v.43  
changed lines
  Added in v.44

  ViewVC Help
Powered by ViewVC 1.1.26