1Lucy::Search::Query(3)User Contributed Perl DocumentationLucy::Search::Query(3)
2
3
4
6 Lucy::Search::Query - A specification for a search query.
7
9 # Query is an abstract base class.
10 package MyQuery;
11 use base qw( Lucy::Search::Query );
12
13 sub make_compiler {
14 my ( $self, %args ) = @_;
15 my $subordinate = delete $args{subordinate};
16 my $compiler = MyCompiler->new( %args, parent => $self );
17 $compiler->normalize unless $subordinate;
18 return $compiler;
19 }
20
21 package MyCompiler;
22 use base ( Lucy::Search::Compiler );
23 ...
24
26 Query objects are simple containers which contain the minimum
27 information necessary to define a search query.
28
29 The most common way to generate Query objects is to feed a search
30 string such as Xfoo AND barX to a QueryParserXs parse() method, which
31 outputs an abstract syntax tree built up from various Query subclasses
32 such as ANDQuery and TermQuery. However, it is also possible to use
33 custom Query objects to build a search specification which cannot be
34 easily represented using a search string.
35
36 Subclasses of Query must implement make_compiler(), which is the first
37 step in compiling a Query down to a Matcher which can actually match
38 and score documents.
39
41 new
42 my $query = MyQuery->SUPER::new(
43 boost => 2.5,
44 );
45
46 Abstract constructor.
47
48 • boost - A scoring multiplier, affecting the Query's relative
49 contribution to each document's score. Typically defaults to 1.0,
50 but subclasses which do not contribute to document scores such as
51 NOTQuery and MatchAllQuery default to 0.0 instead.
52
54 make_compiler
55 my $compiler = $query->make_compiler(
56 searcher => $searcher, # required
57 boost => $boost, # required
58 subordinate => $subordinate, # default: false
59 );
60
61 Abstract factory method returning a Compiler derived from this Query.
62
63 • searcher - A Searcher.
64
65 • boost - A scoring multiplier.
66
67 • subordinate - Indicates whether the Query is a subquery (as opposed
68 to a top-level query). If false, the implementation must invoke
69 normalize() on the newly minted Compiler object before returning
70 it.
71
73 set_boost
74 $query->set_boost($boost);
75
76 Set the QueryXs boost.
77
78 get_boost
79 my $float = $query->get_boost();
80
81 Get the QueryXs boost.
82
83 dump
84 my $obj = $query->dump();
85
86 load
87 my $obj = $query->load($dump);
88
90 Lucy::Search::Query isa Clownfish::Obj.
91
92
93
94perl v5.32.1 2021-01-27 Lucy::Search::Query(3)