About queries

A query usually consist of one or many expressions, which are sent to the index in order to get results.

Expressions can be entered in many ways while building a query:

  • By means of the search box

  • By the configurations applied in the Interface Editor

  • By the filters and contextual editor in an Insight Panel

  • By handling JavaScript Search events to alter the query

Through these means, your expression finds itself in different parts of the query. Therefore, it becomes important to understand how to effectively form your request, as it influences the way your expressions are processed (see Query parameters).

Expression types

Original expression

This is typically the query expression entered by the user in a query box. Since this part of the query is expected to come from user input, it’s processed by the Did You Mean feature.

Invoking the parameter

&q="{term, field}"

Applying to a building/ongoing query

var value = $("#search").coveo('state', 'q');
$("#search").coveo('state', 'q', 'new value');

Advanced expression

This is the part of the query expression generated by code based on various rules, for example, the expressions generated by the use of a facet.

Invoking the parameter

&aq="{term, field}"

Applying to a building/Ongoing Query

See the JavaScript Search QueryBuilder object.

Constant expression

This part of the expression is similar to the advanced query expression. However, it’s meant to hold expressions that are constant for all users of a search interface/widget.

The results of evaluating those expressions are kept in a special index cache, to avoid re-evaluating them on each query. You must be careful not to include dynamic parts in this expression, otherwise you risk filling the cache with useless data, which might have a negative impact on performance.

Invoking the parameter

&cq="{term, field}"

Applying to a building/Ongoing Query

See the JavaScript Search QueryBuilder object.

Large expression

Coveo for Salesforce 2.38 (February 2017)

When Intelligent Term Detection is activated, your search context (for example, the Case subject) is sent in this expression. This allows Coveo Machine Learning to detect the most important words from the context and add it to the query. For more information, see lq.

Invoking the parameter

&lq="{term, field}"

Applying to a building/Ongoing Query

See the JavaScript Search QueryBuilder object.

Nested expression

This is the disjunctive part of the query expression that’s merged with the other expression parts using an OR Boolean operator. When specified, the final expression evaluated by the index ends up being (q aq cq) OR (dq).

Invoking the parameter

&dq="{term, field}"

Applying to a building/Ongoing Query

See the JavaScript Search QueryBuilder object.

Query functions

This specifies an array of function operations executed on the result to restrict the matching.

Invoking the parameter

&queryFunction=[{"function":"aFct","fieldname":"aName"}]

Applying to a building/Ongoing Query

See the JavaScript Search QueryBuilder object.

Ranking expression

This specifies an array of function operations executed on the result to alter their ranking.

Invoking the parameter

&rankingFunction=[{"expression":"anExp","normalizedWeight":"{True, False}"}]

Applying to a building/Ongoing Query

See the JavaScript Search QueryBuilder object.

Inspecting a query

To inspect these types of expressions, your best option is to use your browser developer tools. For example, in Chrome, select F12 (Windows) or Option+Command+I (Mac).

In the excerpt below, from the Network tab of a query originating of a SidePanel, you can clearly see in the AdvancedExpression (aq) the application of the contextual query entered from the Insight Panel editor. In this contextual part of the query, extensions are mainly being used as ranking expressions. Also entered from the Insight Panel editor, you can see the ConstantExpression (cq), which refers to the filters. Lastly, there are no originalExpressions, rankingFunctions, nor queryFunctions.

Another way to inspect the query would be to look at the Console tab