# Xapian::QueryParser Syntax

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.

## Operators

### AND

expression AND expression matches documents which are matched by both of the subexpressions.

### OR

expression OR expression matches documents which are matched by either of the subexpressions.

### NOT

expression NOT expression matches documents which are matched by only the first subexpression.

### XOR

expression XOR expression matches documents which are matched by one or other of the subexpressions, but not both. XOR is probably a bit esoteric.

### Bracketed expressions

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`.

### + and -

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.

### NEAR

`one NEAR two NEAR three` matches documents containing those words within 10 words of each other.

### Phrase searches

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).

### Searching within a probabilistic field

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.

### Searching for proper names

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.

### Searching for already stemmed forms

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.