--- 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/) is a set of semantic rules that can be used to compose advanced [queries](https://docs.coveo.com/en/231/). In other words, it allows you to refine your [queries](https://docs.coveo.com/en/231/) using purpose-built operators. Although the [Coveo query syntax](https://docs.coveo.com/en/181/) is disabled by default in the [`atomic-searchbox`](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#operation/planSearchUsingPost) calls directly, the [query syntax](https://docs.coveo.com/en/181/) is enabled by default. The following tables list examples of different [Coveo query syntax](https://docs.coveo.com/en/181/) features that can help build more relevant [queries](https://docs.coveo.com/en/231/). These features often leverage special characters, so be sure to also read on [using special characters in queries](https://docs.coveo.com/en/2744/). ## Basic queries The following table lists examples of basic [query syntax](https://docs.coveo.com/en/181/): [%header,cols="2"] |=== |[query syntax](https://docs.coveo.com/en/181/) example |Search results |`term` |Returns all [items](https://docs.coveo.com/en/210/) containing `term`. |`term1 term2` |Returns all [items](https://docs.coveo.com/en/210/) containing both `term1` and `term2`. |[.code-text-red]`##"##term1 term2 term3##"##` |Returns all [items](https://docs.coveo.com/en/210/) containing the exact phrase between double quotes (see [Searching for a phrase](https://docs.coveo.com/en/1686/)). |[.code-text-red]`##'##term1 term2 term3##'##` |Returns all [items](https://docs.coveo.com/en/210/) containing `term1`, `term2`, and `term3`.[.footnote]^[[1](#single-quotes1)]^ |[.code-text-red]`##+##term` |Returns all [items](https://docs.coveo.com/en/210/) containing exactly `term`, not other words sharing the same root (see [Searching for an exact term](https://docs.coveo.com/en/1815/)). |[.code-text-red]`term1 #AND# term2` |Returns all [items](https://docs.coveo.com/en/210/) containing both `term1` and `term2` (see the [`AND`](https://docs.coveo.com/en/1814#and) operator). |[.code-text-red]`term1 #OR# term2` |Returns all [items](https://docs.coveo.com/en/210/) containing either `term1` or `term2` (see the [`OR`](https://docs.coveo.com/en/1814#or) operator). |[.code-text-red]`term1 #NOT# term2` [.code-text-red]`term1 ##-##term2` |Returns all [items](https://docs.coveo.com/en/210/) containing `term1` but not `term2` (see the [`NOT`](https://docs.coveo.com/en/1814#not) operator). |[.code-text-red]`term1 #NEAR:5# term2` |Returns all [items](https://docs.coveo.com/en/210/) in which `term1` and `term2` are no more than five terms apart (see the [`NEAR`](https://docs.coveo.com/en/1814#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#general-query-extensions), while double quotes [isolate phrases](https://docs.coveo.com/en/1686/). -- ## Field queries The following table lists examples of [field](https://docs.coveo.com/en/200/) [query syntax](https://docs.coveo.com/en/181/): [cols="2",options="header"] |=== |[query syntax](https://docs.coveo.com/en/181/) example |Search results |[.code-text-red]`##@##[fieldname]` |Returns all [items](https://docs.coveo.com/en/210/) with any value in the specified [field](https://docs.coveo.com/en/200/). |[.code-text-red]`##from:##name` [.code-text-red]`##to:##"firstname lastname"` |Returns all [items](https://docs.coveo.com/en/210/) with `from` or `to` [fields](https://docs.coveo.com/en/200/) containing the specified name (see [Email operators](https://docs.coveo.com/en/1814#email-operators)). |[.code-text-red]`##@title=##term` |Returns all [items](https://docs.coveo.com/en/210/) whose `title` [field](https://docs.coveo.com/en/200/) value contains `term`. |[.code-text-red]`##@date=##yesterday` |Returns all [items](https://docs.coveo.com/en/210/) whose `date` [field](https://docs.coveo.com/en/200/) value is yesterday's date. |[.code-text-red]`##@date=##2015/01/01..2015/03/31` |Returns all [items](https://docs.coveo.com/en/210/) with the `date` [field](https://docs.coveo.com/en/200/) for a range of dates. |[.code-text-red]`##pass:q[@size<=]##128` |Returns all [items](https://docs.coveo.com/en/210/) whose file `size` [field](https://docs.coveo.com/en/200/) value is less than 128 bytes (see [Value range](https://docs.coveo.com/en/1814#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/) whose `author` [field](https://docs.coveo.com/en/200/) value is either of the numbered values (see [Parentheses and comma with field queries](https://docs.coveo.com/en/1814#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/) includes special [field](https://docs.coveo.com/en/200/) operators to perform [advanced matches](https://docs.coveo.com/en/1897/). The following table lists examples of advanced [field](https://docs.coveo.com/en/200/) [query syntax](https://docs.coveo.com/en/181/): > **Note** > > Advanced [field](https://docs.coveo.com/en/200/) [queries](https://docs.coveo.com/en/231/) work only with fields that have the [**Facet** option](https://docs.coveo.com/en/1833#facet-and-multi-value-facet) enabled. [cols="2",options="header"] |=== |[query syntax](https://docs.coveo.com/en/181/) example |Search results |[.code-text-red]`@title=##'##term1 term2 term3##'##` |Returns all [items](https://docs.coveo.com/en/210/) whose `title` [field](https://docs.coveo.com/en/200/) contains `'term1`, `term2`, or `term3'`.[.footnote]^[[3](#single-quotes2)]^ |[.code-text-red]`@author ##~= "##name##"##` |Returns all [items](https://docs.coveo.com/en/210/) whose `author` [field](https://docs.coveo.com/en/200/) contains a value with a fuzzy match for `name`. |[.code-text-red]`@author ##%= "##name##"##` |Returns all [items](https://docs.coveo.com/en/210/) whose `author` [field](https://docs.coveo.com/en/200/) 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/) whose `syssite` [field](https://docs.coveo.com/en/200/) 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/) 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/) whose `title` [field](https://docs.coveo.com/en/200/) defines, but doesn't contain, `"Enterprise Search"` (see [Excludes](https://docs.coveo.com/en/1814#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#general-query-extensions), while double quotes [isolate phrases](https://docs.coveo.com/en/1686/). -- ## General query extensions The [Coveo query syntax](https://docs.coveo.com/en/181/) uses [query extensions](https://docs.coveo.com/en/1462/), which are built-in elements of the [query extension language](https://docs.coveo.com/en/1415/). > **Note** > > There are some [query extensions](https://docs.coveo.com/en/1397/) that return values instead of results. > These must be used in conjunction with other [queries](https://docs.coveo.com/en/231/) to return results. ### `$q` When using the following syntax: `term1 $q() term2` All [items](https://docs.coveo.com/en/210/) containing `term1`, `term2`, and the [basic query expression (`q`)](https://docs.coveo.com/en/178/) are returned. > **Note** > > This syntax is almost never used in the [basic query expression](https://docs.coveo.com/en/178/). For more information, see [`$q`](https://docs.coveo.com/en/1462#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/) returns all [items](https://docs.coveo.com/en/210/) and the [query extension](https://docs.coveo.com/en/1397/) adds a dynamic [field](https://docs.coveo.com/en/200/) called distance that calculates the distance between each [item](https://docs.coveo.com/en/210/) and the entered coordinates (meters). For more information, see [`$qf`](https://docs.coveo.com/en/1462#qf). ### `$qre` When using the following syntax: `$qre(expression:@sfaccountname=='MyCompany', modifier:'100')` The [query](https://docs.coveo.com/en/231/) returns all [items](https://docs.coveo.com/en/210/) and the [query extension](https://docs.coveo.com/en/1397/) boosts [items](https://docs.coveo.com/en/210/) with the `sfaccountname` [field](https://docs.coveo.com/en/200/) with the `MyCompany` value by a value of `100`. For more information, see [`$qre`](https://docs.coveo.com/en/1462#qre). ### `$qrf` When using the following syntax: `$qrf(expression:'sqrt(@sfarticleviewcount)', normalizeWeight: true)` The [query](https://docs.coveo.com/en/231/) returns all [items](https://docs.coveo.com/en/210/) and the [query extension](https://docs.coveo.com/en/1397/) boosts [items](https://docs.coveo.com/en/210/) by the square root of the value of their `sfarticleviewcount` [field](https://docs.coveo.com/en/200/). This boost is normalized to avoid completely overriding the [index](https://docs.coveo.com/en/204/) ranking. For more information, see [`$qrf`](https://docs.coveo.com/en/1462#qrf). ### `$weight` When using the following syntax: `$weight(name:'Adjacency', value:'7')` The [query](https://docs.coveo.com/en/231/) returns all [items](https://docs.coveo.com/en/210/) and the [query extension](https://docs.coveo.com/en/1397/) 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#weight). ### `$sort` When using the following syntax: `$sort(criteria: 'datedescending')` The [query](https://docs.coveo.com/en/231/) returns all [items](https://docs.coveo.com/en/210/) and the [query extension](https://docs.coveo.com/en/1397/) sorts the results by date, in descending order. For more information, see [`$sort`](https://docs.coveo.com/en/1462#sort). ### `$fold` When using the following syntax: `$fold(field:'@sysconversationsubjectid', range:'5')` The [query](https://docs.coveo.com/en/231/) returns all [items](https://docs.coveo.com/en/210/) and the [query extension](https://docs.coveo.com/en/1397/) additionally loads up to `5` child [items](https://docs.coveo.com/en/210/) that share the same value as other results for the `sysconversationsubjectid` field. For more information, see [`$fold`](https://docs.coveo.com/en/1462#fold). ### `$loadParent` When using the following syntax: `$loadParent(parent:'@permanentid', child:'@parentid')` The [query](https://docs.coveo.com/en/231/) returns all [items](https://docs.coveo.com/en/210/) and the [query extension](https://docs.coveo.com/en/1397/) additionally loads the [item](https://docs.coveo.com/en/210/) parents. An [item](https://docs.coveo.com/en/210/) is considered to be the parent of another [item](https://docs.coveo.com/en/210/) when its `permanentid` [field](https://docs.coveo.com/en/200/) value is the same as the other [item](https://docs.coveo.com/en/210/)’s `parentid` [field](https://docs.coveo.com/en/200/) value. For more information, see [`$loadParent`](https://docs.coveo.com/en/1462#loadparent). ### `$quoteVar` When using the following syntax: `$quoteVar(value: myValue)` The [query](https://docs.coveo.com/en/231/) returns `myValue` between double quotes. For more information, see [`$quoteVar`](https://docs.coveo.com/en/1462#quotevar).