Mailing List Archive

Re: Simple->create_excerpt (was: Subclassable Highlighter)
On Jan 30, 2008, at 5:18 PM, Marvin Humphrey wrote:

> Another possibility is to add an "excerpt_field" param to
> Simple::search, and automatically inserts an "excerpt" member into
> the Doc.
>
> $simple->search(
> query => 'foo bar',
> excerpt_field => 'body',
> );
> while ( my $hit = $simple->fetch_hit ) {
> print qq|
> <p>
> <strong>$hit->{title}</strong><br />
> $hit->{excerpt}
> </p>
> |;
> }
>
> I'm not really enthused about either of those, because Simple's
> methods should always resemble the related behaviors of regular KS
> as closely as possible.

How about making excerpt_field part of the constructor? Then we have
this:

my $simple = KinoSearch::Simple->new(
path => '/path/to/index',
language => 'en',
excerpt_field => 'body',
);
$simple->search(
query => 'foo bar',
);
while ( my $hit = $simple->fetch_hit ) {
print qq|
<p>
<strong>$hit->{title}</strong><br />
| . $simple->create_excerpt . qq|
</p>
|;
}

But I suppose this is starting to become KinoSearch::NotSoSimple, so
maybe we should forget about it.