The filter request object

You can add a filter JSON object in a Sitecore Discover Search and Recommendation request to limit the types of content and facets you want returned. The value of the filter object is a value object. The value of the value object is a list containing either a <facet_id> or a <range_filter.

The following shows the structure of a filter object in a request:

RequestResponse
{
    "filter": {
	"<facet_type>": {
             "value": ["<filter_id>"]
	}
}
}

Keys

The following table describes the keys that the filter object contains.

Key

Type

Description

Value

<facet_type>

Filter type object

Required.

The filters you want to apply to the request.

  • brand

  • category_names

  • price

  • rating

Note

The brand, category_names, price, and rating facet types are default and come with all implementations. You can define additional facet types that are specific to your industry when you do the initial data feed.

Filter type object

The following table describes the key in the Filter type object:

Key

Type

Description

Value

value

array

Required.

A list that contains the <filter_id>.

  • <facet_id> - the ID returned by a facet query.

  • <range_filter> - For a number filter, pass a an object that contains min and max keys to represent a range. For a text filter, pass the exact value of the facet.

Example

The following example uses the exact values for a text filter (gender) and a range for a number filter (price):

RequestResponse
{
    "context": {
        "page": {
            "uri": "/mylandingpage"
        }
    },
    "widget": {
        "all": true
    },
    "facet": {
        "all": true
    },
    "filter": {
        "genders": {
            "value": [
                "unisex"
            ]
        },
        "price": {
            "value": [
                {
                    "min": 7,
                    "max": 70
                }
            ]
        }
    },
    "content": {
        "product": {}
    }
}

The following example uses the facet_id for a text filter (gender) and a number filter (price):

RequestResponse
{
    "context": {
        "page": {
            "uri": "/mylandingpage"
        }
    },
    "widget": {
        "all": true
    },
    "facet": {
        "all": true
    },
    "filter": {
        "genders": {
            "value": [
                "facet_iddW5pc2V4"
            ]
        },
        "price": {
            "value": [
                "facet_ideyJtYXgiOjkwLCJtaW4iOjcwfQ=="
            ]
        }
    },
    "content": {
        "product": {}
    }
}

Do you have some feedback for us?

If you have suggestions for improving this article,