LucyX:...:Filter(3pm)
π LucyX::Search::Filter π
okay bestie, so this is a page from the User Contributed Perl Documentation for LucyX::Search::Filter β it's a Perl 3pm manual page and it's literally the blueprint for building a caching filter out of a Query. come sit with me, we're gonna get you fluent in this. π«Ά
β¨ NAME β¨
LucyX::Search::Filter β bestie, this builds a caching filter based on the results of a Query. that's the whole vibe. it's giving "filter, but make it remembered." π
β¨ SYNOPSIS β¨
okay so here's how you'd actually use it β pre-building one filter per category so you can reuse them, then ANDing the user's query with whichever filter matches:
my %category_filters;
for my $category (qw( sweet sour salty bitter )) {
my $cat_query = Lucy::Search::TermQuery->new(
field => 'category',
term => $category,
);
$category_filters{$category} = LucyX::Search::Filter->new(
query => $cat_query,
);
}
while ( my $cgi = CGI::Fast->new ) {
my $user_query = $cgi->param('q');
my $filter = $category_filters{ $cgi->param('category') };
my $and_query = Lucy::Search::ANDQuery->new;
$and_query->add_child($user_query);
$and_query->add_child($filter);
my $hits = $searcher->hits( query => $and_query );
...
}
see how the filters are built once outside the loop? that's the whole point, that's the slay. π
β¨ DESCRIPTION β¨
so a Filter is a Lucy::Search::Query subclass (yes, it's in the family π) and you use it to filter the results of another Query.
the effect? very similar to just using the wrapped inner query directly β BUT. and this is the important part, bestie. there are two important differences:
- a Filter does not contribute to the score of the documents it matches. zero. nada. it's not here for points, it's here to filter. π
- a Filter caches its results, so it's way more efficient if you're gonna use it more than once. reusing it? iconic. not reusing it? why would you. π
and if you want the logically equivalent results to the Filter but you wanna skip the caching? okay so β substitute the wrapped query, but useset_boost()to set its"boost"to0. that's the swap. no cap. β
β¨ METHODS β¨
πΈ new
my $filter = LucyX::Search::Filter->new(
query => $query;
);
Constructor, bestie. it takes one hash-style parameter, "query", and that has to be an object belonging to a subclass of Lucy::Search::Query. that's the whole rule. π
π BUGS π
okay so this is the one that hurts: Filters do not cache when they're used in a search cluster with LucyX::Remote's SearchServer and SearchClient. π₯²
like. the caching? gone. in that specific setup. tragic, honestly, but at least you know now. π
and that's the page, bestie! this one shipped as perl v5.42.0, dated 2025-07-25 β go forth and filter, you absolute main character. π¦β¨π
π¦ 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