About the Query Expression
About the Query Expression
Every time a query is sent to a Coveo organization index, the various parts of the query expression are merged into a single combined query expression which can be read as follows:
((q AND lq AND aq) OR dq) AND cq
In other words, in order for an item to be returned as a query result, that item must satisfy the constant query expression (cq
), along with either of:
-
The basic (
q
) and advanced (aq
) query expressions
This article explains the typical purpose of each part of the query expression.
Basic Query Expression (q)
The basic query expression (q
) typically comes directly from end-user input, such as when an end user is typing keywords in a search box.
As such, this part of the query expression can be altered by query pipeline Stop words and Thesaurus rules, and also serves as the main input for several index features such as:
-
Partial match (see Taking Advantage of the Partial Match Feature)
-
Did You Mean (see Query Correction Feature)
-
Excerpt generation
-
Keyword highlighting
-
A customer triggers a query from a customer service search interface. The query consists of the keywords
speedbit tracking heart rate
. Therefore, theq
part of the combined query expression has the valuespeedbit tracking heart rate
. -
A customer browsing products on the Books4Fun commerce site triggers a query from a search box. The query consists of the keywords
mark twain
. Therefore, theq
part of the combined query expression has the valuemark twain
.
|
Note
In a Coveo JavaScript Search Framework interface, the |
Advanced Query Expression (aq)
The advanced query expression (aq
) is typically created by client-side logic, such as when the end user interacts with facet values or similar search interface elements intended to be used as query result filters.
This part of the query expression is assumed to be code-generated, and can take full advantage of the Coveo query syntax.
-
A support agent selects the Documentation and KB Article values on the File Type facet and the Accessory value on the Product Type facet on a customer service search interface, which triggers a new query. The
aq
value changes to@filetype==("Documentation", "KB Article") @producttype=="Accessory"
. -
A customer selects the Audio Books value from the Exclude File Type facet on the Books4Fun commerce search page, which triggers a new query. As the selected facet was a Exclude File Type facet value, the
aq
value isNOT @filetype==AudioBooks
.
Disjunction Query Expression (dq)
The disjunction query expression (dq
) is typically generated by an Automatic Relevance Tuning (ART) Coveo Machine Learning (Coveo ML) model to ensure relevant items are included in the query results, regardless of matching keywords.
-
A customer triggers a query from a customer service search interface. The ART model on the assigned query pipeline has learned a pattern based on the current context that agents often found the solution to their problem on the result item with a
permanentid
value ofaadd742687c62910d6dc8347304ec2cedfd0b06d5b4d2794a925ce5688bd
. Therefore, thedq
is assigned the value@permanentid=aadd742687c62910d6dc8347304ec2cedfd0b06d5b4d2794a925ce5688bd
. -
A customer triggers a query from the Books4Fun commerce search page. The ART model on the assigned query pipeline has learned a pattern based on the current context that customers often were interested in purchasing a book (e.g., result item) with a
permanentid
value ofh0f0rcprlia27wg8ov6q4347304ec55nzu6nl8rnzn1p5ncou65fvhrg446c
. Therefore, thedq
is assigned the value@permanentid=h0f0rcprlia27wg8ov6q4347304ec55nzu6nl8rnzn1p5ncou65fvhrg446c
.
|
Note
An ART model won’t attempt to populate the |
|
The constant and disjunction query expressions should never be used for any query pipeline feature that affects the ranking of results. Instead, you should use either the basic or advanced query expressions. |
Constant Query Expression (cq)
The constant query expression (cq
) is very similar to the advanced query expression but must hold expressions that are constant for all users of a specific search interface or search tab (e.g., search scope).
The results of evaluating these expressions are kept in a special index cache to avoid re-evaluating them on each query.
-
A support agent authenticates on a customer service search interface. Their generated search token enforces the filter
NOT @source=="Marketing"
to ensure that marketing items don’t appear in their query results, so thecq
value isNOT (@source=="Marketing")
. -
A customer selects the
Shop
tab on the Books4Fun commerce search interface. The selected tab has the value@source==("Products")
, so thecq
value is@source=="Products"
until a different tab is selected.
|
|
Large Query Expression (lq)
The large query expression (lq
) is typically leveraged by case deflection and insight panel search interfaces to send lengthy textual data (e.g., a case description) along with a query.
A Coveo ML ART model with Intelligent Term Detection (ITD) enabled can extract contextually relevant keywords from the large query expression and use those keywords to refine the basic query expression (q
).
A support agent triggers a query from an insight panel search interface.
The lq
contains the case description of a customer requesting help.
The ART model on the assigned query pipeline uses Intelligent Term Detection (ITD) to extract relevant terms from the case description, based on the current context (see How Does Intelligent Term Detection (ITD) Work?).
Combined Query Expression Examples
-
A customer is on the Pro-Sports Athletics commerce search page. The customer interacts with the search page as follows:
-
The customer triggers a query containing the keywords
Blorton snowboard
.The assigned query pipeline applies a Thesaurus rule that replaces
snowboard
withsnowboard OR board
(see Thesaurus - Query Pipeline Feature). -
The customer interacts with the Price Range Facet value, changing the advanced query expression to
@price<=300
. -
The ART model on the assigned query pipeline has learned a pattern based on the current context that customers often were interested in purchasing a snowboard (e.g., result item) with a
permanentid
value ofz0f0rcprlia27wg8ov6q4347f4hjnc55nzu6nl8rnzn1p56ugf1235fvhrg8
. Therefore, thedq
is assigned the value@permanentid=z0f0rcprlia27wg8ov6q4347f4hjnc55nzu6nl8rnzn1p56ugf1235fvhrg8
This results in the following combined query expression:
((Blorton (snowboard OR board)) AND @price<=300) OR @permanentid=z0f0rcprlia27wg8ov6q4347f4hjnc55nzu6nl8rnzn1p56ugf1235fvhrg8)
-
-
A support agent is interacting with a customer service search interface to assist a customer with their Orange Technologies product. The support agent interacts with the search interface as follows:
-
The support agent triggers a query containing the keywords
piPhone crashing
. -
The support agent selects the V6 value from the piPhone Version facet, changing the advanced query expression to
@piphoneversion="V6"
. -
The support agent is authenticated on the customer service search interface, so their generated search token enforces the filter
@source=="Help"
to ensure that only support items appear in the query results, so thecq
value is@source=="Help"
. -
The ART model on the assigned query pipeline uses intelligent term detection to extract the terms
battery
andsettings
from the case description.This results in the following combined query expression:
((%~ Or([Required:60%],"piPhone crashing settings battery") ~%) AND @piphoneversion="V6")) AND @source=="Help")
-