1Lucy::Highlight::HighliUgshetrerC(o3nptmr)ibuted Perl DoLcuucmye:n:tHaitgiholnight::Highlighter(3pm)
2
3
4
6 Lucy::Highlight::Highlighter - Create and highlight excerpts.
7
9 my $highlighter = Lucy::Highlight::Highlighter->new(
10 searcher => $searcher,
11 query => $query,
12 field => 'body'
13 );
14 my $hits = $searcher->hits( query => $query );
15 while ( my $hit = $hits->next ) {
16 my $excerpt = $highlighter->create_excerpt($hit);
17 ...
18 }
19
21 The Highlighter can be used to select relevant snippets from a
22 document, and to surround search terms with highlighting tags. It
23 handles both stems and phrases correctly and efficiently, using
24 special-purpose data generated at index-time.
25
27 new
28 my $highlighter = Lucy::Highlight::Highlighter->new(
29 searcher => $searcher, # required
30 query => $query, # required
31 field => 'content', # required
32 excerpt_length => 150, # default: 200
33 );
34
35 Create a new Highlighter.
36
37 • searcher - An object which inherits from Searcher, such as an
38 IndexSearcher.
39
40 • query - Query object or a query string.
41
42 • field - The name of the field from which to draw the excerpt. The
43 field must marked as be "highlightable" (see FieldType).
44
45 • excerpt_length - Maximum length of the excerpt, in characters.
46
48 create_excerpt
49 my $string = $highlighter->create_excerpt($hit_doc);
50
51 Take a HitDoc object and return a highlighted excerpt as a string if
52 the HitDoc has a value for the specified "field".
53
54 encode
55 my $string = $highlighter->encode($text);
56
57 Encode text with HTML entities. This method is called internally by
58 create_excerpt() for each text fragment when assembling an excerpt. A
59 subclass can override this if the text should be encoded differently or
60 not at all.
61
62 highlight
63 my $string = $highlighter->highlight($text);
64
65 Highlight a small section of text. By default, prepends pre-tag and
66 appends post-tag. This method is called internally by create_excerpt()
67 when assembling an excerpt.
68
69 set_pre_tag
70 $highlighter->set_pre_tag($pre_tag);
71
72 Setter. The default value is “<strong>”.
73
74 set_post_tag
75 $highlighter->set_post_tag($post_tag);
76
77 Setter. The default value is “</strong>”.
78
79 get_pre_tag
80 my $string = $highlighter->get_pre_tag();
81
82 Accessor.
83
84 get_post_tag
85 my $string = $highlighter->get_post_tag();
86
87 Accessor.
88
89 get_field
90 my $string = $highlighter->get_field();
91
92 Accessor.
93
94 get_excerpt_length
95 my $int = $highlighter->get_excerpt_length();
96
97 Accessor.
98
99 get_searcher
100 my $searcher = $highlighter->get_searcher();
101
102 Accessor.
103
104 get_query
105 my $query = $highlighter->get_query();
106
107 Accessor.
108
109 get_compiler
110 my $compiler = $highlighter->get_compiler();
111
112 Accessor for the Lucy::Search::Compiler object derived from "query" and
113 "searcher".
114
116 Lucy::Highlight::Highlighter isa Clownfish::Obj.
117
118
119
120perl v5.38.0 2023-07-20 Lucy::Highlight::Highlighter(3pm)