--- title: About the search process slug: '2678' canonical_url: https://docs.coveo.com/en/2678/ collection: project-guide source_format: adoc --- # About the search process Each time a user triggers a [query](https://docs.coveo.com/en/231/) in a [search interface](https://docs.coveo.com/en/2741/), that query must go through a whole process before the results can be displayed back to the user. Having a high-level understanding of the search process will help you design your search experience. ## Search process overview The following diagram and accompanying explanations provide a fairly high-level overview of a typical search scenario. ![Querying the index steps | Coveo](https://docs.coveo.com/en/assets/images/coveo-solutions/coveo-solutions-querying-process.svg) . The user types some text in the search box and submits a new query. . The search interface, typically relying on the [Coveo Atomic library](https://docs.coveo.com/en/lcdf0264/), [builds the query](#how-queries-are-built) by combining the search keywords submitted by the user with other generated filter expressions and parameters. . The search interface sends the query to the Search API. . The Search API parses the query and determines the appropriate [query pipeline](https://docs.coveo.com/en/180/). . The Search API [routes the query](https://docs.coveo.com/en/1507/) to the appropriate query pipeline. . The query pipeline [applies various rules](https://docs.coveo.com/en/1376/) to modify the query depending on its context. . The query pipeline forwards the modified query to the [index](https://docs.coveo.com/en/204/). . The index executes the query. . The index returns the ranked query response to the Search API. . The Search API builds the JSON query response (for example, populates the results array, evaluates the query duration, etc.). . The Search API sends the query response to the search interface. . The search interface processes the query response and notifies its components (for example, result list, [facet](https://docs.coveo.com/en/198/), etc.) that the query was successful. . Affected components update themselves (for example, the result list renders the query results, facets adjust their values and numbers, etc.). ## How queries are built As you may have inferred from the second step of the [above diagram and explanations](#search-process-overview), a query typically contains far more than the keywords entered by the user (i.e, the [basic query expression (`q`)](https://docs.coveo.com/en/178/)). This means that queries can be built differently depending on the context, to yield more personalized and relevant results to different users, even when they enter the same basic query expression. The Atomic library builds the basic query expression entered in the [`atomic-search-box`](https://static.cloud.coveo.com/atomic/v3/storybook/index.html?path=/docs/atomic-search-box\--docs) component. It also builds other types of expressions based on components such as facets and sorting. In a standard Coveo-powered search implementation, a developer could complete a full project without ever having to build an expression manually. ### About query expressions In a Coveo-powered search implementation, the query that's sent to the index is made up of several discrete [query expressions](https://docs.coveo.com/en/2830/) which can be just as important as the user input. Besides the basic query expression, these can include the following: * [advanced query expression (`aq`)](https://docs.coveo.com/en/175/): generated when toggling facet values. * [constant query expression (`cq`)](https://docs.coveo.com/en/179/): often enforced to confine the scope of a search for a specific search interface. > **Note** > > [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. * [large query expression (`lq`)](https://docs.coveo.com/en/214/): typically added when using a [case deflection](https://docs.coveo.com/en/2911/)-like search interface. * [disjunction query expression (`dq`)](https://docs.coveo.com/en/190/): may be added in the query pipeline by an [Automatic Relevance Tuning (ART)](https://docs.coveo.com/en/1013/) model. The end query that's evaluated against the index is essentially `(((q && aq) || dq) && cq)`. In plain words, the index returns results which match `cq`, and either both of `q` and `aq`, or just `dq`. Additionally, `lq` is processed by the [Intelligent Term Detection (ITD)](https://docs.coveo.com/en/207/) feature to inject relevant keywords in `q`. **Example** A customer searches for a snowboard on a commerce search page, so the `q` part of the combined query expression is `snowboard`. The customer interacts with the **Price** facet to select prices under $300, so the `aq` is `pass:q[@price<=300]`. The ART model on the assigned query pipeline has learned that customers were often interested in purchasing a particular snowboard (for example, result item) with a `permanentid` value of `z0f0rcprlia27`, so the `dq` is `@permanentid=z0f0rcprlia27`. This results in the following combined query expression: ```text ((snowboard AND @price<=300) OR @permanentid=z0f0rcprlia27) ``` > **Notes** > > * All query expressions rely on the [Coveo query syntax](https://docs.coveo.com/en/181/). > Understand this syntax before building your own set of expressions. > > * If you require more customization, there are various non-expression parameters that can be applied [directly through the Search API](https://docs.coveo.com/en/13#tag/Search-V2/operation/searchUsingPost) when creating a query. ### Using query expressions to filter at query time A common use of expressions is filtering at query time. This is a recommended strategy to reduce the scope of certain search pages or search driven listing pages. **Example** 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. The constant query expression in every query sent from that interface is `NOT (@source=="Marketing")`. The [Search API](https://docs.coveo.com/en/52/) only returns results which have the right `@source` field. > **Notes** > > * The index must be clean of unwanted items before filtering at query time. > You can also [filter at indexing time](https://docs.coveo.com/en/2721#further-refine-or-enhance-content-using-indexing-pipeline-extensions). > > * While you can define filter expressions directly in the code of your search interface, a more flexible approach is to create query pipeline [filter rules](https://docs.coveo.com/en/3410/). > You'll learn [more about query pipelines](https://docs.coveo.com/en/2757/) in the **Tune relevance** section of the [Coveo Platform implementation guide](https://docs.coveo.com/en/2648/). ## Authenticating An index can contain publicly accessible items as well as items that only specific users can see, [in accordance with the original repository permission system](https://docs.coveo.com/en/1779#same-users-and-groups-as-in-your-content-system). When querying the index, the Search API only returns the result items that the user is allowed to access. It's therefore important that you generate the [proper access token](https://docs.coveo.com/en/1749/) for your users. In a search interface that only displays public content, the access token can just consist of a public API key. However, a [search token](https://docs.coveo.com/en/1346/) must be generated server-side in a search interface that displays items according to a permission model. This is done using an [authenticated search API key](https://docs.coveo.com/en/1718#create-an-api-key), which should never be exposed publicly. Use the [appropriate method](https://docs.coveo.com/en/1369/) to add authentication to your search page. > **Note** > > Even in a non-secured search page, you may want to consider using the search token authentication, as search tokens can enforce a filter expression, [search hub](https://docs.coveo.com/en/1342/), and query pipeline. ## What's next? The [Leverage the Coveo Atomic library](https://docs.coveo.com/en/2677/) article explains how to implement your search interfaces using the [Atomic library](https://docs.coveo.com/en/lcdf0264/).