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:

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

Keys

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

KeyTypeDescriptionValue
<facet_type>Filter type objectRequired.The filters you want to apply to the request.brandcategory_namespricerating
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:

KeyTypeDescriptionValue
valuearrayRequired.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):

{
    "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):

{
    "context": {
        "page": {
            "uri": "/mylandingpage"
        }
    },
    "widget": {
        "all": true
    },
    "facet": {
        "all": true
    },
    "filter": {
        "genders": {
            "value": [
                "facet_iddW5pc2V4"
            ]
        },
        "price": {
            "value": [
                "facet_ideyJtYXgiOjkwLCJtaW4iOjcwfQ=="
            ]
        }
    },
    "content": {
        "product": {}
    }
}
If you have suggestions for improving this article, let us know!