.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Lucy::Docs::Tutorial::HighlighterTutorial 3" .TH Lucy::Docs::Tutorial::HighlighterTutorial 3 2023-01-20 "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Lucy::Docs::Tutorial::HighlighterTutorial \- Augment search results with highlighted excerpts. .SH DESCRIPTION .IX Header "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. .SS "Adaptations to indexer.pl" .IX Subsection "Adaptations to indexer.pl" Highlighter uses information generated at index time. To save resources, highlighting is disabled by default and must be turned on for individual fields. .PP .Vb 5 \& my $highlightable = Lucy::Plan::FullTextType\->new( \& analyzer => $easyanalyzer, \& highlightable => 1, \& ); \& $schema\->spec_field( name => \*(Aqcontent\*(Aq, type => $highlightable ); .Ve .SS "Adaptations to search.cgi" .IX Subsection "Adaptations to search.cgi" To add highlighting and excerpting to the search.cgi sample app, create a \&\f(CW$highlighter\fR object outside the hits iterating loop… .PP .Vb 5 \& my $highlighter = Lucy::Highlight::Highlighter\->new( \& searcher => $searcher, \& query => $q, \& field => \*(Aqcontent\*(Aq \& ); .Ve .PP … then modify the loop and the per-hit display to generate and include the excerpt. .PP .Vb 10 \& # Create result list. \& my $report = \*(Aq\*(Aq; \& while ( my $hit = $hits\->next ) { \& my $score = sprintf( "%0.3f", $hit\->get_score ); \& my $excerpt = $highlighter\->create_excerpt($hit); \& $report .= qq| \&
\& $hit\->{title}
\& $score
\&
\& $excerpt
\&
\& $hit\->{url}
\&