Boolean Operators
Boolean Operators for use with Haven OnDemand text indexes.

Boolean Operators

Operator Description Example
AND Both terms must occur. cat AND dog
NOT The first term must occur, but not the second term. dog NOT wolf
OR One of the terms must occur, but not necessarily both. collie OR sheepdog

Proximity Operators

Operator Description Example
NEARN The terms must occur within N words of each other. fish NEAR3 chips
Matches "fish and chips" and "chips and freshly caught fish", but not "fish is sometimes battered and fried, and served with chips".
DNEARN The terms must occur within N words of each other, in the specified order. fish DNEAR3 chips
Matches "fish and chips" and "fish and fresh cut chips", but not "chips and fish".
BEFORE Both terms must occur, and the first term must occur earlier in the document than the second term. cat BEFORE nap
AFTER Both terms must occur, and the first term must occur later in the document than the second term. Labrador AFTER Canada

Note: Proximity matches do not count stop words. For example, fish DNEAR1 chips matches both "fish chips" and "fish and chips", because and is a stop word.


Brackets

You can use parentheses () to define the order in which to apply Boolean and proximity operators. The API evaluates the expression inside the brackets first, and then the expression outside the brackets.

For example:

(fish OR pie) AND (chips OR mash)

Matches documents that contain any of the following term combinations:

fish chips fish mash
pie chips pie mash
fish pie chips fish pie mash
fish chips mash pie chips mash
fish pie chips mash  

Field Restrictions

You can specify field restrictions for text queries to specify that the query text must occur in a specified Index field (see Index Field Types). For example, you might want to return results where your query term occurs in the title, rather than in the body of the text. To specify that a query term must occur in a specific field, use the following syntax:

QueryTerm:FieldName

For example:

Football:title

This specifies that the term Football must occur in the title field of a result.

You can specify multiple fields by separating them with colons. For example:

Football:title:wikipedia_alias

This specifies that the term Football must occur in the title or wikipedia_alias field of a result.

For information about the fields available in the Haven OnDemand public data sets, see Public Data Sets.