--- trunk/Estraier.pm 2006/01/05 13:55:06 20 +++ trunk/Estraier.pm 2006/01/05 23:00:22 40 @@ -272,8 +272,8 @@ $draft .= "\n"; - $draft .= join("\n", @{ $self->{dtexts} }) . "\n"; - $draft .= "\t" . join("\n\t", @{ $self->{htexts} }) . "\n"; + $draft .= join("\n", @{ $self->{dtexts} }) . "\n" if ($self->{dtexts}); + $draft .= "\t" . join("\n\t", @{ $self->{htexts} }) . "\n" if ($self->{htexts}); return $draft; } @@ -478,16 +478,16 @@ package Search::Estraier::ResultDocument; -use Carp qw/confess croak/; +use Carp qw/croak/; -use Search::Estraier; -our @ISA = qw/Search::Estraier/; +#use Search::Estraier; +#our @ISA = qw/Search::Estraier/; =head1 Search::Estraier::ResultDocument =head2 new - my $doc = new Search::HyperEstraier::ResultDocument( + my $rdoc = new Search::HyperEstraier::ResultDocument( uri => 'http://localhost/document/uri/42', attrs => { foo => 1, @@ -511,44 +511,89 @@ $self ? return $self : return undef; } +=head2 uri +Return URI of result document -package Search::Estraier::Master; + print $rdoc->uri; -use Carp; +=cut -=head1 Search::Estraier::Master +sub uri { + my $self = shift; + return $self->{uri}; +} -Controll node master. This requires user with administration priviledges. + +=head2 attr_names + +Returns array with attribute names from result document object. + + my @attrs = $rdoc->attr_names; =cut -{ - package RequestAgent; - our @ISA = qw(LWP::UserAgent); +sub attr_names { + my $self = shift; + croak "attr_names return array, not scalar" if (! wantarray); + return sort keys %{ $self->{attrs} }; +} - sub new { - my $self = LWP::UserAgent::new(@_); - $self->agent("Search-Estraier/$Search::Estraer::VERSION"); - $self; - } +=head2 attr - sub get_basic_credentials { - my($self, $realm, $uri) = @_; -# return ($user, $password); - } +Returns value of an attribute. + + my $value = $rdoc->attr( 'attribute' ); + +=cut + +sub attr { + my $self = shift; + my $name = shift || return; + return $self->{attrs}->{ $name }; } +=head2 snippet +Return snippet from result document -=head2 new + print $rdoc->snippet; -Create new connection to node master. +=cut - my $master = new Search::Estraier::Master( - url => 'http://localhost:1978', - user => 'admin', - passwd => 'admin', +sub snippet { + my $self = shift; + return $self->{snippet}; +} + +=head2 keywords + +Return keywords from result document + + print $rdoc->keywords; + +=cut + +sub keywords { + my $self = shift; + return $self->{keywords}; +} + + +package Search::Estraier::NodeResult; + +use Carp qw/croak/; + +#use Search::Estraier; +#our @ISA = qw/Search::Estraier/; + +=head1 Search::Estraier::NodeResult + +=head2 new + + my $res = new Search::HyperEstraier::NodeResult( + docs => @array_of_rdocs, + hits => %hash_with_hints, ); =cut @@ -558,14 +603,297 @@ my $self = {@_}; bless($self, $class); - foreach my $p (qw/url user passwd/) { - croak "need $p" unless ($self->{$p}); + foreach my $f (qw/docs hints/) { + croak "missing $f for ResultDocument" unless defined($self->{$f}); } $self ? return $self : return undef; } +=head2 doc_num + +Return number of documents + + print $res->doc_num; +=cut + +sub doc_num { + my $self = shift; + return $#{$self->{docs}}; +} + +=head2 get_doc + +Return single document + + my $doc = $res->get_doc( 42 ); + +Returns undef if document doesn't exist. + +=cut + +sub get_doc { + my $self = shift; + my $num = shift; + croak "expect number as argument" unless ($num =~ m/^\d+$/); + return undef if ($num < 0 || $num > $self->{docs}); + return $self->{docs}->[$num]; +} + +=head2 hint + +Return specific hint from results. + + print $rec->hint( 'VERSION' ); + +Possible hints are: C, C, C, C, C, C, +C