Skip to main content

Suggestion with Auto-Complete

The Suggestion with Auto-Complete API extends the standard Suggestion API by adding auto-complete functionality. This endpoint returns suggested terms, trending terms, and auto-complete suggestions based on prefix matching of the search query.

Auto-complete suggestions are generated by matching the beginning of the user's input against previously searched terms, sorted by search frequency (popularity).

API Endpoint

Method: POST

URL: https://<PA_SEARCH_END_POINT>/search/suggestion-auto-complete

Request Header

NameValue
Content-Typeapplication/json
AuthorizationBearer ACCESS_TOKEN

Request Parameters (Body)

ParameterTypeRequiredDescription
website_idstringYesClient unique website ID provided by PA.
qstringYesInput search query string. Used for prefix matching in auto-complete.
clientstringYesUnique client shortcode provided by PA.

Example Request

curl --location 'https://<PA_SEARCH_END_POINT>/search/suggestion-auto-complete' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "dress",
"client": "CLIENT_SHORTCODE"
}'

Response Payload

{
"type": 1,
"code": 0,
"payload": {
"suggested_terms": [
{
"search_term": "dress",
"frequency": 1250
},
{
"search_term": "dress shoes",
"frequency": 890
}
],
"trending_terms": [
{
"search_term": "summer dress",
"frequency": 2100
}
],
"synthetic_suggested_terms": [
{
"search_term": "dress shirts",
"frequency": 500
}
],
"synthetic_trending_terms": [
{
"search_term": "wedding dress",
"frequency": 800
}
],
"auto_complete": [
{
"search_term": "dress",
"frequency": 1250
},
{
"search_term": "dress shoes",
"frequency": 890
},
{
"search_term": "dress pants",
"frequency": 650
},
{
"search_term": "dresses for women",
"frequency": 420
}
]
}
}

Response Fields

FieldTypeDescription
typeintegerResponse type. 1 = success, -1 = failed.
codeintegerResponse code. 0 = normal.
payloadobjectContains all suggestion results.
payload.suggested_termsarrayList of suggested terms based on search history.
payload.trending_termsarrayList of currently trending search terms.
payload.synthetic_suggested_termsarrayList of manually configured suggested terms.
payload.synthetic_trending_termsarrayList of manually configured trending terms.
payload.auto_completearrayList of auto-complete suggestions based on prefix matching, sorted by frequency.

Auto-Complete Behavior

The auto_complete field provides search term suggestions that start with the user's input query:

  • Prefix Matching: Matches terms that begin with the query string (case-insensitive)
  • Frequency Sorting: Results are sorted by search frequency in descending order
  • Result Limit: Returns up to 10 auto-complete suggestions by default

For example, if the query is "dre", auto-complete might return: "dress", "dress shoes", "dress pants", etc.

Error Response

If there are any errors, the response will indicate failure:

{
"type": -1,
"code": 0,
"payload": {},
"detail": "Failed to construct search query"
}

Example Usage (JavaScript)

const apiUrl = 'https://<PA_SEARCH_END_POINT>/search/suggestion-auto-complete';
const accessToken = 'YOUR_ACCESS_TOKEN';

const body = {
website_id: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
q: 'dress',
client: 'CLIENT_SHORTCODE'
};

fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`
},
body: JSON.stringify(body)
})
.then(response => response.json())
.then(data => {
if (data.type === 1) {
// Display auto-complete suggestions as user types
const autoComplete = data.payload.auto_complete || [];
autoComplete.forEach(item => {
console.log(`${item.search_term} (${item.frequency} searches)`);
});

// Also access other suggestion types
console.log('Suggested terms:', data.payload.suggested_terms);
console.log('Trending terms:', data.payload.trending_terms);
} else {
console.error('Request failed');
}
})
.catch(error => console.error('Error:', error));

Summary

  • The Suggestion with Auto-Complete API extends the standard Suggestion API with prefix-based auto-complete.
  • Auto-complete suggestions match the beginning of the search query and are sorted by popularity.
  • Returns suggested terms, trending terms, synthetic terms, and auto-complete suggestions in a single response.
  • Ideal for implementing search-as-you-type functionality in search boxes.
  • For basic suggestions without auto-complete, see the Suggestion API.