The suggestion response object
You get a response suggestion JSON object in a Sitecore Discover Search and Recommendation response if you send a suggestion object in the request. The response returns suggestions on your query based on different algorithms like autocomplete and query expansion.
The following shows the basic structure of the suggestion object in a response:
{
"suggestion": {
"<suggestion_type>": {
"value": [{
"id": "<suggestion_value_id>",
"text": "<display_text>,
"in_content": "<content_type>",
},
"with_filter": {
"filter_id": "<filter_value_id>",
"text": "<display_text>,
"min": 1,
"max": 10
}
}]
}
}
}Keys
Depending on your request you might see some or all response keys.
The following table describes the keys in the suggestion response object:
|
Parameters |
Key |
Description |
Value |
|---|---|---|---|
|
|
Returns the specific algorithm used for generating the suggestion. Note If you added a |
See suggestion types for details. |
Suggestion type object
The following table describes the keys in the suggestion_type object:
|
Parameters |
Key |
Description |
Suggestion types |
|---|---|---|---|
|
|
string |
A unique ID that corresponds to the suggested value. You can use either the | |
|
|
object |
You see this only if a specific filter is applied to the | |
|
|
string |
Unique ID that corresponds to the filter value. | |
|
|
string |
Display name of the filtered item. |
Suggestion types
The following are different types or algorithms for generating the suggestion
|
<suggestion_type> |
Description |
Value |
|---|---|---|
|
|
A mix of suggestions. |
|
|
|
Categories that contain the searched term. |
n/a |
|
|
A category that is trending now. |
n/a |
|
|
Completion of a |
n/a |
|
|
Recent search history. |
n/a |
Related key
The following table describes the key related to the suggestion response.
|
Key |
Type |
Description |
|---|---|---|
|
|
Array |
Fields that Discover autocorrects. Note The response can return a modified |
Example
The following code is an example of a response with a keyphrase suggestion using query_expansion:
{
"suggestion": {
"query_expansion": {
"value": [{
"id": "pkel1Q",
"text": "Men's Shirt",
"in_content": "product"
},
{
"id": "msa2fwS",
"text": "Men's Styles",
"in_content": "article",
"with_filter": {
"filter_id": "clothing_id123",
"text": "Clothing"
}
}]
}
}
}The next example shows a response that returns an autocorrected keyphrase from the original misspelled search term. This applies if a suggestion object is added to the request.
{
"request_for": {
"query": {
"orig_keyphrase": "chacolate",
"keyphrase": "chocolate"
}
}