--- title: Use query ranking expressions slug: '2777' canonical_url: https://docs.coveo.com/en/2777/ collection: project-guide source_format: adoc --- # Use query ranking expressions One of the most direct ways you can influence relevance in your search solution is by designing and using [query ranking expressions (QREs)](https://docs.coveo.com/en/1472/). By default, the [index](https://docs.coveo.com/en/204/) computes a unique [ranking score](https://docs.coveo.com/en/1624/) for each [query](https://docs.coveo.com/en/231/) result [item](https://docs.coveo.com/en/210/) based on various [standard factors](https://docs.coveo.com/en/1624#index-ranking-phases) such as term frequency-inverse document frequency (TFIDF), term adjacency, and modification date. A QRE lets you further increase (or reduce) the ranking score of a specific subset of query result items by a fixed amount. You can easily design, maintain, and test QREs by creating [ranking expression](https://docs.coveo.com/en/3375/) and [featured result](https://docs.coveo.com/en/3376/) rules in a [query pipeline](https://docs.coveo.com/en/180/). You can also enforce QREs [directly in the code](https://docs.coveo.com/en/303/) of your search interface, although you should only do this if necessary. ## Use cases * Top a result for a specific query: You significantly increase the ranking score for a single item that you want to promote when the user submits a specific popular [basic query expression (`q`)](https://docs.coveo.com/en/178/). This would likely be a featured result rule in a query pipeline. * Promote new content related to a query: You slightly increase the ranking score for items containing the latest release notes of a product when the user submits the basic query expression `what's new`. * Demote content intended for another audience: You slightly reduce the ranking score for administrator-oriented documentation when the user has identified themselves as a developer. * Demote legacy content: You significantly reduce the ranking score for every item related to a legacy product, unless that product is explicitly included as a term in the basic query expression. ## Leading practices ### Use QREs for the right reasons QREs are especially useful when you need to enforce specific or temporary business rules which your [Coveo Machine Learning (Coveo ML)](https://docs.coveo.com/en/188/) [models](https://docs.coveo.com/en/1012/) couldn't otherwise deduce from natural user behavior. By increasing or decreasing the ranking scores of certain query result items under specific circumstances, you can lead a significant number of users to the most contextually-relevant content. Your [Coveo ML](https://docs.coveo.com/en/188/) models will learn from these positive outcomes and, in time, you'll be able to stop enforcing the QREs. **Example** You want to promote ACME monitors in a Coveo-powered commerce portal. In the portal's [query pipeline](https://docs.coveo.com/en/180/), you define a [ranking expression](https://docs.coveo.com/en/1472/) rule that adds a positive modifier to the ranking score for each result item whose `@brand` [field](https://docs.coveo.com/en/200/) value is `ACME` when the query contains the terms `monitor` or `screen`. ![Promoting ACME monitors](https://docs.coveo.com/en/assets/images/coveo-platform/promote-acme-monitors.png) A user accesses the commerce portal and submits the following query: `globex computer screen`. Even though the user is apparently searching for Globex-brand monitors, your ranking expression rule is likely to make ACME monitors appear higher in the result list. ### Make your QREs just specific enough Each QRE should only apply under specific circumstances. Before creating a QRE that affects most or all queries, consider whether you can improve relevance in your index itself. However, you should also avoid creating QREs that are _too_ specific. If a QRE applies to an insignificant volume of queries (such as 1 or 2 per month), it won't produce enough [data](https://docs.coveo.com/en/259/) for your [Coveo ML](https://docs.coveo.com/en/188/) models to learn from. ### Test your QREs QREs can have unexpected side-effects. When you add a new QRE rule in a query pipeline (such as a ranking expression or featured result rule), it's a good idea to use [A/B testing](https://docs.coveo.com/en/3255/) to confirm that it has the expected effect on relevance in your search solution. If so, you can go ahead and let it alter a more significant volume of queries. You may also want to set up A/B testing before you remove an existing QRE rule from a query pipeline. ### Keep as few QREs as possible QRE interactions can be complex, so it's difficult to maintain many QREs in a search solution. After a QRE has affected the behavior of a significant number of users for a long enough time, your [Coveo ML](https://docs.coveo.com/en/188/) models will adapt their output accordingly. This will often render the original QRE obsolete. When a QRE is no longer useful, you should consider removing it. ## What's next? The [Leverage Coveo Machine Learning](https://docs.coveo.com/en/2778/) article explains how to take advantage of the [Coveo ML](https://docs.coveo.com/en/188/) [Query Suggestion (QS)](https://docs.coveo.com/en/1015/) and [Automatic Relevance Tuning (ART)](https://docs.coveo.com/en/1013/) features.