This document describes the query syntax supported by the Xapian::QueryParser class. The syntax is designed to be similar to other web based search engines, so that users familiar with them don't have to learn a whole new syntax.
expression AND expression matches documents which are matched by both of the subexpressions.
expression OR expression matches documents which are matched by either of the subexpressions.
expression NOT expression matches documents which are matched by only the first subexpression.
expression XOR expression matches documents which are matched by one or other of the subexpressions, but not both. XOR is probably a bit esoteric.
You can control the precedence of the boolean operators using brackets.
In the query one OR two AND three
the AND takes precedence,
so this is the same as one OR (two AND three)
. You can override
the precedence using (one OR two) AND three
.
A group of terms with some marked with + and - will match documents containing all of the + terms, but none of the - terms. Terms not marked with + or - contribute towards the document rankings. You can also use + and - on phrases and on bracketed expressions.
one NEAR two NEAR three
matches documents containing those
words within 10 words of each other.
A phrase surrounded with double quotes ("") matches documents containing that exact phrase. Hyphenated words are also treated as phrases, as are cases such as filenames and email addresses (e.g. /etc/passwd or president@whitehouse.gov).
If the database has been indexed with prefixes on probabilistic terms
from certain fields, you can set up a prefix map so that the user can
search within those fields. For example author:dickens title:shop
might find documents by dickens with shop in the title. You can also specify a
prefix on a quoted phrase or on a bracketed expression.
If the databases has been indexed with capitalised words producing R-prefixed terms from the unstemmed words, then searching for a capitalised word will match the unstemmed form.
A term which ends with a dot is assumed to be already stemmed. This isn't useful for users, but omega uses it sometimes for terms added from topterms.
The QueryParser supports using a trailing '*' wildcard, which matches any
number of trailing characters, so wildc*
would match wildcard,
wildcarded, wildcards, wildcat, wildcats, etc. This feature is disabled
by default - pass Xapian::QueryParser::FLAG_WILDCARD in the flags argument
to Xapian::QueryParser::parse_query() to enable it.