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:

RequestResponse
{
    "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

suggestion_type

Suggestion type object

Returns the specific algorithm used for generating the suggestion.

Note

If you added a suggestion object in your request, the response automatically returns an autocomplete suggestion regardless of the <suggestion_type> you requested.

  • keyphrase

  • category

  • trending_category

  • autocomplete

  • recent

See suggestion types for details.

Suggestion type object

The following table describes the keys in the suggestion_type object:

Parameters

Key

Description

Suggestion types

id

string

A unique ID that corresponds to the suggested value.

You can use either the id or text for future query requests.

with_filter

object

You see this only if a specific filter is applied to the suggestion.

filter_id

string

Unique ID that corresponds to the filter value.

text

string

Display name of the filtered item.

Suggestion types

The following are different types or algorithms for generating the suggestion

<suggestion_type>

Description

Value

keyphrase

A mix of suggestions.

  • type_correction,

  • autocomplete,

  • query_expansion

  • related_search

category

Categories that contain the searched term.

n/a

trending_category

A category that is trending now.

n/a

autocomplete

Completion of a keyphrase and predicting the possible search term based on earlier typed values.

n/a

recent

Recent search history.

n/a

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

Key

Type

Description

request_for

Array

Fields that Discover autocorrects.

Note

The 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:

RequestResponse
{
    "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.

RequestResponse
{
    "request_for": {
        "query": {
            "orig_keyphrase": "chacolate", 
            "keyphrase": "chocolate" 
        }
    }

Do you have some feedback for us?

If you have suggestions for improving this article,