387 |
sub set_max { |
sub set_max { |
388 |
my $self = shift; |
my $self = shift; |
389 |
my $max = shift; |
my $max = shift; |
390 |
croak "set_max needs number" unless ($max =~ m/^\d+$/); |
croak "set_max needs number, not '$max'" unless ($max =~ m/^\d+$/); |
391 |
$self->{max} = $max; |
$self->{max} = $max; |
392 |
} |
} |
393 |
|
|
662 |
sub get_doc { |
sub get_doc { |
663 |
my $self = shift; |
my $self = shift; |
664 |
my $num = shift; |
my $num = shift; |
665 |
croak "expect number as argument" unless ($num =~ m/^\d+$/); |
croak "expect number as argument, not '$num'" unless ($num =~ m/^\d+$/); |
666 |
return undef if ($num < 0 || $num > $self->{docs}); |
return undef if ($num < 0 || $num > $self->{docs}); |
667 |
return $self->{docs}->[$num]; |
return $self->{docs}->[$num]; |
668 |
} |
} |
750 |
sub set_proxy { |
sub set_proxy { |
751 |
my $self = shift; |
my $self = shift; |
752 |
my ($host,$port) = @_; |
my ($host,$port) = @_; |
753 |
croak "proxy port must be number" unless ($port =~ m/^\d+$/); |
croak "proxy port must be number, not '$port'" unless ($port =~ m/^\d+$/); |
754 |
$self->{pxhost} = $host; |
$self->{pxhost} = $host; |
755 |
$self->{pxport} = $port; |
$self->{pxport} = $port; |
756 |
} |
} |
767 |
sub set_timeout { |
sub set_timeout { |
768 |
my $self = shift; |
my $self = shift; |
769 |
my $sec = shift; |
my $sec = shift; |
770 |
croak "timeout must be number" unless ($sec =~ m/^\d+$/); |
croak "timeout must be number, not '$sec'" unless ($sec =~ m/^\d+$/); |
771 |
$self->{timeout} = $sec; |
$self->{timeout} = $sec; |
772 |
} |
} |
773 |
|
|
841 |
my $self = shift; |
my $self = shift; |
842 |
my $id = shift || return; |
my $id = shift || return; |
843 |
return unless ($self->{url}); |
return unless ($self->{url}); |
844 |
croak "id must be number" unless ($id =~ m/^\d+$/); |
croak "id must be number, not '$id'" unless ($id =~ m/^\d+$/); |
845 |
$self->shuttle_url( $self->{url} . '/out_doc', |
$self->shuttle_url( $self->{url} . '/out_doc', |
846 |
'application/x-www-form-urlencoded', |
'application/x-www-form-urlencoded', |
847 |
"id=$id", |
"id=$id", |
894 |
} |
} |
895 |
|
|
896 |
|
|
897 |
|
=head2 get_doc |
898 |
|
|
899 |
|
Retreive document |
900 |
|
|
901 |
|
my $doc = $node->get_doc( document_id ) or die "can't get document"; |
902 |
|
|
903 |
|
Return true on success or false on failture. |
904 |
|
|
905 |
|
=cut |
906 |
|
|
907 |
|
sub get_doc { |
908 |
|
my $self = shift; |
909 |
|
my $id = shift || return; |
910 |
|
return $self->_fetch_doc( id => $id ); |
911 |
|
} |
912 |
|
|
913 |
|
=head2 get_doc_by_uri |
914 |
|
|
915 |
|
Retreive document |
916 |
|
|
917 |
|
my $doc = $node->get_doc_by_uri( 'file:///document_uri' ) or die "can't get document"; |
918 |
|
|
919 |
|
Return true on success or false on failture. |
920 |
|
|
921 |
|
=cut |
922 |
|
|
923 |
|
sub get_doc_by_uri { |
924 |
|
my $self = shift; |
925 |
|
my $uri = shift || return; |
926 |
|
return $self->_fetch_doc( uri => $uri ); |
927 |
|
} |
928 |
|
|
929 |
|
=head2 _fetch_doc |
930 |
|
|
931 |
|
Private function used for implementation of C<get_doc> and C<get_doc_by_uri>. |
932 |
|
|
933 |
|
my $doc = $node->fetch_doc( id => 42 ); |
934 |
|
my $doc = $node->fetch_doc( uri => 'file://uri/42' ); |
935 |
|
|
936 |
|
=cut |
937 |
|
|
938 |
|
sub _fetch_doc { |
939 |
|
my $self = shift; |
940 |
|
my ($name,$val) = @_; |
941 |
|
return unless ($name && defined($val) && $self->{url}); |
942 |
|
if ($name eq 'id') { |
943 |
|
croak "id must be numberm not '$val'" unless ($val =~ m/^\d+$/); |
944 |
|
} |
945 |
|
my $rv = $self->shuttle_url( $self->{url} . '/get_doc', |
946 |
|
'application/x-www-form-urlencoded', |
947 |
|
"$name=$val", |
948 |
|
my $draft, |
949 |
|
); |
950 |
|
return if ($rv != 200); |
951 |
|
return new Search::Estraier::Document($draft); |
952 |
|
} |
953 |
|
|
954 |
|
|
955 |
|
|
956 |
|
|
957 |
=head2 shuttle_url |
=head2 shuttle_url |
958 |
|
|
959 |
This is method which uses C<IO::Socket::INET> to communicate with Hyper Estraier node |
This is method which uses C<IO::Socket::INET> to communicate with Hyper Estraier node |