The XSearch service provides four main capabilities:
Run a standard search query to retrieve results with full control over pagination, sorting, and filters
Pull all possible property values for a collection to power facets and filter menus
View trending search terms to understand what shoppers are looking for most.
View search suggestions terms for a user’s current query.
Methods
// Returns a search response containing the results
xg.search.getResults({query: 'coat', options: {collection: '<collection>', deploymentId:'<deployment_id>'}});
// Returns a list of property values for the given collection
xg.search.getResultValues({collection: '<collection>'});
// Returns a list of trending search terms for the given collection
xg.search.getTrendingSearches({collection: '<collection>'});
// Returns a list of search suggestions from the given collection
xg.search.getSearchSuggestions({collection: '<collection>', query: '<query>'});getResults
getResults
Description: Gets recommendation results by a single search experience id.
Parameters
Name | Type | Required | Description |
|
| ✅ | The ID of the element |
|
| ✅ | Options object that allows you to control the search result response |
↳ |
| ✅ | Collection to get items from |
↳ |
| ✅ | The deploymentId to get search results for |
↳ |
| ❌ | The locale used for tracking (it is recommended to provide this globally when initializing the |
↳ |
| ❌ | The page of results |
↳ |
| ❌ | The number of results per page (max is 120). Default is 60. |
↳ |
| ❌ | If facets is passed as |
↳ |
| ❌ | If deep search should be forced. Useful for Type to Search. |
↳ |
| ❌ | Sort by price or update date |
↳ |
| ❌ | Sort order |
↳ |
| ❌ | Context object used for dynamic filtering |
↳ |
| ❌ | The url used for tracking purposes. This will be passed by default in the browser. |
↳ |
| ❌ | The referrer used for tracking purposes. This will be passed by default in the browser. |
|
| ❌ (defaults to | Can turn off auto tracking of |
|
| ❌ | An optional queryId passed to cancel a request |
Returns
A Promise resolving to the object below:
{
items: SearchProduct[];
facets: { [key: string]: unknown };
isFromCache: boolean;
page: number;
keyword: string;
isUrlRedirect: boolean;
isQueryTranslated: boolean;
isCachedFilterApplied: boolean;
isKeywordConfigApplied: boolean;
behaviorId: string;
responseEngine: string;
totalResults: number;
sortedBy: string;
variantMapping?: { [key: string]: string };
searchTermMatches?: string[];
}getResultValues
getResultValues
Description: Gets the possible properties of a search result.
Parameters
Name | Type | Required | Description |
|
| ✅ | Collection to get items from |
|
| ❌ | Can specify a specific product to get values for |
Returns
A Promise resolving to the object below:
{
[key: string]: {
name: string;
count: number;
}
}getTrendingSearches
getTrendingSearches
Description: Returns a list of trending search terms for the given collection.
Parameters
Name | Type | Required | Description |
|
| ✅ | Collection to get items from |
Returns
A Promise resolving to the array below:
string[];getSearchSuggestions
getSearchSuggestions
Description: Returns a list of search suggestions based on search_result events. This has a look back period of 5 days and the query sent must be 3 characters or more to get results. (note: this endpoint will return empty results if there is not enough event data being sent)
Parameters
Name | Type | Required | Description |
|
| ✅ | Collection to get items from |
|
| ✅ | The query to get suggestions for. |
|
| ❌ | Options object that allow you to control the search suggestions response |
↳ |
| ❌ | If |
Returns
A Promise resolving to the array below:
string[];