> For the complete documentation index, see [llms.txt](https://salsa-digital.gitbook.io/govcms-site-builder/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://salsa-digital.gitbook.io/govcms-site-builder/unit-9-search-and-related-content/search-and-related-content/exercise-9-5-extend-the-search-with-facets.md).

# Exercise 9.5: Extend the search with Facets

**Facets** is a great tool to improve search UI by adding **filtering options** that the end user can use to filter the search results by category, price, location or any other similar fields. A typical use of a Facet is to allow filtering the search results by a price range on a shopping cart website, or filtering jobs based on location.

![Image of Jobs Search with facets](/files/4T4laXAmGEd7s8u3qvSf)

Our Job posting content type provides fields such as **Terms of employment**, **State/Territory** and **Agency**. Let’s add them as facets and see if that improves our search.

**Facets** module is already enabled in your training environment.

## Configure Facets

1. Go to *Administration* → *Configuration* → *Search and metadata* → **Facets**. This page has a few facet sources available. These facets were created for you by the Facets module from each of the Views in your site. As you may expand your site with more Views that use a Search API index, they all become available here.
2. Locate our Job search in the Facet source, and click **configure**:

   <img src="/files/IR4ckMjKvPW2R3op5C4G" alt="Image of Configure Jobs search facet" data-size="original">
3. Enter a unique filter key. This key will be used in the query string to identify the facet source, which avoids errors when using multiple facets. We could leave this configuration empty; in which case the Facets will use an internally generated string.

![Image of Configure Jobs search facet](/files/ppYEpJsPS2rFvaa9svdd)

## Add State/Territory facet

1. Click the **Add facet** button.
2. Select **View Jobs Search**, display Page as the **Facet Source**.
3. Select *State (field\_jobstate)* as the **Field**.
4. Enter *State/Territory* in the **Name** field. This will be used as the facet header.
5. **Save** the configuration and **configure the facet**.

   <img src="/files/cvY8hzEjyyB64JAK3C1C" alt="Image of Configure Jobs search facet" data-size="original">
6. **Widget:** List of checkboxes.
7. **Show the amount of results:** selected.
8. **List item label:** selected.

   <img src="/files/5cuzUlTd6B1y4VZYcumd" alt="Image of Configure Jobs search facet" data-size="original">
9. **Transform entity ID to label:** selected.
10. **URL alias:** state.
11. **Empty facet behaviour:** Do not display facet.
12. **Operator:** OR.

    <img src="/files/5Pknf0i7QK67a06kIQQt" alt="Image of Configure Jobs search facet" data-size="original">
13. **Sort by active state:** not selected.
14. **Sort by count:** not selected.
15. **Sort by display value:** selected.
16. **Sort order:** Ascending

    <img src="/files/57wztr8tcXMPzbVJGbdB" alt="Image of Configure Jobs search facet" data-size="original">
17. The “Sort by display value: Ascending” will ensure the taxonomy terms for the **State/Territory** will be listed alphabetically.

    Alternatively, we may enable the weight-based ordering of the facet filters to replicate the term sorting in the taxonomy vocabulary. For this to work, you unselect the “Sort by display value” above and select the “Sort by taxonomy term weight” checkbox.

    For now, leave the “Sort by display value” selected.
18. Save the configuration. This will create a block, which we have to place into the **Content top** region, so it appears to the end user.

## Place new Facet block in Content Top

1. Navigate to the *Structure* → **Block Layout**.
2. Place the State/Territory block (category Facets) into the **Content above** region.
3. Restrict the visibility of the block to the **Jobs Search** page (/jobs-search).

   <img src="/files/LVxnm2VP9eyHxQNuF2ec" alt="Image of Configure Jobs search facet" data-size="original">
4. **Save blocks** the block layout page.
5. Test your facet by navigating to the **Jobs Search** page.

![Image of Configure Jobs search facet](/files/T00MQpsrj3RZkVQULdRS)

## Create facet for Agency field

Use your experience from the previous step and create a facet for the **Agency** field. Place it as a block in the **Content Top** region.

![Image of Agency facet](/files/Xt9GHIEU2MuFOkbru73w)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://salsa-digital.gitbook.io/govcms-site-builder/unit-9-search-and-related-content/search-and-related-content/exercise-9-5-extend-the-search-with-facets.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
