Understanding 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. It thus 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)

To have this expression, you need to activate Machine Learning Intelligent Term Detection (see Activating Machine Learning Intelligent Term Detection (ITD) in Salesforce).

When Intelligent Term Detection is activated, your search context (e.g., 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, press the F12 key (or alt+ cmd + i on a 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

Recommended Articles