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.
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 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 one NEAR two NEAR three
matches documents containing those
words within 10 words of each other. You can set the threshold to n
by using NEAR/n like so:
one NEAR/6 two
.
ADJ
ADJ
is like NEAR
but only matches if the words
appear in the same order as in the query. So one ADJ two ADJ
three
matches documents containing those three words in that order
and within 10 words of each other. You can set the threshold to n
by using ADJ/n like so:
one ADJ/6 two
.
Phrase searches
Searching within a probabilistic field
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.
Searching for proper names
Searching for already stemmed forms
Wildcards
wildc*
would match wildcard,
wildcarded, wildcards, wildcat, wildcats, etc. This feature is disabled
by default - pass Xapian::QueryParser::FLAG_WILDCARD
in the flags
argument of
Xapian::QueryParser::parse_query(query_string, flags)
to enable it, and tell the QueryParser which database to expand wildcards from
using the QueryParser::set_database(database)
method.