Skip to content

Product Search with our .NET client ​

Looking for setup prerequisites, authentication details, and package references? Start with the .NET SDK landing page.

csharp
ISearcher searcher = new Searcher(
    new Guid("00000000-0000-0000-0000-000000000001"),
    "your API Key",
    "server-url");

Before going any further, read about handling different types of users here.

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

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

request.Settings.SelectedProductProperties = new SelectedProductPropertiesSettings
{
    DisplayName = true,
    CategoryPaths = true,
    Brand = true,
    DataKeys = new string[] { "Description", "ImagePath" },
    AllVariants = true
};

request.Facets.AddBrand(new[] { "77", "93" });
request.Facets.AddDataString(DataSelectionStrategy.Product, "Environment", new[] { "Selection 1" });
request.Facets.AddDataBoolean(DataSelectionStrategy.Product, "InStock", new[] { true });

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

Using facets and selecting values. ​

Adding the following code to the request will return a facet with the different brands from the products matching the search.

csharp
request.Facets.AddBrand();

When the user selects a brand, update the code to the following:

csharp
request.Facets.AddBrand(new[] { "93" });

You can learn more about facets here.

Batching Search Requests in .NET ​

Similar to filtering, API requests to Relewise may be batched to reduce overall load and improve loading speed on the website.

Below is an example of a batched request:

ts
ProductSearchRequest productSearch = new ProductSearchRequest(
    new Language("da"),
    new Currency("DKK"),
    user,
    "Search Page",
    "a",
    skip: 0,
    take: 10);

productSearch.Settings.SelectedProductProperties = new SelectedProductPropertiesSettings
{
    DisplayName = true,
};

ProductCategorySearchRequest productCategorySearch = new ProductCategorySearchRequest(
    new Language("da"),
    new Currency("DKK"),
    user,
    "Search Page",
    "shoe",
    skip: 0,
    take: 30);

productCategorySearch.Settings.SelectedCategoryProperties = new SelectedProductCategoryPropertiesSettings
{
    DisplayName = true,
};

SearchRequestCollection batchedRequest = new SearchRequestCollection();
batchedRequest.Requests.Add(productSearch);
batchedRequest.Requests.Add(productCategorySearch);

SearchResponseCollection response = await searcher.BatchAsync(batchedRequest, cancellationToken);

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