The facet response object
You get a facet JSON object in the Sitecore Discover Search and Recommendation response if you send a facet object in the request. The response returns the <facet_type> requested and shows the corresponding facet values according to the keys in your request.
The following code shows the basic structure of the facet object in a response:
{
"facet": {
"<facet_type>": {
"number_of_products": 2,
"total": 10,
"display_name": "<alternate_display_name>",
"value": [{
"id": "<facet_value_id>",
"text": "<display_text>",
"count": 15,
"min": 1,
"max": 10,
"in_content": "<content_type>",
"<other_fields>": "<field_value>",
"sub": [<facet_value>]
}]
},
"facet_names": [{<facet_type>}]
}Keys
Depending on your request you might see some or all response keys.
The following table describes the keys in the facet response object:
|
Key |
Type |
Description |
|---|---|---|
|
|
Returns the |
Facet type object
The following table describes the keys in the facet_type object:
|
Key |
Type |
Description |
|---|---|---|
|
|
number |
The number of products containing an attribute value with the |
|
|
number |
Total number of facet values for the |
|
|
string |
Alternate name to display the You can contact your support representative if you want the response to display a different name for the returned |
|
|
number |
A unique ID that corresponds to the facet value. You can use the |
|
|
string |
The response returns the |
|
|
number |
The minimum value in a range. The response returns this only when the |
|
|
number |
The maximum value in a range. The response returns this only when |
|
|
array |
The response returns this only when the |
|
|
array |
Determines the order of the returned facets. Each Note The order of the returned facets reflects how you explicitly configured it in the Customer Engagemenrt Console (CEC). Otherwise, you get the default order. |
Facet types
The following are default facets that 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> |
Description |
|---|---|
|
|
Filter by product brands. |
|
|
Filter by product category names. |
|
|
Filter by price or price range. |
|
|
Filter by product review rating. You must specify a |
Examples
Example 1: The following is an example of a response containing a term facet with discrete values. In the response, there are:
-
Five Red items
-
Two Blue items
-
A total of eleven types of
colors, but only two are shown
{
"facet": {
"colors": {
"number_of_products": 235,
"total": 11,
"value": [{
"id": "cr1",
"text": "Red",
"count": 5
},
{
"id": "cr2",
"text": "Blue",
"count": 2
}
]
}
}
}Example 2: The next example is a response containing a range facet where:
-
The total number of buckets is two
-
The minimum (
min) of the price range is 10 -
The maximum (
max) of the price range is 50 -
The
valuecontains the suggested buckets where:-
There are two groups of buckets
-
The first bucket is from 10 to 20
-
The second bucket is from 20 to 50
-
{
"facet": {
"price": {
"number_of_products": 27,
"total": 2,
"min": 10,
"max": 50,
"value": [{
"id": "p1",
"text": "10 - 20",
"count": 5,
"min": 10,
"max": 20
},
{
"id": "p2",
"text": "20 - 50",
"count": 2,
"min": 20,
"max": 50
}
]
}
}
}Example 3: The following is an example of a nested facet having a hierarchical structure. In this example, there are four categories:
-
Mens > Shirt
-
Mens > Pants
-
Women > Shirt
-
Women > Pants
{
"facet": {
"category_tree": {
"value": [
{
"id": "ct1",
"text": "Mens",
"count": 5,
"sub": [
{"id": "ct11", "text": "Shirt", "count": 2},
{"id": "ct12", "text": "Pants", "count": 3}
]
},
{
"id": "ct2",
"text": "Women",
"count": 2,
"sub": [
{"id": "ct21", "text": "Shirt", "count": 1},
{"id": "ct22", "text": "Pants", "count": 1}
]
}
]
}
}