Autocomplete
The autocomplete endpoint supports similar options to the Searching endpoint.
Autocomplete performs prefix matches on fields rather than token matching.
Prefix matching compares a user's input against a smaller document representation in real time.
| Engine Type | Supported? |
|---|---|
| Crawler-based Engine | YES |
| API-based Engine | YES |
Read more about Crawler-based Engines and API-based Engines within the API Overview.
Autocomplete within an Engine
Search for prefix matches over all string field types.
For example, if the bookstore Engine has string fields for books, tea, toys and magazines, then autocomplete will look for prefixes across all of these fields. This can be useful to help visitors find the popular thing, but might be less useful if someone just wanted to look for a book.
curl -X GET 'https://search-api.swiftype.com/api/v1/public/engines/suggest.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "YOUR_ENGINE_KEY",
"q":"act"
}'
Autocomplete within a DocumentType
Search for prefix matches over the specified string field type.
For example, the bookstore Engine has string fields for books, tea, toys and magazines and you only want to search for prefix matches over books.
books DocumentType for the prefix query "act"
curl -X GET 'https://search-api.swiftype.com/api/v1/public/engines/suggest.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "YOUR_ENGINE_KEY",
"q":"act",
"document_types": ["books"]
}'
Analytics, Autoselect
You can make an analytics autoselect request to record information on which documents were clicked or selected during autocomplete.
Read the Analytics API Reference for more information.
Stuck? Looking for help? Contact support or check out the Site Search community forum!