--- trunk/Estraier.pm 2006/01/06 01:12:10 44 +++ trunk/Estraier.pm 2006/01/06 02:07:10 48 @@ -818,7 +818,7 @@ sub put_doc { my $self = shift; my $doc = shift || return; - return unless ($self->{url}); + return unless ($self->{url} && $doc->isa('Search::Estraier::Document')); $self->shuttle_url( $self->{url} . '/put_doc', 'text/x-estraier-draft', $doc->dump_draft, @@ -854,7 +854,7 @@ Remove a registrated document using it's uri - $node->out_doc_by_uri( 'file:///document_url' ) or "can't remove document"; + $node->out_doc_by_uri( 'file:///document/uri/42' ) or "can't remove document"; Return true on success or false on failture. @@ -885,7 +885,7 @@ sub edit_doc { my $self = shift; my $doc = shift || return; - return unless ($self->{url}); + return unless ($self->{url} && $doc->isa('Search::Estraier::Document')); $self->shuttle_url( $self->{url} . '/edit_doc', 'text/x-estraier-draft', $doc->dump_draft, @@ -915,7 +915,7 @@ Retreive document - my $doc = $node->get_doc_by_uri( 'file:///document_uri' ) or die "can't get document"; + my $doc = $node->get_doc_by_uri( 'file:///document/uri/42' ) or die "can't get document"; Return true on success or false on failture. @@ -946,7 +946,7 @@ Retreive document - my $keywords = $node->etch_doc_by_uri( 'file:///document_uri' ) or die "can't etch document"; + my $keywords = $node->etch_doc_by_uri( 'file:///document/uri/42' ) or die "can't etch document"; Return true on success or false on failture. @@ -959,13 +959,41 @@ } +=head2 uri_to_id + +Get ID of document specified by URI + + my $id = $node->uri_to_id( 'file:///document/uri/42' ); + +=cut + +sub uri_to_id { + my $self = shift; + my $uri = shift || return; + return $self->_fetch_doc( uri => $uri, path => '/uri_to_id', chomp_resbody => 1 ); +} + + =head2 _fetch_doc Private function used for implementing of C, C, C, C. - my $doc = $node->fetch_doc( id => 42, etch => 1 ); - my $doc = $node->fetch_doc( uri => 'file://uri/42' ); + # this will decode received draft into Search::Estraier::Document object + my $doc = $node->_fetch_doc( id => 42 ); + my $doc = $node->_fetch_doc( uri => 'file:///document/uri/42' ); + + # to extract keywords, add etch + my $doc = $node->_fetch_doc( id => 42, etch => 1 ); + my $doc = $node->_fetch_doc( uri => 'file:///document/uri/42', etch => 1 ); + + # more general form which allows implementation of + # uri_to_id + my $id = $node->_fetch_doc( + uri => 'file:///document/uri/42', + path => '/uri_to_id', + chomp_resbody => 1 + ); =cut @@ -976,7 +1004,7 @@ my ($arg, $resbody); - my $path = '/get_doc'; + my $path = $a->{path} || '/get_doc'; $path = '/etch_doc' if ($a->{etch}); if ($a->{id}) { @@ -991,7 +1019,7 @@ my $rv = $self->shuttle_url( $self->{url} . $path, 'application/x-www-form-urlencoded', $arg, - $resbody, + \$resbody, ); return if ($rv != 200); @@ -1004,12 +1032,80 @@ $self->{kwords}->{$k} = $v if ($v); } return $self->{kwords}; + } elsif ($a->{chomp_resbody}) { + return unless (defined($resbody)); + chomp($resbody); + return $resbody; } else { return new Search::Estraier::Document($resbody); } } +=head2 name + + my $node_name = $node->name; + +=cut + +sub name { + my $self = shift; + $self->set_info unless ($self->{name}); + return $self->{name}; +} + + +=head2 label + + my $node_label = $node->label; + +=cut + +sub label { + my $self = shift; + $self->set_info unless ($self->{label}); + return $self->{label}; +} + + +=head2 doc_num + + my $documents_in_node = $node->doc_num; + +=cut + +sub doc_num { + my $self = shift; + $self->set_info if ($self->{dnum} < 0); + return $self->{dnum}; +} + + +=head2 word_num + + my $words_in_node = $node->word_num; + +=cut + +sub word_num { + my $self = shift; + $self->set_info if ($self->{wnum} < 0); + return $self->{wnum}; +} + + +=head2 size + + my $node_size = $node->size; + +=cut + +sub size { + my $self = shift; + $self->set_info if ($self->{size} < 0); + return $self->{size}; +} + =head2 shuttle_url @@ -1123,6 +1219,37 @@ return $self->{status}; } + +=head2 set_info + +Set information for node + + $node->set_info; + +=cut + +sub set_info { + my $self = shift; + + $self->{status} = -1; + return unless ($self->{url}); + + my $resbody; + my $rv = $self->shuttle_url( $self->{url} . '/inform', + 'text/plain', + undef, + \$resbody, + ); + + return if ($rv != 200 || !$resbody); + + chomp($resbody); + + ( $self->{name}, $self->{label}, $self->{dnum}, $self->{wnum}, $self->{size} ) = + split(/\t/, $resbody, 5); + +} + ### =head1 EXPORT