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
| Name | Value |
|---|---|
Content-Type | application/json |
Authorization | Bearer ACCESS_TOKEN |
Request Parameters (Body)
| Parameter | Type | Required | Description |
|---|---|---|---|
website_id | string | Yes | Client unique website ID provided by PA. |
q | string | Yes | Input search query string. Used for prefix matching in auto-complete. |
client | string | Yes | Unique 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
| Field | Type | Description |
|---|---|---|
type | integer | Response type. 1 = success, -1 = failed. |
code | integer | Response code. 0 = normal. |
payload | object | Contains all suggestion results. |
payload.suggested_terms | array | List of suggested terms based on search history. |
payload.trending_terms | array | List of currently trending search terms. |
payload.synthetic_suggested_terms | array | List of manually configured suggested terms. |
payload.synthetic_trending_terms | array | List of manually configured trending terms. |
payload.auto_complete | array | List 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.