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:

ParametersKeyDescriptionValue
suggestion_typeSuggestion type objectReturns the specific algorithm used for generating the suggestion.NoteIf you added a suggestion object in your request, the response automatically returns an autocomplete suggestion regardless of the <suggestion_type> you requested.keyphrasecategorytrending_categoryautocompleterecentSee suggestion types for details.

Suggestion type object

The following table describes the keys in the suggestion_type object:

ParametersKeyDescriptionSuggestion types
idstringA unique ID that corresponds to the suggested value.

You can use either the id or text for future query requests.
with_filterobjectYou see this only if a specific filter is applied to the suggestion.
filter_idstringUnique ID that corresponds to the filter value.
textstringDisplay name of the filtered item.

Suggestion types

The following are different types or algorithms for generating the suggestion

<suggestion_type>DescriptionValue
keyphraseA mix of suggestions.type_correction,autocomplete,query_expansionrelated_search
categoryCategories that contain the searched term.n/a
trending_categoryA category that is trending now.n/a
autocompleteCompletion of a keyphrase and predicting the possible search term based on earlier typed values.n/a
recentRecent search history.n/a

The following table describes the key related to theĀ suggestion response.

KeyTypeDescription
request_forArrayFields that Discover autocorrects.NoteThe response can return a modified keyphrase if you added both request_for and suggestion objects in your request.

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"
        }
    }
If you have suggestions for improving this article, let us know!