Range search
This article describes how to search on a range of values. A common search in this area can be a price range search or search for news articles by date range by published date.
To make a range search, include the "RangeTag" to the filter tags of the search query. Following example searches for all products on a given price range inside a price list.
Give special attention to how the price list tag name is obtained.
/// <summary>
/// search for list of products in a price range in the given pricelist
/// </summary>
/// <param name="languageId">The language id.</param>
/// <param name="priceListId">The price list id.</param>
/// <param name="minPrice">The min price.</param>
/// <param name="maxPrice">The max price.</param>
/// <param name="token">The token.</param>
/// <returns></returns>
public static IEnumerable<Guid> PriceRangeSearch(Guid languageId, Guid priceListId, decimal minPrice, decimal maxPrice, SecurityToken token)
{
IEnumerable<Guid> result = null;
var request = new QueryRequest(languageId, ProductCatalogSearchDomains.Products, token);
var priceListTagName = TagNames.GetTagNameForPriceExludingVAT(priceListId);
request.FilterTags.Add(new RangeTag(priceListTagName, minPrice, maxPrice));
var response = Solution.Instance.SearchService.Search(request);
if (response.Hits != null)
{
result = response.Hits.Select(x => new Guid(x.Id));
}
return result ?? new List<Guid>();
}
Note that in practice the final list price of an article may depend on other factors such as product campaigns or ERP pricing.