---
title: Query syntax
slug: '1552'
canonical_url: https://docs.coveo.com/en/1552/
collection: searching-with-coveo
source_format: adoc
---
# Query syntax

The [Coveo query syntax](https://docs.coveo.com/en/181.md) is a set of semantic rules that can be used to compose advanced [queries](https://docs.coveo.com/en/231.md).
In other words, it allows you to refine your [queries](https://docs.coveo.com/en/231.md) using purpose-built operators.

Although the [Coveo query syntax](https://docs.coveo.com/en/181.md) is disabled by default in the [`atomic-search-box`](https://static.cloud.coveo.com/atomic/v3/storybook/index.html?path=/docs/atomic-search-box\--docs) component, it can be enabled by setting the `enable-query-syntax` attribute to `true`.

When performing [Search API](https://docs.coveo.com/en/13.md#operation/planSearchUsingPost) calls directly, the [query syntax](https://docs.coveo.com/en/181.md) is enabled by default.

The following tables list examples of different [Coveo query syntax](https://docs.coveo.com/en/181.md) features that can help build more relevant [queries](https://docs.coveo.com/en/231.md).
These features often leverage special characters, so be sure to also read on [using special characters in queries](https://docs.coveo.com/en/2744.md).

## Basic queries

The following table lists examples of basic [query syntax](https://docs.coveo.com/en/181.md):

| [query syntax](https://docs.coveo.com/en/181.md) example | Search results |
|---|---|
| `term` | Returns all [items](https://docs.coveo.com/en/210.md) containing `term`. |
| `term1 term2` | Returns all [items](https://docs.coveo.com/en/210.md) containing both `term1` and `term2`. |
| [.code-text-red]`##"##term1 term2 term3##"##` | Returns all [items](https://docs.coveo.com/en/210.md) containing the exact phrase between double quotes (see [Searching for a phrase](https://docs.coveo.com/en/1686.md)). |
| [.code-text-red]`##'##term1 term2 term3##'##` | Returns all [items](https://docs.coveo.com/en/210.md) containing `term1`, `term2`, and `term3`.[.footnote]^[[1](#single-quotes1)]^ |
| [.code-text-red]`##+##term` | Returns all [items](https://docs.coveo.com/en/210.md) containing exactly `term`, not other words sharing the same root (see [Searching for an exact term](https://docs.coveo.com/en/1815.md)). |
| [.code-text-red]`term1 #AND# term2` | Returns all [items](https://docs.coveo.com/en/210.md) containing both `term1` and `term2` (see the [`AND`](https://docs.coveo.com/en/1814.md#and) operator). |
| [.code-text-red]`term1 #OR# term2` | Returns all [items](https://docs.coveo.com/en/210.md) containing either `term1` or `term2` (see the [`OR`](https://docs.coveo.com/en/1814.md#or) operator). |
| [.code-text-red]`term1 #NOT# term2` [.code-text-red]`term1 ##-##term2` | Returns all [items](https://docs.coveo.com/en/210.md) containing `term1` but not `term2` (see the [`NOT`](https://docs.coveo.com/en/1814.md#not) operator). |
| [.code-text-red]`term1 #NEAR:5# term2` | Returns all [items](https://docs.coveo.com/en/210.md) in which `term1` and `term2` are no more than five terms apart (see the [`NEAR`](https://docs.coveo.com/en/1814.md#near) operator). |

--
1. Single quotes aren't handled the same as double quotes.
Single quotes are interpreted as any other alphanumeric character except in [general query extensions](https://docs.coveo.com/en/1552.md#general-query-extensions), while double quotes [isolate phrases](https://docs.coveo.com/en/1686.md).
--

## Field queries

The following table lists examples of [field](https://docs.coveo.com/en/200.md) [query syntax](https://docs.coveo.com/en/181.md):

| [query syntax](https://docs.coveo.com/en/181.md) example | Search results |
|---|---|
| [.code-text-red]`##@##[fieldname]` | Returns all [items](https://docs.coveo.com/en/210.md) with any value in the specified [field](https://docs.coveo.com/en/200.md). |
| [.code-text-red]`##from:##name` [.code-text-red]`##to:##"firstname lastname"` | Returns all [items](https://docs.coveo.com/en/210.md) with `from` or `to` [fields](https://docs.coveo.com/en/200.md) containing the specified name (see [Email operators](https://docs.coveo.com/en/1814.md#email-operators)). |
| [.code-text-red]`##@title=##term` | Returns all [items](https://docs.coveo.com/en/210.md) whose `title` [field](https://docs.coveo.com/en/200.md) value contains `term`. |
| [.code-text-red]`##NOT @author=##term` | Returns all [items](https://docs.coveo.com/en/210.md) whose `author` [field](https://docs.coveo.com/en/200.md) value doesn't contain `term` (top-level [`NOT`](https://docs.coveo.com/en/1814.md#not) operator). |
| [.code-text-red]`##@date=##yesterday` | Returns all [items](https://docs.coveo.com/en/210.md) whose `date` [field](https://docs.coveo.com/en/200.md) value is yesterday's date. |
| [.code-text-red]`##@date=##2015/01/01..2015/03/31` | Returns all [items](https://docs.coveo.com/en/210.md) with the `date` [field](https://docs.coveo.com/en/200.md) for a range of dates. |
| [.code-text-red]`##@size<=##128` | Returns all [items](https://docs.coveo.com/en/210.md) whose file `size` [field](https://docs.coveo.com/en/200.md) value is less than 128 bytes (see [Value range](https://docs.coveo.com/en/1814.md#value-range)). |
| [.code-text-red]`##@author==(##bob##,##robert##,##rob##)##` [.code-text-red]`##@author==(##"bob jones"##,##"robert smith"##,##"rob johnson"##)##` | Returns all [items](https://docs.coveo.com/en/210.md) whose `author` [field](https://docs.coveo.com/en/200.md) value is either of the numbered values (see [Parentheses and comma with field queries](https://docs.coveo.com/en/1814.md#field-parentheses-and-comma-with-field-queries)).[.footnote]^[[2](#numbered-value)]^ |

--
2. When a numbered value contains more than one term, place the value between double quotes.
--

## Advanced field queries

The [Coveo query syntax](https://docs.coveo.com/en/181.md) includes special [field](https://docs.coveo.com/en/200.md) operators to perform [advanced matches](https://docs.coveo.com/en/1897.md).
The following table lists examples of advanced [field](https://docs.coveo.com/en/200.md) [query syntax](https://docs.coveo.com/en/181.md):

> **Note**
>
> Advanced [field](https://docs.coveo.com/en/200.md) [queries](https://docs.coveo.com/en/231.md) work only with fields that have the [**Facet** option](https://docs.coveo.com/en/1833.md#facet-and-multi-value-facet) enabled.

| [query syntax](https://docs.coveo.com/en/181.md) example | Search results |
|---|---|
| [.code-text-red]`@title=##'##term1 term2 term3##'##` | Returns all [items](https://docs.coveo.com/en/210.md) whose `title` [field](https://docs.coveo.com/en/200.md) contains `'term1`, `term2`, or `term3'`.[.footnote]^[[3](#single-quotes2)]^ |
| [.code-text-red]`@author ##~= "##name##"##` | Returns all [items](https://docs.coveo.com/en/210.md) whose `author` [field](https://docs.coveo.com/en/200.md) contains a value with a fuzzy match for `name`. |
| [.code-text-red]`@author ##%= "##name##"##` | Returns all [items](https://docs.coveo.com/en/210.md) whose `author` [field](https://docs.coveo.com/en/200.md) value phonetically matches `name`. |
| [.code-text-red]`@syssite ##/= "##^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$##"##` | Returns all [items](https://docs.coveo.com/en/210.md) whose `syssite` [field](https://docs.coveo.com/en/200.md) contains a string matching an IP address regular expression (regex). |
| `filetype:artist [[@artistid] [[@albumid] songtitle:love ] genre:rock ]` | Returns all [items](https://docs.coveo.com/en/210.md) corresponding to an `artist` whose rock albums have at least one song with the word **love** in its title. |
| [.code-text-red]`@title #<># "Enterprise Search"` | Returns all [items](https://docs.coveo.com/en/210.md) whose `title` [field](https://docs.coveo.com/en/200.md) defines, but doesn't contain, `"Enterprise Search"` (see [Excludes](https://docs.coveo.com/en/1814.md#excludes)). |

--
3. Single quotes aren't handled the same as double quotes.
Single quotes are interpreted as any other alphanumeric character except in [general query extensions](https://docs.coveo.com/en/1552.md#general-query-extensions), while double quotes [isolate phrases](https://docs.coveo.com/en/1686.md).
--

## General query extensions

The [Coveo query syntax](https://docs.coveo.com/en/181.md) uses [query extensions](https://docs.coveo.com/en/1462.md), which are built-in elements of the [query extension language](https://docs.coveo.com/en/1415.md).

> **Note**
>
> There are some [query extensions](https://docs.coveo.com/en/1397.md) that return values instead of results.
> These must be used in conjunction with other [queries](https://docs.coveo.com/en/231.md) to return results.
### `$q`

When using the following syntax:

`term1 $q() term2`

All [items](https://docs.coveo.com/en/210.md) containing `term1`, `term2`, and the [basic query expression (`q`)](https://docs.coveo.com/en/178.md) are returned.

> **Note**
>
> This syntax is almost never used in the [basic query expression](https://docs.coveo.com/en/178.md).
For more information, see [`$q`](https://docs.coveo.com/en/1462.md#q).

### `$qf`

When using the following syntax:

`$qf(function:'dist(@latitude, @longitude, 46.8167, -71.2167)', fieldName: 'distance')`

The [query](https://docs.coveo.com/en/231.md) returns all [items](https://docs.coveo.com/en/210.md) and the [query extension](https://docs.coveo.com/en/1397.md) adds a dynamic [field](https://docs.coveo.com/en/200.md) called distance that calculates the distance between each [item](https://docs.coveo.com/en/210.md) and the entered coordinates (meters).

For more information, see [`$qf`](https://docs.coveo.com/en/1462.md#qf).

**Common scenario**

A `$qf` query extension uses context variables in the function argument, such as `$qf(function:'dist(@latitude, @longitude, $context[lat], $context[long])', fieldName: 'distance')`, but the distance calculation returns incorrect results.
Because the function argument of a `$qf` is parsed as a string, object access expressions such as `$context[lat]` inside the argument are not evaluated — the string is passed as-is, and the context values are not substituted into the function.
### `$qre`

When using the following syntax:

`$qre(expression:@sfaccountname=='MyCompany', modifier:'100')`

The [query](https://docs.coveo.com/en/231.md) returns all [items](https://docs.coveo.com/en/210.md) and the [query extension](https://docs.coveo.com/en/1397.md) boosts [items](https://docs.coveo.com/en/210.md) with the `sfaccountname` [field](https://docs.coveo.com/en/200.md) with the `MyCompany` value by a value of `100`.

For more information, see [`$qre`](https://docs.coveo.com/en/1462.md#qre).

### `$qrf`

When using the following syntax:

`$qrf(expression:'sqrt(@sfarticleviewcount)', normalizeWeight: true)`

The [query](https://docs.coveo.com/en/231.md) returns all [items](https://docs.coveo.com/en/210.md) and the [query extension](https://docs.coveo.com/en/1397.md) boosts [items](https://docs.coveo.com/en/210.md) by the square root of the value of their `sfarticleviewcount` [field](https://docs.coveo.com/en/200.md).
This boost is normalized to avoid completely overriding the [index](https://docs.coveo.com/en/204.md) ranking.

For more information, see [`$qrf`](https://docs.coveo.com/en/1462.md#qrf).

### `$weight`

When using the following syntax:

`$weight(name:'Adjacency', value:'7')`

The [query](https://docs.coveo.com/en/231.md) returns all [items](https://docs.coveo.com/en/210.md) and the [query extension](https://docs.coveo.com/en/1397.md) changes the ranking so that term proximity (adjacency) is more important when ordering results.

For more information, see [`$weight`](https://docs.coveo.com/en/1462.md#weight).

### `$sort`

When using the following syntax:

`$sort(criteria: 'datedescending')`

The [query](https://docs.coveo.com/en/231.md) returns all [items](https://docs.coveo.com/en/210.md) and the [query extension](https://docs.coveo.com/en/1397.md) sorts the results by date, in descending order.

For more information, see [`$sort`](https://docs.coveo.com/en/1462.md#sort).

### `$fold`

When using the following syntax:

`$fold(field:'@sysconversationsubjectid', range:'5')`

The [query](https://docs.coveo.com/en/231.md) returns all [items](https://docs.coveo.com/en/210.md) and the [query extension](https://docs.coveo.com/en/1397.md) additionally loads up to `5` child [items](https://docs.coveo.com/en/210.md) that share the same value as other results for the `sysconversationsubjectid` field.

For more information, see [`$fold`](https://docs.coveo.com/en/1462.md#fold).

### `$loadParent`

When using the following syntax:

`$loadParent(parent:'@permanentid', child:'@parentid')`

The [query](https://docs.coveo.com/en/231.md) returns all [items](https://docs.coveo.com/en/210.md) and the [query extension](https://docs.coveo.com/en/1397.md) additionally loads the [item](https://docs.coveo.com/en/210.md) parents.
An [item](https://docs.coveo.com/en/210.md) is considered to be the parent of another [item](https://docs.coveo.com/en/210.md) when its `permanentid` [field](https://docs.coveo.com/en/200.md) value is the same as the other [item](https://docs.coveo.com/en/210.md)’s `parentid` [field](https://docs.coveo.com/en/200.md) value.

For more information, see [`$loadParent`](https://docs.coveo.com/en/1462.md#loadparent).

### `$quoteVar`

When using the following syntax:

`$quoteVar(value: myValue)`

The [query](https://docs.coveo.com/en/231.md) returns `myValue` between double quotes.

For more information, see [`$quoteVar`](https://docs.coveo.com/en/1462.md#quotevar).