| 1 | package SWISH::Prog::Result; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use base qw( SWISH::Prog::Class ); | ||
| 5 | use Carp; | ||
| 6 | |||
| 7 | our $VERSION = '0.75'; | ||
| 8 | |||
| 9 | __PACKAGE__->mk_accessors(qw( doc score )); | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | SWISH::Prog::Result - base result class | ||
| 14 | |||
| 15 | =head1 SYNOPSIS | ||
| 16 | |||
| 17 | my $results = $searcher->search( 'foo bar' ); | ||
| 18 | while (my $result = $results->next) { | ||
| 19 | printf("%4d %s\n", $result->score, $result->uri); | ||
| 20 | } | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | SWISH::Prog::Results is a base results class. It defines | ||
| 25 | the APIs that all SWISH::Prog storage backends adhere to in | ||
| 26 | returning results from a SWISH::Prog::InvIndex. | ||
| 27 | |||
| 28 | =head1 METHODS | ||
| 29 | |||
| 30 | The following methods are all accessors (getters) only. | ||
| 31 | |||
| 32 | =head2 doc | ||
| 33 | |||
| 34 | Returns a SWISH::Prog::Doc instance. | ||
| 35 | |||
| 36 | =head2 score | ||
| 37 | |||
| 38 | Returns the ranking score for the Result. | ||
| 39 | |||
| 40 | =head2 uri | ||
| 41 | |||
| 42 | =head2 mtime | ||
| 43 | |||
| 44 | =head2 title | ||
| 45 | |||
| 46 | =head2 summary | ||
| 47 | |||
| 48 | =head2 swishdocpath | ||
| 49 | |||
| 50 | Alias for uri(). | ||
| 51 | |||
| 52 | =head2 swishlastmodified | ||
| 53 | |||
| 54 | Alias for mtime(). | ||
| 55 | |||
| 56 | =head2 swishtitle | ||
| 57 | |||
| 58 | Alias for title(). | ||
| 59 | |||
| 60 | =head2 swishdescription | ||
| 61 | |||
| 62 | Alias for summary(). | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | sub uri { croak "must implement uri" } | ||
| 67 | sub mtime { croak "must implement mtime" } | ||
| 68 | sub title { croak "must implement title" } | ||
| 69 | sub summary { croak "must implement summary" } | ||
| 70 | |||
| 71 | # version 2 names for the faithful | ||
| 72 | sub swishdocpath { shift->uri } | ||
| 73 | sub swishlastmodified { shift->mtime } | ||
| 74 | sub swishtitle { shift->title } | ||
| 75 | sub swishdescription { shift->summary } | ||
| 76 | |||
| 77 | =head2 get_property( I<property> ) | ||
| 78 | |||
| 79 | Returns the stored value for I<property> for this Result. | ||
| 80 | |||
| 81 | The default behavior is to simply call a method called I<property> | ||
| 82 | on the internal doc() object. Subclasses should implement per-engine | ||
| 83 | behavior. | ||
| 84 | |||
| 85 | =cut | ||
| 86 | |||
| 87 | sub get_property { | ||
| 88 | my $self = shift; | ||
| 89 | my $propname = shift or croak "propname required"; | ||
| 90 | return $self->doc->property($propname); | ||
| 91 | } | ||
| 92 | |||
| 93 | 1; | ||
| 94 | |||
| 95 | __END__ |