Lucy::...ighter(3pm)
π Lucy::Highlight::Highlighter β the vibe check π
okay so bestie, welcome to the Lucy::Highlight::Highlighter page from the User Contributed Perl Documentation β¨ this is the glow-up artist for your search results, and honestly? it's giving main character energy π
πΈ NAME πΈ
Lucy::Highlight::Highlighter β create and highlight excerpts. periodt. π
β¨ SYNOPSIS β¨
my $highlighter = Lucy::Highlight::Highlighter->new(
searcher => $searcher,
query => $query,
field => 'body'
);
my $hits = $searcher->hits( query => $query );
while ( my $hit = $hits->next ) {
my $excerpt = $highlighter->create_excerpt($hit);
...
}
like literally that's the whole flow, bestie β build it, pull hits, excerpt each one, slay π¦
π DESCRIPTION π
The Highlighter is your girl for picking out the relevant little snippets from a document and then wrapping your search terms in highlighting tags so they pop π₯
She handles both stems and phrases correctly and efficiently β and the way she does it? using special-purpose data generated at index-time, no cap. so it's fast, it's accurate, it's iconic π₯
π CONSTRUCTORS π
π new
my $highlighter = Lucy::Highlight::Highlighter->new(
searcher => $searcher, # required
query => $query, # required
field => 'content', # required
excerpt_length => 150, # default: 200
);
Create a new Highlighter. brand new, fresh out the box π
searcherβ an object which inherits fromSearcher, such as anIndexSearcher. yes, it's required, don't skip her πqueryβ a Query object or a query string. either one, she's flexible like that π«fieldβ the name of the field from which to draw the excerpt. and bestie, listen: the field must be marked as "highlightable" (seeFieldType). no highlightable field, no excerpt. that's the rule π¨excerpt_lengthβ maximum length of the excerpt, in characters. (the example above shows150, but the default is200β iykyk π)
π METHODS π
π create_excerpt
my $string = $highlighter->create_excerpt($hit_doc);
Hand her a HitDoc object and she'll hand you back a highlighted excerpt as a string β but only if the HitDoc actually has a value for the specified "field". no value? no excerpt. simple as π«Ά
π§ encode
my $string = $highlighter->encode($text);
Encode text with HTML entities. This one is called internally by create_excerpt() for each text fragment when she's assembling an excerpt. and here's the tea: a subclass can override this if the text should be encoded differently β or not at all. your call, bestie π
β highlight
my $string = $highlighter->highlight($text);
Highlight a small section of text. by default, she prepends pre-tag and appends post-tag. This method is called internally by create_excerpt() when assembling an excerpt β so she's doing the behind-the-scenes werk π
πΈ set_pre_tag
$highlighter->set_pre_tag($pre_tag);
Setter. The default value is "<strong>". πͺ
π set_post_tag
$highlighter->set_post_tag($post_tag);
Setter. The default value is "</strong>". closing the tag, as she should π
π« get_pre_tag
my $string = $highlighter->get_pre_tag();
Accessor. π
π get_post_tag
my $string = $highlighter->get_post_tag();
Accessor. β¨
π¦ get_field
my $string = $highlighter->get_field();
Accessor. πΈ
π₯ get_excerpt_length
my $int = $highlighter->get_excerpt_length();
Accessor. π’
π get_searcher
my $searcher = $highlighter->get_searcher();
Accessor. π«Ά
π get_query
my $query = $highlighter->get_query();
Accessor. π
π get_compiler
my $compiler = $highlighter->get_compiler();
Accessor for the Lucy::Search::Compiler object derived from "query" and "searcher". she built that herself, honestly obsessed π
π INHERITANCE π
Lucy::Highlight::Highlighter isa Clownfish::Obj. family tree stays iconic π³β¨
and that's the whole page, bestie π no cap, you're now fully qualified to highlight excerpts like a main character.
perl v5.42.0 Β· 2025-07-25 Β· straight from the Lucy::...ighter(3pm) manual, wrapped up with love π mwah π
π¦ where this page comes from
- fedora 43: perl-Lucy 0.6.2-26.fc43 Β· Apache-2.0 AND MIT AND Unicode-DFS-2015
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms