--- trunk/Estraier.pm 2006/01/04 23:10:48 19 +++ trunk/Estraier.pm 2006/01/05 15:21:29 27 @@ -476,6 +476,217 @@ } +package Search::Estraier::ResultDocument; + +use Carp qw/croak/; + +#use Search::Estraier; +#our @ISA = qw/Search::Estraier/; + +=head1 Search::Estraier::ResultDocument + +=head2 new + + my $rdoc = new Search::HyperEstraier::ResultDocument( + uri => 'http://localhost/document/uri/42', + attrs => { + foo => 1, + bar => 2, + }, + snippet => 'this is a text of snippet' + keywords => 'this\tare\tkeywords' + ); + +=cut + +sub new { + my $class = shift; + my $self = {@_}; + bless($self, $class); + + foreach my $f (qw/uri attrs snippet keywords/) { + croak "missing $f for ResultDocument" unless defined($self->{$f}); + } + + $self ? return $self : return undef; +} + +=head2 uri + +Return URI of result document + + print $rdoc->uri; + +=cut + +sub uri { + my $self = shift; + return $self->{uri}; +} + + +=head2 attr_names + +Returns array with attribute names from result document object. + + my @attrs = $rdoc->attr_names; + +=cut + +sub attr_names { + my $self = shift; + croak "attr_names return array, not scalar" if (! wantarray); + return sort keys %{ $self->{attrs} }; +} + +=head2 attr + +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 + + print $rdoc->snippet; + +=cut + +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 + +sub new { + my $class = shift; + my $self = {@_}; + bless($self, $class); + + 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