Autocomplete
Autocomplete Queries
- Shell
- JavaScript
- Python
- Java
- iOS
- Android
- C#
curl -X GET -H "Content-Type: application/json" \
"https://ac.cnstrc.com/autocomplete/[query]?key=[your API key]" \
"&filters[group_id]=123"
// Client side Javascript
// Please refer to https://Krestor-io.github.io/Krestorio-client-javascript/module-autocomplete.html#~getAutocompleteResults
// Node
// Please refer to https://Krestor-io.github.io/Krestorio-node/module-autocomplete.html#~getAutocompleteResults
# Please refer to https://Krestor-io.github.io/Krestorio-python/Krestor_io.modules.html#module-Krestor_io.modules.autocomplete
// Please refer to https://Krestor-io.github.io/Krestorio-java/io/Krestor/client/KrestorIO.html
// Please refer to https://Krestor-io.github.io/Krestorio-client-swift/
// Please refer to https://Krestor-io.github.io/Krestorio-client-android/library/io.Krestor.core/-Krestor-io/index.html#%5Bio.Krestor.core%2FKrestorIo%2FgetAutocompleteResults%2F%23kotlin.String%23kotlin.collections.List%5Bkotlin.Pair%5Bkotlin.String%2Ckotlin.collections.List%5Bkotlin.String%5D%5D%5D%3F%23kotlin.Int%3F%23kotlin.collections.List%5Bkotlin.String%5D%3F%2FPointingToDeclaration%2F%5D%2FFunctions%2F-1632692142
// This method is not currently supported.
info
The above command returns a 200 Success response on success.
You can try out an autocomplete query on your dataset by typing the following URL into a web browser: https://ac.cnstrc.com/autocomplete/[query]?key=[your API key]
, replacing [query]
with the query you'd like to make, and [your API key]
with your API key.
Want to try it right now? You can search for labrador
from our demo list of dog breeds here.
When implementing our autocomplete on a website, we recommend most customers use our Javascript (front-end) client. For other uses, please check out the list of SDKs we have.
HTTP Request
GET https://ac.cnstrc.com/autocomplete/[query]?key=[your API key]
Parameters
Parameter | Required? | Description |
---|---|---|
query | Yes | The URL-encoded autocomplete query. |
key | Yes | The key for the autocomplete you would like to query. |
num_results | No | The number of results to return across all sections in the autocomplete (rounded down if num_results isn't divisible by the number of autocomplete sections). The maximum value is 50. |
num_results_[section_name] | No | The number of results to return from autocomplete section section_name . section_name is URL encoded, so 3 results from section Dog Breeds would be num_results_Dog%20Breeds=3 . A single request can include several of these parameters to specify the number of results to return from multiple sections. The maximum value is 50. |
filters | No | A filter to be applied to autocomplete requests, so that only results that have that filter are returned. You can use facets or group_ids as filters. Autosuggest calls allow a maximum of one filter to be applied. |
variations_map | n/a | Mapping configuration to return item variations data in a specific format. It is a JSON string where you can list the only attributes of item variation you need. It's also possible to group variations and aggregate their fields in some way. For example, you can ask for min and max prices across all item variations, return only the first image URL instead of all variation pictures, or get only a list of all possible colors and no other data. The feature can be useful to build item swatches right in your autocomplete results view or reduce response size to speed up render of the results. More details, including the exact schema for this value can be found here |
Autocomplete Responses: Overview
Krestor's autocomplete returns easy-to-process JSON responses.
Response structure: Sections
Autocomplete responses are returned in discrete sections. Most typically there will be two such sections: Products
and Search Suggestions
. The purpose of these is as follows:
Products
These are the items you sell and want to facilitate discovery for. Krestor's autosuggest allows users to jump right to the product they're interested in within milliseconds -- even with millions of catalog items.Search Suggestions
These are suggested search terms users can choose to search. Suggested search terms help users discover your catalog and better qualify their search by encouraging more specific, well-formed queries. Customers can generate and maintain Search Suggestions themselves, but most customers rely on Krestor's optimization and suggestion algorithms to generate and optimize the list of search suggestions.
These are the typical sections, but we also support suggesting category page results, store locations, etc. You can work with our Implementation Engineering team to define and optimize other entities you'd like to search within.
{
"request": {
...
},
"response": {
"sections": {
"Search Suggestions": [
...
],
"Products": [
...
]
}
}
}
Response structure: Request object
Within each autocomplete response JSON, we include data on the submitted request.
Values with a default as well as the autocompleted term will always be returned. Otherwise, only given parameters will be returned within the request data.
We intentionally omit the following parameters from the response request object for privacy reasons: key, c, i, ui, s, _dt
Example: For the query 'https://ac.cnstrc.com/autocomplete/bird%20food?key=[your_key]' we might get the following request info:
{
"request": {
"term": "bird food"
},
"response": {
"sections": {
...
}
}
}
Response structure: Value & matched terms
All autosuggest responses will include at least two fields:
matched_terms
This indicates the terms that were matched within each item returned and is useful for implementing highlighting of match values. In the example to the right, imagine the user has typeddoge food
, Krestor resolves this to the spell correcteddog food
and returns the matched terms to permit match highlighting even for misspellings.value
This is the primary field searched and displayed to the user and generally corresponds toitem_name
you provided when adding the item.
{
"sections": {
"Search Suggestions": [
{
"data": [
...
],
"is_slotted": false,
"labels": {},
"matched_terms": [
"dog food"
],
"value": "mccormick's farmstand dog food"
},
...
],
"Products": [
{
"data": [
...
],
"is_slotted": true,
"labels": {
"is_sponsored": true
},
"matched_terms": [
"dog food"
],
"value": "McCormick's Farmstand Small Bites Potato & Duck Formula Dog Food"
},
...
]
}
}
Autocomplete Responses: Search Suggestions
Search Suggestions and Products response structures are broadly similar, but reviewing them individually is helpful as certain fields are more common or bear different significance depending on their location.
Search Suggestions: Groups
One of the most important roles of autosuggest is to clarify ambiguous queries. By leveraging Krestor's category suggestions, we can help users clarify their intent. Users often make over-broad searches like shirts
which may be men's or women's shirts or juniors shirts.
User types shirt
Autosuggest returns:
Shirts
in Women's Clothing
in Men's Clothing
in Juniors' Clothing
Each Search Suggestion is returned with a data
array containing Krestor's ordered recommendations for group suggestions.
The contents of this array are configurable, but most often include the following fields:
display_name
The name you would like displayed for the group in question.group_id
An alphanumeric identifier your company uses to uniquely identify the particular group entity.path
The hierarchy ofgroup_id
s within which the group exists. In the example to the right,95
would be the parentClothing
category.
{
"sections": {
"Search Suggestions": [
{
"data": {
"groups": [
{
"display_name": "Women's Clothing",
"group_id": "394",
"path": "/95/394/"
},
{
"display_name": "Men's Clothing",
"group_id": "339",
"path": "/95/339/"
},
{
"display_name": "Juniors' Clothing",
"group_id": "455",
"path": "/95/455/"
}
],
},
"is_slotted": false,
"labels": {},
"matched_terms": [
"dog"
],
"value": "Natural Balance Small Bites Potato & Duck Formula Dog Food"
}
],
"Products": [
...
]
}
}
Autocomplete Responses: Products
Products are typically the main items a company is interested in promoting so typically have the most metadata associated with them.
Products: Common fields
In addition to always returning value
, is_slotted
, labels
and matched_terms
, Krestor can display any data that's been uploaded for the items in question, which is returned in a data
object. We'll go over a typical subset below:
Additional Data (may not be present)
data.url
The URL where the item can be viewed or purchased.data.id
An ID that uniquely identifies the item within the company.data.image_url
An image of the item in question.data.groups
The category(ies) an item belongs to. We'll review these in greater detail below.data.facets
The facet(s) an item is associated with. We'll review these in greater detail below.
The autocomplete response format for product data matches the search response format.
System Status
To check the health of the system that serves /autocomplete
requests, you can issue a GET /status/product/autocomplete
, as shown below:
- Shell
- JavaScript
- Python
- Java
- iOS
- Android
- C#
curl -X GET "https://ac.cnstrc.com/status/product/autocomplete"
// This method is not currently supported.
# This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
// This method is not currently supported.
A healthy system will reply with {"message": "OK"}