Autocomplete API (Beta)

Autocomplete API allows you to display queries suggestions, based on the user query. This allows the user to refine its search request, with queries that yield results in the past.

Suggested queries are based on previous queries typed by users that returned results, over the last week (default time span). By default, suggestions are ordered by the number of search views.

Prerequisites to enable autocomplete

  • Having a working XO Search implementation

  • Having tracking enabled

  • Having XO search tracking implemented, as documented in the XO tracking plan:

XO Tracking plan

  • Contact us to enable autocomplete.

Autocomplete

POST https://api-eu.attraqt.io/search/autocomplete

Autocomplete the user's queries and get suggestions using the XO Search engine.

Request Body

NameTypeDescription

token*

string

XO Search token (can be found in the XO Console)

query*

string

The query string used for the search

options.numberOfSuggestions

integer

Number of suggestions to get, at most.

Defaults to 10

(must be between 1 and 20)

configurationId

string

Configuration to use. If unspecified, the default configuration will be used

Example autocomplete request

POST https://api-eu.attraqt.io/search/autocomplete HTTP/1.1
Content-Type: application/json; charset=UTF-8

{
  "token": "SEARCH_API_TOKEN",
  "query": "T-Shirt",
  "options": {
    "numberOfSuggestions": 10
  }
}

Response

The search response contains two parts:

PropertyTypeDescription

suggestions

array

Array of suggestions. See below for the exact format

metadata

object

Metadata about the autocomplete request: elapsed time, ...

suggestions

The suggestions based on the input query

PropertyTypeDescription

suggestion

string

A suggestion, prefixed by the input query

metadata

Metadata about the search query and its results.

PropertyTypeDescription

time

number

Time the request took to complete (in milliseconds)

token

string

Search API token used for the request

id

string

Unique identifier

configurationId

string

Search configuration id used

Example

{
  "suggestions": [
    { "suggestion": "t-shirt black" },
    { "suggestion": "t-shirt for kids" },
    { "suggestion": "t-shirt on sale" }
  ],
  "metadata": {
    "id": "autocomplete_573e30b1-7d97-46a0-bbe0-110527150534",
    "configurationId": "cddda87b-c99d-45aa-bf45-cd53d2bc8ace",
    "time": 35,
    "token": "MY_SEARCH_TOKEN"
  }
}

Last updated