--- title: About the query expression slug: '2830' canonical_url: https://docs.coveo.com/en/2830/ collection: searching-with-coveo source_format: adoc --- # About the query expression Every time a [query](https://docs.coveo.com/en/231/) is sent to a [Coveo organization](https://docs.coveo.com/en/185/) [index](https://docs.coveo.com/en/204/), the various parts of the query expression are merged into a single combined query expression which can be read as follows: ```text ((q AND lq AND aq) OR dq) AND cq ``` In other words, in order for an [item](https://docs.coveo.com/en/210/) to be returned as a query result, that item must satisfy the [constant query expression (`cq`)](https://docs.coveo.com/en/179/), along with either: * The [basic (`q`)](https://docs.coveo.com/en/178/) and [advanced (`aq`)](https://docs.coveo.com/en/175/) query expressions * The [disjunction query expression (`dq`)](https://docs.coveo.com/en/190/) 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](https://docs.coveo.com/en/414/) * [Did You Mean](https://docs.coveo.com/en/1810/) * Excerpt generation * Keyword highlighting **Example** A customer triggers a query from a customer service search interface. The query consists of the keywords `what are barca environment policies`. Therefore, the `q` part of the combined query expression has the value `what are barca environment policies`. This basic query expression returns the following search results: !["Coveo|basic-query-expression.png"](https://docs.coveo.com/en/assets/images/jsui/basic-query-expression.png) > **Note** > > In a [Coveo JavaScript Search Framework](https://docs.coveo.com/en/187/) interface, the [`Searchbox`](https://coveo.github.io/search-ui/components/searchbox.html) component disables [query syntax](https://docs.coveo.com/en/181/) on the basic query expression by default. ## 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](https://docs.coveo.com/en/198/) 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](https://docs.coveo.com/en/181/). **Example** A support agent selects the `SOLAS` and `Marine Insurance` value on the **Article Tags** facet and the `Corporate` value on the `Source` facet on a customer service search interface, which triggers a new query. The `aq` value changes to `@articletags==("Marine Insurance", "SOLAS")` and `@source== "Corporate"`. This advanced query expression returns the following search results: !["Coveo|advanced-query-expression.png"](https://docs.coveo.com/en/assets/images/jsui/advanced-query-expression.png) ## Disjunction query expression (dq) The disjunction query expression (`dq`) is typically generated by an [Automatic Relevance Tuning (ART)](https://docs.coveo.com/en/1013/) [Coveo Machine Learning (Coveo ML)](https://docs.coveo.com/en/188/) [model](https://docs.coveo.com/en/1012/) to ensure relevant items are included in the query results, regardless of matching keywords. **Example** A customer triggers a query from a customer service search interface. The ART model on the assigned [query pipeline](https://docs.coveo.com/en/180/) has learned a pattern based on the current context that agents often find the information in the article titled `What are the Different types of Maritime Regulations` useful when they initially search for `what are barca environment policies`. This article is indexed as an item in a source with the `permanentid` `aadd742687c62910d6dc8347304ec2cedfd0b06d5b4d2794a925ce5688bd.` Therefore, the `dq` is assigned the value `@permanentid=aadd742687c62910d6dc8347304ec2cedfd0b06d5b4d2794a925ce5688bd`. This disjunction query expression returns the following search results: ![Search interface showing filters and query results with disjunction query expression | Coveo](https://docs.coveo.com/en/assets/images/jsui/search-page-with-facet-values-selected.png) > **Note** > > An ART model won't attempt to populate the `dq` at all if both [**Match the query**](https://docs.coveo.com/en/l1ca1038#match-the-query) and [**Match the advanced query**](https://docs.coveo.com/en/l1ca1038#match-the-advanced-query) options are enabled. > **Important** > > 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 (for example, search scope). The results of evaluating these expressions are kept in a special index cache to avoid re-evaluating them on each query. **Example** A customer selects the value **Corporate** for the **Source** facet on the customer service search interface. The selected tab has the value `@source=="Corporate"`, so the `cq` value is also `@source=="Corporate"` until a different tab is selected. This constant query expression returns the following search results: !["Coveo|constant-query-expression.png"](https://docs.coveo.com/en/assets/images/jsui/constant-query-expression.png) > **Important** > > * The constant query expression should never be used in conjunction with the `$context` QPL object variables. > * [nested queries](https://docs.coveo.com/en/220/) should never be in the constant query expression, as they prevent caching and will slow down all queries. > * 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. ## Large query expression (lq) The [large query expression (`lq`)](https://docs.coveo.com/en/214/) is typically leveraged by case deflection and Insight Panel search interfaces to send lengthy textual data (for example, 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`). **Example** 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](https://docs.coveo.com/en/180/) uses [Intelligent Term Detection (ITD)](https://docs.coveo.com/en/207/) to extract relevant terms from the case description, based on the current context (see [How does Intelligent Term Detection (ITD) work?](https://docs.coveo.com/en/1803#how-does-intelligent-term-detection-itd-work)). ## Combined Query Expression Example A customer interacts with the search page as follows: . The customer triggers a query containing the keywords `Updating boat software`. . They interact with the **Content Type** facet, changing the advanced query expression to `@contenttype=="Article"`. . The ART model on the assigned query pipeline has learned a pattern based on the current context that customers often were interested in looking at the article titled `How to Upgrade Your Boat Software` when they searched for `Updating boat software`. This article has a `permanentid` value of `z0f0rcprlia27wg8ov6q4347f4hjnc55nzu6nl8rnzn1p56ugf1235fvhrg8`. Therefore, the `dq` is assigned the value `@permanentid=z0f0rcprlia27wg8ov6q4347f4hjnc55nzu6nl8rnzn1p56ugf1235fvhrg8` This results in the following combined query expression: ```text ((Updating boat software AND @contenttype=="Article") OR @permanentid=z0f0rcprlia27wg8ov6q4347f4hjnc55nzu6nl8rnzn1p56ugf1235fvhrg8) ``` This combined query expression returns the following search results: ![Search interface showing filters and results for updating boat software | Coveo](https://docs.coveo.com/en/assets/images/jsui/search-page-combined-query-expression.png)