Lucy::...ighter(3pm)

πŸ“¦
version 0.6.2 Β· 2 versions
, in fedora 43

πŸ’– 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 from Searcher, such as an IndexSearcher. 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" (see FieldType). no highlightable field, no excerpt. that's the rule 🚨
  • excerpt_length β€” maximum length of the excerpt, in characters. (the example above shows 150, but the default is 200 β€” 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