Azure Search: price range - min & max value calculation
Asked Answered
T

1

15

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:

Azure Facet Navigation

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:

Price Range

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:

MultiValue Facet Handler Result

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.

Price Field

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?

Taciturnity answered 20/9, 2017 at 17:2 Comment(1)
While I don't have an answer for you, I can tell you that Aggregations are not supported in Azure Search. See here (feedback.azure.com/forums/263029-azure-search/suggestions/…)Perplexed
S
1

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

Surcease answered 2/3, 2018 at 23:25 Comment(1)
Only for the filtering operation this is correct but i am looking for a way to get the minimum and maximun values when requesting the actual range facetsTaciturnity

© 2022 - 2024 — McMap. All rights reserved.