# Setting up dynamic filtering

In this article, you will learn to use certain tags and fields to dynamically filter and facet your recommendation results.

You can use any combination of the different filtering mechanisms outlined below. For example, you can use category and the tag filtering to constrain the recommendation results.

**Note:** In order to leverage dynamic filtering please read our guide on configuring the filtering behavior.

All category pages already leverage dynamic filtering. As documented in our guide to tagging categories, the `nosto_category` tagging constraints Nosto to show recommendations from only the current category.

Tagging the current category is often for most retailers to add personalization to the category pages. If your store uses faceting and you would like Nosto to respect the faceting constraints, you may need to use either the attribute or tag filtering mechanisms to achieve the desired result.

### **Filtering by categories**

You can filter by categories to narrow down the recommendation results to only show products from the specified category or categories. If multiple categories are specified, the products must be in each of those categories.

```javascript
nostojs(api => {
  api.setTaggingProvider("categories", ["/Men's/Shirts"])
})
```

You can even use multiple

```javascript
nostojs(api => {
  api.setTaggingProvider("categories", ["/Men's/Shirts", "/Men's/Sale"])
})
```

**Note:** Remember to tag the categories exactly as they are tagged in your product pages. If you've omitted the leading `/Home` from your category tagging on the product pages, you'll need to tag them in a similar format here.

### Filtering by tags

You can filter by tags to narrow down the recommendation results to only show products containing the specified tag or tags. If multiple tags are specified, the products must contain all the specified tags.

```javascript
nostojs(api => {
  api.setTaggingProvider("tags", ["colorful"])
})
```

You can even use multiple

```javascript
nostojs(api => {
  api.setTaggingProvider("tags", ["colorful", "shiny"])
})
```

### Filtering by attributes

You can filter by attributes to narrow down the recommendation results to only show products containing the specified attributes. If multiple attributes are specified, the products must contain all the attributes.

```javascript
nostojs(api => {
  api.setTaggingProvider("customFields", { gender: ["male"] })
});
```

You can even use multiple

```javascript
nostojs(api => {
  api.setTaggingProvider("customFields", { gender: ["male"], material: ["cotton"] })
})
```

These colon separated values are then parsed into an object with format { "key1":"value1,value2", "key2":"value1" }.

```javascript
texts.keyValueTexts(nodes)
```

The above method will receive references to all the "nosto\_custom\_field" elements. It extracts the colon separated strings and parses them to an object. For e.g. the above gender and material custom fields will be parsed to

```json
{
  "gender": "male",
  "material": "cotton"
}
```

## Dynamically reloading

If you want to refresh the recommendations with new facet constraints, the simplest way would be to update the value of the filters in the page and then reload the recommendations.

The following example illustrates a simple way of modifying the current category tagging and then using the JS API to reload the recommendations.

```javascript
nostojs(api => {
  api.setTaggingProvider("categories", ["/Shoes"])
  api.loadRecommendations()
})
```

## See also

To learn more about the `setTaggingProvider` usage, please refer to the [official API documentation](https://nosto.github.io/nosto-js/interfaces/client.API.html#settaggingprovider).

For more information on `loadRecommendations`, refer to [this](https://nosto.github.io/nosto-js/interfaces/client.API.html#loadrecommendations) API documentation


---

# Agent Instructions: 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:

```
GET https://docs.nosto.com/techdocs/apis/frontend/js-apis/recommendations/setting-up-dynamic-filtering.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
