Autocomplete
Autocomplete functionality provides relevant search suggestions to users as they type. Loop54 provides autocomplete query suggestions and also query suggestions with preset facets/ scoped suggestions (normally search in a category). For example the suggestions “orange” and “orange” in category “fruit” could both be examples to the string “or”.
The autocomplete suggestions should be requested for every key press after the user has typed 2 letters with a key press delay of about 50-150ms to avoid flickering when the user is typing longer queries.
A Simple Example
This simple example only considers suggestions without a facet.
// Below is an example of a request - response cycle of an autocomplete request
AutoCompleteRequest request = new AutoCompleteRequest(query);
request.QueriesOptions.Skip = 0;
request.QueriesOptions.Take = 9;
AutoCompleteResponse response = _loop54Client.AutoComplete(request);
var queries = response.Queries.Items.Select(q => q.Query).ToList();
//print out all suggested autocomplete queries
Debug.WriteLine("queries: " + string.Join(", ", queries));
C# source code on Github: AutoCompleteController.cs
Handling Scoped suggestions
This example does the same thing as the simple example and it also checks for query suggestions with scoped suggestions. Note that the existence of preset facets in the response are determined by the Loop54 service and not a part of the request. Therefore the existence of scoped queries must be checked for each response.
// Below is an example of a request - response cycle of an autocomplete request
// where scopes are used to provide the user with more context
AutoCompleteRequest request = new AutoCompleteRequest(query);
request.QueriesOptions.Skip = 0;
request.QueriesOptions.Take = 9;
AutoCompleteResponse response = _loop54Client.AutoComplete(request);
//prints out the scoped suggestions
if(response.ScopedQuery != null)
{
Debug.WriteLine("scoped query: " + response.ScopedQuery.Query);
Debug.WriteLine("scopes based on: " + response.ScopedQuery.ScopeAttributeName);
Debug.WriteLine("scopes: " + string.Join(", ", response.ScopedQuery.Scopes));
}
C# source code on Github: AutoCompleteController.cs
Last updated