Plucen...llector(3pm)

πŸ“¦
version 1.25 Β· 2 versions
  • 1.25 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.25 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

ok so bestie, meet Plucene::Search::HitCollector β€” the little Perl module that sits next to your searcher and gets a lil ping every time something scores. it's giving callback royalty and honestly? we're obsessed. ✨

this page lives in the 3pm section of the manual, aka the "perl modules, but make it fancy" shelf. πŸŽ€


✨ SYNOPSIS ✨

the whole vibe is: you pair it up with the IndexSearcher. like a duo. iconic behavior only. πŸ’…

# used in conjunction with the IndexSearcher

my $searcher = Plucene::Search::IndexSearcher->new($DIRECTORY);

my $hc = Plucene::Search::HitCollector->new( collect =>
    sub {
        my ($self, $doc, $score) = @_;
        ...
});

$searcher->search_hc($QUERY, $hc);

🌸 DESCRIPTION 🌸

okay so here's the tea β˜• β€” this module is used in conjunction with the IndexSearcher. and the way that it works?? every single time a document with a non-zero score gets found, the subref that the HitCollector was made with gets called. like, automatically. no cap. it just rings you up every time something juicy shows up. πŸ¦‹

no zero-score nonsense invited to the party, btw. if it scored 0, we simply don't call. πŸ’€


🧚 METHODS 🧚

new πŸ‘‘

my $hc = Plucene::Search::HitCollector->new( collect =>
    sub {
        my ($self, $doc, $score) = @_;
        ...
});

this will create a new Plucene::Search::HitCollector with the passed subref. that's it. that's the whole ritual. hand it a collect subref and boom πŸ’₯ you have yourself a HitCollector, bestie. main character energy from line one. 🫢

collect πŸ“

this is called once for every non-zero scoring document, with the document number and its score.

so like, your subref gets the doc number and the score, one call per qualifying doc, and then it's your moment to shine. ⭐

ngl this is the fun part. every non-zero scoring doc = one call. that's the whole deal, fr fr.

and that's the page, babe πŸ’œ β€” this was pulled straight from the perl v5.36.0 docs, dated 2022-12-04, filed under Plucen...llector(3pm) in the User Contributed Perl Documentation. mwah, go forth and collect hits πŸ‘‘πŸŒˆ

πŸ“¦ where this page comes from