Appearance
Product Search with our .NET client
Relewise has a .NET SDK which, among other things, will make implementing search very easy.
It is available via NuGet.
csharp
ISearcher searcher = new Searcher(
new Guid("00000000-0000-0000-0000-000000000001"),
"your api key",
"server-url");
Before going any further, make sure you have read the following:
- Read about how to authenticate against our API here.
- 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
var 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
var productSearch = new ProductSearchRequest(
new Language("da"),
new Currency("DKK"),
user,
"Search Page",
"a",
skip: 0,
take: 10);
productSearch.Settings.SelectedProductProperties = new SelectedProductPropertiesSettings
{
DisplayName = true,
};
var productCategorySearch = new ProductCategorySearchRequest(
new Language("da"),
new Currency("DKK"),
user,
"Search Page",
"shoe",
skip: 0,
take: 30);
productCategorySearch.Settings.SelectedCategoryProperties = new SelectedProductCategoryPropertiesSettings
{
DisplayName = true,
};
var batchedRequest = new SearchRequestCollection();
batchedRequest.Requests.Add(productSearch);
batchedRequest.Requests.Add(productCategorySearch);
SearchResponseCollection response = await searcher.BatchAsync(batchedRequest, cancellationToken);