Query syntax
Query syntax
The Coveo query syntax is a set of semantic rules that can be used to compose advanced queries. In other words, it allows you to refine your queries using purpose-built operators.
Although the Coveo query syntax is disabled by default in Coveo JavaScript Search interfaces, it may be enabled by an administrator or a developer through the enableQuerySyntax QueryBox
option.
If you perform Search API calls directly rather than through the Coveo JavaScript Search Framework, the query syntax is enabled by default.
You can disable it by setting the enableQuerySyntax
query parameter to false
.
The following tables list examples of different Coveo query syntax features that can help build more relevant search queries. These features often leverage special characters, so be sure to also read on using special characters in queries.
Simple Queries
Query syntax example | Search results |
---|---|
|
Returns all items containing |
|
Returns all items containing both |
|
Returns all items containing exactly the phrase between double quotes (see Searching for a Phrase). |
|
Returns all items containing |
|
Returns all items containing |
|
Returns all items containing exactly |
|
Returns all items containing |
|
Returns all items containing either |
|
Returns all items containing |
|
Returns all items in which |
Field Queries
Query syntax example | Search results |
---|---|
|
Returns all items with any value in the specified field. |
|
Returns all items with |
|
Returns all items whose |
|
Returns all items whose |
|
Returns all items with the |
|
Returns all items whose file |
|
Returns all items whose |
Advanced Field Queries
The Coveo query syntax includes special field operators to perform advanced matches.
|
Note
Advanced field queries work only with facet fields. |
Query syntax example | Search results |
---|---|
|
Returns all items whose |
|
Returns all items whose |
|
Returns all items whose |
|
Returns all items whose |
|
Returns all items whose |
|
Returns all items corresponding to an |
|
Returns all items whose |
JavaScript Search Only
Query syntax example | Search results |
---|---|
|
Returns all items containing the terms but special characters within the no-syntax block ( |
General Query Extensions
|
Note
There are some query extensions that return values instead of results which must be used in conjunction with other queries to return results (see Standard Query Extensions). |
$q
When using the following syntax:
term1 $q() term2
All items containing term1
, term2
, and the basic query expression (q
) are returned.[4]
For more information on the $q
query extension, see $q
.
$qf
When using the following syntax:
$qf(function:'dist(@latitude, @longitude, 46.8167, -71.2167)', fieldName: 'distance')
The query returns all items and the query extension adds a dynamic field called distance that calculates the distance between each item and the entered coordinates, in meters.
For more information on the $qf
query extension, see $qf
.
$qre
When using the following syntax:
$qre(expression:@sfaccountname=='MyCompany', modifier:'100')
The query returns all items and the query extension boosts items with the sfaccountname
field with the MyCompany
value by a value of 100.
For more information on the $qre
query extension, see $qre
.
$qrf
When using the following syntax:
$qrf(expression:'sqrt(@sfarticleviewcount)', normalizeWeight: true)
The query returns all items an the query extension boosts items by the square root of the value of their sfarticleviewcount
field.
The boost is normalized to avoid completely overriding the index ranking.
For more information on the $qrf
query extension, see $qrf
.
$weight
When using the following syntax:
$weight(name:'Adjacency', value:'7')
The query returns all items and the query extension changes the ranking so that term proximity (adjacency) is more important when ordering results.
For more information on the $weight
query extension, see $weight
.
$sort
When using the following syntax:
$sort(criteria: 'datedescending')
The query returns all items and the query extension sorts results by date descending.
For more information on the $sort
query extension, see $sort
.
$fold
When using the following syntax:
$fold(field:'@sysconversationsubjectid', range:'5')
The query returns all items and the query extension additionally loads up to 5 child items that share the same value as other results for the sysconversationsubjectid
field.
For more information on the $fold
query extension, see $fold
.
$loadParent
When using the following syntax:
$loadParent(parent:'@permanentid', child:'@parentid')
The query returns all items and the query extension additionally loads the item parents. Items are considered parent of another item when their permanentid
field value is the same as the other item parentid
field value.
For more information on the $loadParent
query extension, see $loadParent
.
$quoteVar
When using the following syntax:
$quoteVar(value: myValue)
The query returns myValue
between double quotes.
For more information on the $quoteVar
query extension, see $quoteVar
.
enableWildcards
option) independently from the Coveo query syntax (enableQuerySyntax
option) in the Querybox
component. Exact phrase search is always available (see Searching for a Phrase).