Autocomplete

Provides real-time, personalized, typo resistant typeahead for your search bar.


Syntax

const response = await client.api.search.autocomplete(payload, options);

Payload

The payload parameter is an object with the following properties:

Name Type Description
engine_id string The engine you want to get results from. If not specified, the default engine will be used.
user_id string The user who made the query and for whom Miso will personalize the results. Either user_id or anonymous_id needs to be specified.
anonymous_id string The anonymous visitor who made the query and for whom Miso will personalize the results. Either user_id or anonymous_id needs to be specified for personalization to work.
user_hash string The hash of user_id (or anonymous_id) encrypted by your Secret API Key.
q string Required. The search query the user has entered. Must be non-empty.
fq string A query string in Solr syntax which restricts the superset of products to return, without influencing the overall ranking.
fl array of strings List of fields to retrieve. The field product_id is always included. When not specified, only product_id will be retrieved. You can retrieve all fields with ["*"]. Default: ["*"].
type string Specify the type of product to return.
start integer The offset of records to retrieve. Default: 0.
rows integer Number of records to retrieve. Default: 5.

Return value

A Promise of response object with the following properties:

Name Type Description
completions object An object of autocompletion information.
start integer The offset of records to retrieve. Default: 0.
total integer The total number of matched records.

Examples

const payload = {
user_id: '...',
user_hash: '...',
q: 'shiba ',
fl: ['title', 'sale_price'],
completion_fields: ['title', 'tags', 'custom_attributes.author']
};
const { completions } = await client.api.search.autocomplete(payload);
for (const { text, text_with_markups, product } of completions.title) {
// ...
}

Learn more

For advanced usage, see REST API.