Contents

autocomplete(query, options)

Retrieves a list of autocomplete results for the specified search query.

Declaration

autocomplete(
    query: string,
    options?: SearchAutocompleteOptions,
): Promise<SearchAutocompleteResponse>;

Parameters

  • query:

    A string that represents the user’s search in progress.

  • options:

    Options for this specific query that supersede values set on the Search object. See Searchautocompleteoptions.

Return Value

A promise that resolves with a SearchAutocompleteResponse on success, or rejects with an Error on failure.

Discussion

To provide the user with a menu of search suggestions, invoke the autocomplete(query, options) method as users type. This method minimizes typing and brings users the results they’re looking for.

Pass an AbortSignal from an AbortController to the signal option to allow the controller to cancel a pending request. When the controller aborts, the promise it returns rejects with a DOMException whose name is "AbortError".

See Also

Performing a search autocomplete