The facet request object
You can add a facet object to a Sitecore Discover Search and Recommendation request to specify the type of facet and other facet properties you want in the response.
The following code sample shows the structure of the facet object in a request:
{
"all": false,
"max": 10,
"total": false,
"empty": false,
"sort": {
"type": "text",
"order": "asc"
},
"brand": {
"min_count": 1,
"max": 10,
"total": false,
"sort": {
"type": "text",
"order": "asc"
},
"in_content": "<content_type>",
"field": [
"<field_type"
],
"value": [
<facet_type_value_or_id>
]
}
}The following table describes the keys in the facet object:
|
Key |
Type |
Description |
|---|---|---|
|
|
Boolean |
Optional. Gets all facet types. Default: |
|
|
integer |
Optional. The maximum number of facet values per Use Note If you request too many facet values, you see a lag in response times. We recommend that you use Default: |
|
|
Boolean |
Optional. If Useful when you use the Default: |
|
|
Boolean |
Optional. If Default: |
|
|
Optional. Determines the sort order of the facet values. Note The facet sort object does not overwrite the The sort request object because they are independent. | |
|
|
Optional. Returns a facet type that allows users to filter by product brands. You can have more than one facet type object. | |
|
|
Optional. Returns a facet that allows users to filter by category names. You can have more than one facet type object. | |
|
|
Optional. Returns a facet that allows users to filter by price or price range. You can have more than one facet type object. | |
|
|
Optional. Returns a facet that allows users to filter by product review rating. You must specify a minimum and a maximum. You can have more than one facet type object. |
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.
Facet type object
The following table describes the keys in the facet type object:
|
Key |
Type/default value |
Description |
|---|---|---|
|
|
integer |
Optional. Minimum count of any returned facet value. Default: |
|
|
integer |
Optional. The maximum number of facet values for this Default: |
|
|
Boolean |
Optional. If Default: |
|
|
string |
Optional. The Default: |
|
|
Optional. Determines the sort order of the facet values of this facet type. This key overrides the facet | |
|
|
array of strings |
Optional. Additional fields returned in the facet value. Default: empty. |
|
|
array of strings |
Optional. Returns fixed facet values. Default: empty. |
|
|
string |
Optional. Returns facet values that match the given keyphrase. Default: empty. |
Sort object
The following table describes the keys in the sort object:
|
Key |
Type |
Description |
Value |
|---|---|---|---|
|
|
string |
Required. Whether you want to sort facets alphabetically or by the number of items that have this value. For example, a search result has five red and four blue items. If you specify the sort |
|
|
|
string |
Required. Whether you want to sort facets in an ascending or descending order. |
|
Example
The following shows an example of a facet object in a request to:
-
Return 2 facet values per
<facet_type>. -
Sort the facet values in alphabetical order.
-
For color, return
color_id_10andcolor_id_2if thecountis not equal to 0. -
For category, give 15 facet values (instead of 2) and return the facet value with a
countgreater than or equal to 5.
{
"facet": {
"max": 2,
"sort": {
"value": [
{"type": "text", "order": "asc"}
]
}
},
"colors": {
"value": ["color_id_10", "color_id_2"]
},
"category_names": {
"min_count":5,
"max": 15
}