Currently, I am trying out Azure Search SDK. Having a strong background working with lucene and bobobrowse, the Azure Search is quite fantastic and has a lot of features from both frameworks out of the box.
The only thing I am puzzling with is to get the minimum and maximum value of a numeric facet item. By intention, I do not want to use the interval parameter nor the value lists:
My requirement is to display the price facet with a calculated minimum and maximum value. Following website has such a facet in their facet list:
In my existing desktop application (.Net) I successfully used BoboBrowse framework and implemented a Custom-FacetHandler to get the desired results which are shown in the following picture below:
Never mind the facet values within these pictures. These are just length, height and other characteristic values of tools.
This is how I build one document for demonstration purposes. There is a price field which is generated dynamically. Because of azure search needs a strongly fixed schema for every index. I update the schema within the indexing process. This works very well.
So the question is how can i achieve the required functionality with azure search?
In the elastic search, such a problem could be solved by using Aggregations. Does this feature exist in Azure Search?
The $filter
parameter supports the lt
(less than) and gt
(greater than) operators. For example: $filter=price gt 0 and price lt < 100
Sample code:
string PriceFilter(double? fromPrice, double? toPrice)
{
var filter = "$filter=";
if(fromPrice.HasValue)
filter+="price gt " + fromPrice.Value.ToString()
+ (toPrice.HasValue ? " and " : "");
if(toPrice.HasValue)
filter+="price lt " + toPrice.Value.ToString();
return filter;
}
Reference: Build a filter for a range
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With