Autocomplete

Autocomplete works in a similar fashion to the general search functionalities.

Optimizely.Hawksearch.Client package contains classes which will correspond to the requests and responses provided by Hawksearch’s Autocomplete API.

  • AutocompleteRequest

  • AutocompleteResponse


However, it does not contain Search filters.

The Flow

  1. Using only Optimizely.Hawksearch.Client

  • Create and populate an AutocompleteRequest object

  • Use the Autocomplete method of the SearchClient class (or its async counterpart)

public AutocompleteResponse<TProduct, TContent> Autocomplete<TProduct, TContent>(AutocompleteRequest searchRequest) where TProduct : HawksearchProductItem where TContent : HawksearchContentItem public async Task<AutocompleteResponse<TProduct, TContent>> AutocompleteAsync<TProduct, TContent>(AutocompleteRequest searchRequest) where TProduct : HawksearchProductItem where TContent : HawksearchContentItem
  • Get the AutocompleteResponse object then map it to your business models

 

  1. Using both

Optimizely.Hawksearch.Client and Optimizely.Hawksearch.Connector

  • Build an AutocompleteRequest object by passing a keyword (string) to an AutocompleteRequestBuilder and its Fluent API

  • Use one of the Autocomplete methods of the SearchClient class show above

  • Get the AutocompleteResponse object then map it to your business models

A high-level example:

public AutocompleteResults Autocomplete(string keyword) { var request = new AutocompleteRequestBuilder() .ForLanguage("en") .DisplayFullResponse() .Build(keyword); //SearchClient _client var response = _client.Autocomplete<HawksearchProductItem, HawksearchContentItem>(request); var mappedResponse = MapAutocompleteResults(response); return mappedResponse; }

 

Â