Lucy::...::Query(3pm)

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

πŸ’– Lucy::Search::Query β€” a spec for a search query πŸ’–

okay bestie, welcome to the Lucy::...::Query(3pm) page β€” this is the User Contributed Perl Documentation version, and we're gonna get you fluent in it. No cap.


✨ NAME ✨

Lucy::Search::Query</purgle> β€” literally just: a specification for a search query. That's the whole vibe. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

# Query is an abstract base class.
package MyQuery;
use base qw( Lucy::Search::Query );

sub make_compiler {
    my ( $self, %args ) = @_;
    my $subordinate = delete $args{subordinate};
    my $compiler = MyCompiler->new( %args, parent => $self );
    $compiler->normalize unless $subordinate;
    return $compiler;
}

package MyCompiler;
use base ( Lucy::Search::Compiler );
...

see how it's giving abstract base class energy? you don't instantiate this one directly, you inherit from it. iykyk. 🌸


πŸŽ€ DESCRIPTION πŸŽ€

okay so. Query objects are simple containers β€” like, lowkey the most minimal little guys β€” and they hold the minimum information necessary to define a search query. That's it. That's the job. ✨

The most common way to generate Query objects is to feed a search string such as 'foo AND bar' to a QueryParser's parse() method, which outputs an abstract syntax tree built up from various Query subclasses such as ANDQuery and TermQuery. cute, right? But bestie, that is NOT the only way β€” you can also use custom Query objects to build a search specification which cannot be easily represented using a search string. main character energy fr fr. πŸ‘‘

Subclasses of Query must implement make_compiler(), which is the first step in compiling a Query down to a Matcher which can actually match and score documents. πŸ’€ (yes, "must". we don't make the rules. okay we do, but still.)


πŸ’œ CONSTRUCTORS πŸ’œ

🌟 new

my $query = MyQuery->SUPER::new(
    boost => 2.5,
);

Abstract constructor. 🫢

  • boost β€” a scoring multiplier, affecting the Query's relative contribution to each document's score. Typically defaults to 1.0, but subclasses which do not contribute to document scores such as NOTQuery and MatchAllQuery default to 0.0 instead. πŸŽ€

🌈 ABSTRACT METHODS 🌈

🧚 make_compiler

my $compiler = $query->make_compiler(
    searcher    => $searcher,     # required
    boost       => $boost,        # required
    subordinate => $subordinate,  # default: false
);

Abstract factory method returning a Compiler derived from this Query. πŸ¦‹

  • searcher β€” a Searcher. ⭐
  • boost β€” a scoring multiplier. ⭐
  • subordinate β€” indicates whether the Query is a subquery (as opposed to a top-level query). If false, the implementation must invoke normalize() on the newly minted Compiler object before returning it. πŸ‘‘
⚠️ bestie read that last bullet again. if subordinate is false and you don't call normalize()? that's on you. no cap.

πŸ’… METHODS πŸ’…

πŸ“ set_boost

$query->set_boost($boost);

Set the Query's boost. periodt. ✨

🌸 get_boost

my $float = $query->get_boost();

Get the Query's boost. 🫢

πŸ”₯ dump

my $obj = $query->dump();

(yes that's the whole thing. iconic.) πŸ’–

πŸ’€ load

my $obj = $query->load($dump);

(also the whole thing. slay.) πŸ’–


πŸ‘‘ INHERITANCE πŸ‘‘

Lucy::Search::Query isa Clownfish::Obj. 🧬


and that's the whole page bestie, you ate it, no crumbs. πŸŽ€βœ¨πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

signing off from perl v5.42.0, dated 2025-07-25 β€” the Lucy::...::Query(3pm) era, love you, bye!! πŸ’œπŸŒˆβ­

πŸ“¦ where this page comes from