1 package Search
::Xapian
::QueryParser
;
9 our @ISA = qw(DynaLoader);
11 # Preloaded methods go here.
13 # In a new thread, copy objects of this class to unblessed, undef values.
16 use overload
'=' => sub { $_[0]->clone() },
21 my $class = ref( $self );
22 my $copy = new2
( $self );
32 $qp->set_database(@_) if scalar(@_) == 1;
43 Search::Xapian::QueryParser - Parse a query string into a Search::Xapian::Query object
47 This module turns a human readable string into something Xapian can
48 understand. The syntax supported is designed to be similar to other web
49 based search engines, so that users familiar with them don't have to learn
54 use Search::Xapian qw/:standard/;
56 my $qp = new Search::Xapian::QueryParser( [$database] );
57 $qp->set_stemmer(new Search::Xapian::Stem("english"));
58 $qp->set_default_op(OP_AND);
60 $database->enquire($qp->parse_query('a NEAR word OR "a phrase" NOT (too difficult) +eh'));
68 QueryParser constructor.
70 =item set_stemmer <stemmer>
72 Set the Search::Xapian::Stem object to be used for stemming query terms.
74 =item set_stemming_strategy <strategy>
76 Set the stemming strategy. Valid values are C<STEM_ALL>, C<STEM_SOME>,
79 =item set_stopper <stopper>
81 Set the Search::Xapian::Stopper object to be used for identifying stopwords.
83 =item set_default_op <operator>
85 Set the default operator.
87 This operator is used to combine non-filter query items when no
88 explicit operator is used.
90 The most useful values for this are OP_OR (the default) and OP_AND.
91 OP_NEAR and OP_PHRASE can also be useful.
93 See L<Search::Xapian> for descriptions of these constants.
97 Returns the current default operator.
99 =item set_database <database>
101 Pass a L<Search::Xapian::Database> object which is used to check whether
102 terms exist in some situations.
104 =item parse_query <query_string> [<flags>]
106 Parses the query string according to the rules defined in the query parser
107 documentation below. You can specify certain flags to modify the
110 FLAG_BOOLEAN, FLAG_PHRASE, FLAG_LOVEHATE, FLAG_BOOLEAN_ANY_CASE,
111 FLAG_WILDCARD, FLAG_PURE_NOT, FLAG_PARTIAL, FLAG_SPELLING_CORRECTION,
112 FLAG_SYNONYM, FLAG_AUTO_SYNONYMS, FLAG_AUTO_MULTIWORD_SYNONYMS
114 To specify multiple flags, "bitwise or" them together (with C<|>). The
115 default flags are C<FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE>
117 =item add_prefix <field> <prefix>
119 Add a probabilistic term prefix. E.g. $qp->add_prefix("author", "A");
121 Allows the user to search for author:orwell which will search for the term
122 "Aorwel" (assuming English stemming is in use). Multiple fields can be mapped
123 to the same prefix (so you can e.g. make title: and subject: aliases for each
127 field The user visible field name
128 prefix The term prefix to map this to
130 =item add_boolean_prefix <field> prefix
132 Add a boolean term prefix allowing the user to restrict a search with a
133 boolean filter specified in the free text query. E.g.
135 $p->add_boolean_prefix("site", "H");
137 Allows the user to restrict a search with site:xapian.org which will be
138 converted to Hxapian.org combined with any probabilistic query with
141 Multiple fields can be mapped to the same prefix (so you can e.g. make site:
142 and domain: aliases for each other).
145 field The user visible field name
146 prefix The term prefix to map this to
156 =item get_description
158 Returns a string describing this object.
160 =item get_corrected_query_string
162 Get the spelling-corrected query string.
164 This will only be set if FLAG_SPELLING_CORRECTION is specified when
165 QueryParser::parse_query() was last called.
167 If there were no corrections, an empty string is returned.
169 =item set_max_wildcard_expansion <limit>
171 Specify the maximum expansion of a wildcard term.
173 Note: you must also set FLAG_WILDCARD for wildcard expansion to happen.
175 Parameter limit is the maximum number of terms each wildcard in the query can
176 expand to, or 0 for no limit (which is the default).
184 https://xapian.org/docs/queryparser.html
185 https://xapian.org/docs/sourcedoc/html/classXapian_1_1QueryParser.html