Skip to content

Filtering products in search or recommendations

The examples below are using our .NET/C# SDK, which is available via NuGet.

In the examples we will be performing filtering on Search-request, but you can do the same for all recommendation requests. You will need an instance of our Searcher:

csharp
ISearcher seacher = new Searcher(
  new Guid("00000000-0000-0000-0000-000000000001"), 
  "your api key");

It is recommended that you start by reading about product search.

Also remember to specify your Server URL in your request.

The following shows an example on how to perform a product search with 3 selected facets.

Different assortments

A common scenario is handling different assortments. You might have products that are unique to specific markets or specific customers on the same website using Relewise. Here the assortments might be overlapping but not identical, so we need some way of only showing the products that are available in the given context. There are 2 different ways of handling this.

The first option is to use our Assortment feature, and specify an Assortment value for each market/customer (these have to be numbers) on all products.

csharp
new Product("productId") {
  Assortments = new List<int>() { 1, 2 }
};

Then when performing a search you want to add a ProductAssortmentFilter to the search request.

csharp
var request = new ProductSearchRequest(
    new Language("da"), 
    new Currency("DKK"), 
    GetUser(), 
    "Search overlay", 
    "<search-term>", 
    skip: 0, 
    take: 10);

request.Filters.Add(new ProductAssortmentFilter(1));

ProductSearchResponse response = await searcher.SearchAsync(request, cancellationToken);

If you are using Variants, and these also can be specific to market/customer then you can use the mechanism on variants and add an assortment to those.

Using the Data-bag to handle assortment

The second option is using the Products Data-bag to add a list of shops, where the product is available and then filter on those.

csharp
	new Product("productId")
	{
		Data = new Dictionary<string, DataValue?>
		{
			["AvailableOnMarkets"] = new List<string> { "DK", "DE" }
		}
	};

Then when performing a search you want to add a ProductDataFilter to the search request.

csharp
var request = new ProductSearchRequest(
    new Language("da"), 
    new Currency("DKK"), 
    GetUser(), 
    "Search overlay", 
    "gaffel", 
    skip: 0, 
    take: 10);

request.Filters.Add(new ProductDataFilter(
	"AvailableOnMarkets",
	new ContainsCondition("DK"),
	filterOutIfKeyIsNotFound: true));

ProductSearchResponse response = await searcher.SearchAsync(request, cancellationToken);

In Stock

Hiding products that are out of stock, can be achieved by adding a InStock indicator on products, like so:

csharp
	new Product("productId")
	{
		Data = new Dictionary<string, DataValue?>
		{
			["InStock"] = true/false
		}
	};

Then when performing a search you want to add a ProductDataFilter to the search request.

csharp
var request = new ProductSearchRequest(
    new Language("da"), 
    new Currency("DKK"), 
    GetUser(), 
    "Search overlay", 
    "gaffel", 
    skip: 0, 
    take: 10);

request.Filters.Add(new ProductDataFilter(
	"InStock",
	new EqualsCondition(true),
	filterOutIfKeyIsNotFound: true));

ProductSearchResponse response = await searcher.SearchAsync(request, cancellationToken);

Don't know us? Don't worry - you can find more information about us, by visiting our main page www.relewise.com