1Lucy::Docs::Tutorial::HUisgehrliCgohntterriTbuuLttuoecrdyi:aP:leD(ro3lc)sD:o:cTuumteonrtiaatli:o:nHighlighterTutorial(3)
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 loopX
29
30           my $highlighter = Lucy::Highlight::Highlighter->new(
31               searcher => $searcher,
32               query    => $q,
33               field    => 'content'
34           );
35
36       X 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 Xadvanced searchX interface using Query objects instead of
59       query strings.
60
61
62
63perl v5.32.1                      2L0u2c1y-:0:1D-o2c7s::Tutorial::HighlighterTutorial(3)
Impressum