Suggestions
Get real-time search suggestions.
Endpoint
GET /api/suggestions
Headers
| Header | Required | Description |
|---|---|---|
X-Widget-Token | Yes | Authentication token |
Query params
| Param | Type | Required | Description |
|---|---|---|---|
q | string | Yes | Partial query |
limit | number | No | Number of suggestions (default: 5) |
Response
{
"suggestions": [
{
"type": "query",
"text": "running shoes",
"count": 150
},
{
"type": "category",
"text": "Sports Shoes",
"count": 320
},
{
"type": "brand",
"text": "Nike",
"count": 85
},
{
"type": "product",
"text": "Nike Air Max 90",
"product": {
"id": "prod_123",
"name": "Nike Air Max 90",
"price": 129.99,
"imageUrl": "https://..."
}
}
]
}
Suggestion types
| Type | Description |
|---|---|
query | Related popular search |
category | Matching category |
brand | Matching brand |
product | Specific product |
Example
curl -X GET "https://api.neuroon.ai/api/suggestions?q=shoe&limit=5" \
-H "X-Widget-Token: YOUR_TOKEN"
Recommended usage
Implement debounce to avoid excessive requests:
import { debounce } from 'lodash';
const fetchSuggestions = debounce(async (query) => {
const response = await fetch(
`https://api.neuroon.ai/api/suggestions?q=${encodeURIComponent(query)}`,
{ headers: { 'X-Widget-Token': token } }
);
return response.json();
}, 150);
input.addEventListener('input', async (e) => {
if (e.target.value.length >= 2) {
const { suggestions } = await fetchSuggestions(e.target.value);
renderSuggestions(suggestions);
}
});
Notes
- Minimum 2 characters to get suggestions
- Suggestions are sorted by relevance
- The
countfield indicates related products