1 package Xapian
::QueryParser
;
5 Xapian::QueryParser - Parse a query string into a Xapian::Query object
9 This module turns a human readable string into something Xapian can
10 understand. The syntax supported is designed to be similar to other web
11 based search engines, so that users familiar with them don't have to learn
16 use Xapian qw/:standard/;
18 my $qp = new Xapian::QueryParser( [$database] );
19 $qp->set_stemmer(new Xapian::Stem("english"));
20 $qp->set_default_op(OP_AND);
22 $database->enquire($qp->parse_query('a NEAR word OR "a phrase" NOT (too difficult) +eh'));
30 QueryParser constructor.
32 =item set_stemmer <stemmer>
34 Set the Xapian::Stem object to be used for stemming query terms.
36 =item set_stemming_strategy <strategy>
38 Set the stemming strategy. Valid values are C<STEM_ALL>, C<STEM_SOME>,
41 =item set_stopper <stopper>
43 Set the Xapian::Stopper object to be used for identifying stopwords.
45 =item set_default_op <operator>
47 Set the default operator.
49 This operator is used to combine non-filter query items when no
50 explicit operator is used.
52 The most useful values for this are OP_OR (the default) and OP_AND.
53 OP_NEAR and OP_PHRASE can also be useful.
55 See L<Xapian> for descriptions of these constants.
59 Returns the current default operator.
61 =item set_database <database>
63 Pass a L<Xapian::Database> object which is used to check whether
64 terms exist in some situations.
66 =item parse_query <query_string> [<flags>]
68 Parses the query string according to the rules defined in the query parser
69 documentation below. You can specify certain flags to modify the
72 FLAG_BOOLEAN, FLAG_PHRASE, FLAG_LOVEHATE, FLAG_BOOLEAN_ANY_CASE,
73 FLAG_WILDCARD, FLAG_PURE_NOT, FLAG_PARTIAL, FLAG_SPELLING_CORRECTION,
74 FLAG_SYNONYM, FLAG_AUTO_SYNONYMS, FLAG_AUTO_MULTIWORD_SYNONYMS,
77 To specify multiple flags, "bitwise or" them together (with C<|>). The
78 default flags are C<FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE>
80 =item add_prefix <field> <prefix>
82 Add a term prefix mapping. E.g. $qp->add_prefix("author", "A");
84 Allows the user to search for author:orwell which will search for the term
85 "Aorwel" (assuming English stemming is in use). Multiple fields can be mapped
86 to the same prefix (so you can e.g. make title: and subject: aliases for each
90 field The user visible field name
91 prefix The term prefix to map this to
93 =item add_boolean_prefix <field> prefix
95 Add a boolean term prefix mapping, allowing the user to restrict a search with
96 a boolean filter specified in the free text query. E.g.
98 $p->add_boolean_prefix("site", "H");
100 Allows the user to restrict a search with site:xapian.org which will be
101 converted to Hxapian.org combined with the rest of the parsed query using
104 Multiple fields can be mapped to the same prefix (so you can e.g. make site:
105 and domain: aliases for each other).
108 field The user visible field name
109 prefix The term prefix to map this to
119 =item get_description
121 Returns a string describing this object.
123 =item get_corrected_query_string
125 Get the spelling-corrected query string.
127 This will only be set if FLAG_SPELLING_CORRECTION is specified when
128 QueryParser::parse_query() was last called.
130 If there were no corrections, an empty string is returned.
132 =item set_max_wildcard_expansion <limit>
134 Specify the maximum expansion of a wildcard term.
136 Note: you must also set FLAG_WILDCARD for wildcard expansion to happen.
138 Parameter limit is the maximum number of terms each wildcard in the query can
139 expand to, or 0 for no limit (which is the default).
147 https://xapian.org/docs/queryparser.html
148 https://xapian.org/docs/sourcedoc/html/classXapian_1_1QueryParser.html