1Lucy::Docs::Tutorial::HUisgehrliCgohntterriLTbuuucttyoe:rd:iDaPolec(rs3l:p:mDT)ouctuomreinatla:t:iHoinghlighterTutorial(3pm)
2
3
4

NAME

6       Lucy::Docs::Tutorial::HighlighterTutorial - Augment search results with
7       highlighted excerpts.
8

DESCRIPTION

10       Adding relevant excerpts with highlighted search terms to your search
11       results display makes it much easier for end users to scan the page and
12       assess which hits look promising, dramatically improving their search
13       experience.
14
15   Adaptations to indexer.pl
16       Highlighter uses information generated at index time.  To save
17       resources, highlighting is disabled by default and must be turned on
18       for individual fields.
19
20           my $highlightable = Lucy::Plan::FullTextType->new(
21               analyzer      => $easyanalyzer,
22               highlightable => 1,
23           );
24           $schema->spec_field( name => 'content', type => $highlightable );
25
26   Adaptations to search.cgi
27       To add highlighting and excerpting to the search.cgi sample app, create
28       a $highlighter object outside the hits iterating loop…
29
30           my $highlighter = Lucy::Highlight::Highlighter->new(
31               searcher => $searcher,
32               query    => $q,
33               field    => 'content'
34           );
35
36       … then modify the loop and the per-hit display to generate and include
37       the excerpt.
38
39           # Create result list.
40           my $report = '';
41           while ( my $hit = $hits->next ) {
42               my $score   = sprintf( "%0.3f", $hit->get_score );
43               my $excerpt = $highlighter->create_excerpt($hit);
44               $report .= qq|
45                   <p>
46                     <a href="$hit->{url}"><strong>$hit->{title}</strong></a>
47                     <em>$score</em>
48                     <br />
49                     $excerpt
50                     <br />
51                     <span class="excerptURL">$hit->{url}</span>
52                   </p>
53               |;
54           }
55
56   Next chapter: Query objects
57       Our next tutorial chapter, QueryObjectsTutorial, illustrates how to
58       build an “advanced search” interface using Query objects instead of
59       query strings.
60
61
62
63perl v5.38.0                    Lu2c0y2:3:-D0o7c-s2:0:Tutorial::HighlighterTutorial(3pm)
Impressum