-
-
04 Sep 2014 00:12:31 UTC
- Distribution: Lucy
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Clone repository
- Issues
- Testers (2 / 91 / 0)
- Kwalitee
Bus factor: 1- License: apache_2_0
- Perl: v5.8.3
- Activity
24 month- Tools
- Download (1.06MB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors- The Apache Lucy Project <dev at lucy dot apache dot org>
- Dependencies
- Clownfish
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Lucy::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 for end users to scan the page and assess which hits look promising, dramatically improving their search experience.
Adaptations to indexer.pl
Lucy::Highlight::Highlighter uses information generated at index time. To save resources, highlighting is disabled by default and must be turned on for individual fields.
my $highlightable = Lucy::Plan::FullTextType->new( analyzer => $polyanalyzer, highlightable => 1, ); $schema->spec_field( name => 'content', type => $highlightable );
Adaptations to search.cgi
To add highlighting and excerpting to the search.cgi sample app, create a
$highlighter
object outside the hits iterating loop...my $highlighter = Lucy::Highlight::Highlighter->new( searcher => $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 $excerpt = $highlighter->create_excerpt($hit); $report .= qq| <p> <a href="$hit->{url}"><strong>$hit->{title}</strong></a> <em>$score</em> <br /> $excerpt <br /> <span class="excerptURL">$hit->{url}</span> </p> |; }
Next chapter: Query objects
Our next tutorial chapter, Lucy::Docs::Tutorial::QueryObjects, illustrates how to build an "advanced search" interface using Query objects instead of query strings.
Module Install Instructions
To install Lucy::Simple, copy and paste the appropriate command in to your terminal.
cpanm Lucy::Simple
perl -MCPAN -e shell install Lucy::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.