Appearance
Sorting a product collection
Looking for setup prerequisites, authentication details, and package references? Start with the TypeScript / JavaScript SDK landing page.
If you do use it directly from a CDN, then all of our types are namespaced with a Relewise.-prefix. So to get the recommender you need to write new Relewise.Recommender() instead of new Recommender().
To get started with recommendations we need to start by making an Recommender-instance.
ts
const recommender = new Recommender(RELEWISE_DATASET_ID, RELEWISE_API_KEY, {
serverUrl: RELEWISE_SERVER_URL,
});Before going any further, read about handling different types of users here.
Sorting Products
When using your own search engine and want to get a personalized sorting of a collection of products you can use our SortProducts-recommendation to achieve this. The recommended way of using Relewise for category pages is using our search features. Read about how to use our Search API for category pages here.
Parse in the Product IDs you want personalized, and specify the number of recommendations you want back. If you want a subset of the collection, you can just set a specific amount you want returned.
ts
const settings: Settings = {
language: 'da-DK',
currency: 'DKK',
displayedAtLocation: 'Product Details Page',
user: getUser()
};
const productIds = ['p-1', 'p-2', 'p-3'];
const builder = new SortProductsBuilder(settings)
.setProductIds(productIds)
.setNumberOfRecommendations(productIds.length);
await recommender.sortProducts(builder.build());You can still use filters, relevance modifiers and of course select what product and variant properties you want returned in the response.