Coveo Cloud Query Syntax

The Coveo Cloud 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 Cloud 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.

Simple Queries

Query syntax example Search results
term Returns all items containing term
term1 term2 Returns all items containing both term1 and term2
"term1 term2 term3"1 Returns all items containing exactly the phrase between double quotes [more]
'term1 term2 term3'

Returns all items containing term1, term2, and term32

term*1 Returns all items containing term or any word starting with term [more]
+term Returns all items containing exactly term, not other words sharing the same root [more]
term1 AND term2 Returns all items containing term1 and term2 [more]
term1 OR term2 Returns all items containing either term1 or term2 [more]
term1 NOT term2
term1 -term2
Returns all items containing term1 but not term2 [more]
term1 NEAR:5 term2 Returns all items in which term1 and term2 are no more than five terms apart [more]

Note 1: JavaScript Search page developers can enable or disable wildcard match (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).

Note 2: Single quotes aren’t handled the same as double quotes, i.e., single quotes are interpreted as any other alphanumerical character except in general query expressions, while double quotes isolate phrases (see General Query Extensions and Searching for a Phrase).

Field Queries

Query syntax example Search results
@[fieldname] Returns all items with any value in the specified field
from:name
to:"firstname lastname"
Returns all items with from or to fields containing the specified name [more]
@title=term Returns all items whose title field value contains term
@date=yesterday Returns all items whose date field value is yesterday's date
@date=2015/01/01..2015/03/31 Returns all items with the date field for a range of dates
@size<=128 Returns all items whose file size field value is less than 128 bytes [more]
@author==(bob,robert,rob)

@author==("bob jones","robert smith","rob johnson")

Returns all items whose author field value is either of the enumerated values [more]1

Note 1: When an enumerated value contains more than one term, you must place the value between double quotes.

Advanced Field Queries

The Coveo query syntax includes special field operators to perform advanced matches.

Advanced field queries work only with facet fields.

Query syntax example Search results
@title *= "*term1 te?m2" Returns all items whose title field contains wildcard variants of the specified terms
@title='term1 term2 term3'

Returns all items whose title field contains 'term1, term2, or term3'1

@author ~= "name" Returns all items whose author field contains a value with a fuzzy match for name  
@author %= "name" Returns all items whose author field value phonetically matches name  
@syssite /= "^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$" Returns all items whose syssite field contains a string matching an IP address regular expression (regex)
filetype:artist [[@artistid] [[@albumid] songtitle:love ] genre:rock ]

Returns all items corresponding to an artist whose rock albums have at least one song with the word love in its title

@title <> "Enterprise Search" Returns all items whose title field defines, but doesn't contain "Enterprise Search" [more]

Note 1: Single quotes aren’t handled the same as double quotes, i.e., single quotes are interpreted as any other alphanumerical character except in general query expressions, while double quotes isolate phrases (see General Query Extensions and Searching for a Phrase).

JavaScript Search Only

Query syntax example Search results
term1 <@- +term2*=(term3) -@> term4

Returns all items containing the terms but special characters within the no-syntax block (<@- and -@>) are removed [more]

General Query Extensions

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

Query syntax example Search results
term1 $q() term2

Returns all items containing term1, term2, and the basic query expression [more]1

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

Returns all items and adds a dynamic field called distance that calculates the distance between each item and the entered coordinates, in meters [more] [more]

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

Returns all items and boosts items with the sfaccountname field with the MyCompany value by a value of 100 [more]

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

Returns all items and boosts items by the square root of the value of their sfarticleviewcount field. The boost is normalized to avoid completely overriding the index ranking [more]

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

Returns all items and changes the ranking so that term proximity (adjacency) is more important when ordering results [more]

$sort(criteria: 'datedescending')

Returns all items and sorts results by date descending [more]

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

Returns all items and additionally loads up to 5 child items that share the same value as other results for the sysconversationsubjectid field [more]

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

Returns all items and 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 [more]

Note 1: This syntax is almost never used in the basic expression.

Recommended Articles