NAME

KinoSearch::Docs::Tutorial::Highlighter - Augment search results with highlighted excerpts.

DESCRIPTION

Adding relevant excerpts with highlighted search terms to your search results display makes it much easier to scan and assess which hits look promising, radically improving the end user experience.

To add highlighting and excerpting to the search.cgi sample app via KinoSearch::Highlight::Highlighter, create a $highlighter object outside the hits iterating loop...

    my $highlighter = KinoSearch::Highlight::Highlighter->new(
        searchable => $searcher,
        query      => $q,
        field      => 'content'
    );

... then modify the loop and the per-hit display to generate and include the excerpt.

    # Create result list.
    my $report = '';
    while ( my $hit = $hits->next ) {
        my $score   = sprintf( "%0.3f", $hit->get_score );
        my $title   = encode_entities( $hit->{title} );
        my $excerpt = $highlighter->create_excerpt($hit);
        $report .= qq|
                        <p>
                            <a href="$hit->{url}"><strong>$title</strong></a>
                            <em>$score</em>
                            <br />
                            $excerpt
                            <br />
                            <span class="excerptURL">$hit->{url}</span>
                        </p>
                |;
    }

COPYRIGHT

Copyright 2008 Marvin Humphrey

LICENSE, DISCLAIMER, BUGS, etc.

See KinoSearch version 0.20.

Copyright © 2004-2008 Marvin Humphrey