--- trunk/Estraier.pm 2006/01/05 23:32:31 41 +++ trunk/Estraier.pm 2006/01/05 23:38:32 42 @@ -27,6 +27,10 @@ =cut +=head1 Inheritable common methods + +This methods should really move somewhere else. + =head2 _s Remove multiple whitespaces from string, as well as whitespaces at beginning or end @@ -56,6 +60,7 @@ This class implements Document which is collection of attributes (key=value), vectors (also key value) display text and hidden text. + =head2 new Create new document, empty or from draft. @@ -175,6 +180,7 @@ push @{ $self->{htexts} }, $self->_s($text); } + =head2 id Get the ID number of document. If the object has never been registred, C<-1> is returned. @@ -188,6 +194,7 @@ return $self->{id}; } + =head2 attr_names Returns array with attribute names from document object. @@ -233,6 +240,7 @@ return @{ $self->{dtexts} }; } + =head2 cat_texts Return whole text as single scalar. @@ -246,6 +254,7 @@ return join(' ',@{ $self->{dtexts} }); } + =head2 dump_draft Dump draft data from document object. @@ -278,6 +287,7 @@ return $draft; } + =head2 delete Empty document object @@ -330,6 +340,7 @@ $self ? return $self : return undef; } + =head2 set_phrase $cond->set_phrase('search phrase'); @@ -341,6 +352,7 @@ $self->{phrase} = $self->_s( shift ); } + =head2 add_attr $cond->add_attr('@URI STRINC /~dpavlin/'); @@ -353,6 +365,7 @@ push @{ $self->{attrs} }, $self->_s( $attr ); } + =head2 set_order $cond->set_order('@mdate NUMD'); @@ -364,6 +377,7 @@ $self->{order} = shift; } + =head2 set_max $cond->set_max(42); @@ -377,6 +391,7 @@ $self->{max} = $max; } + =head2 set_options $cond->set_options( SURE => 1 ); @@ -405,6 +420,7 @@ $self->{options} ||= $options->{$option}; } + =head2 phrase Return search phrase. @@ -418,6 +434,7 @@ return $self->{phrase}; } + =head2 order Return search result order. @@ -431,6 +448,7 @@ return $self->{order}; } + =head2 attrs Return search result attrs. @@ -445,6 +463,7 @@ return @{ $self->{attrs} }; } + =head2 max Return maximum number of results. @@ -460,6 +479,7 @@ return $self->{max}; } + =head2 options Return options for this condition. @@ -511,6 +531,7 @@ $self ? return $self : return undef; } + =head2 uri Return URI of result document @@ -539,6 +560,7 @@ return sort keys %{ $self->{attrs} }; } + =head2 attr Returns value of an attribute. @@ -553,6 +575,7 @@ return $self->{attrs}->{ $name }; } + =head2 snippet Return snippet from result document @@ -566,6 +589,7 @@ return $self->{snippet}; } + =head2 keywords Return keywords from result document @@ -610,6 +634,7 @@ $self ? return $self : return undef; } + =head2 doc_num Return number of documents @@ -623,6 +648,7 @@ return $#{$self->{docs}}; } + =head2 get_doc Return single document @@ -641,6 +667,7 @@ return $self->{docs}->[$num]; } + =head2 hint Return specific hint from results. @@ -697,6 +724,7 @@ $self ? return $self : return undef; } + =head2 set_url Specify URL to node server @@ -710,6 +738,7 @@ $self->{url} = shift; } + =head2 set_proxy Specify proxy server to connect to node server @@ -726,6 +755,7 @@ $self->{pxport} = $port; } + =head2 set_timeout Specify timeout of connection in seconds @@ -741,6 +771,7 @@ $self->{timeout} = $sec; } + =head2 set_auth Specify name and password for authentication to node server. @@ -757,6 +788,7 @@ $self->{auth} = $basic_auth; } + =head2 status Return status code of last request. @@ -772,6 +804,7 @@ return $self->{status}; } + =head2 put_doc Add a document @@ -838,6 +871,29 @@ ) == 200; } + +=head2 edit_doc + +Edit attributes of a document + + $node->edit_doc( $document_draft ) or die "can't edit document"; + +Return true on success or false on failture. + +=cut + +sub edit_doc { + my $self = shift; + my $doc = shift || return; + return unless ($self->{url}); + $self->shuttle_url( $self->{url} . '/edit_doc', + 'text/x-estraier-draft', + $doc->dump_draft, + undef + ) == 200; +} + + =head2 shuttle_url This is method which uses C to communicate with Hyper Estraier node