Developer forum

Forum » CMS - Standard features » Index - Pricerange filter min and max values

Index - Pricerange filter min and max values

Thomas Larsen
Reply

Hi,

Is there a way to find min and max values when implementing a range filter: 

http://doc.dynamicweb.com/documentation-9/how-tos/general/implementing-a-pricerange-query#sideNavTitle1-4

BR
Thomas

 


Replies

 
Nicolai Pedersen
Reply

Hi Thomas

Unfortunately not. Lucene has no simple way of finding that - as I understand it, we have to do either 2 searches or iterate the term enum to find min and max. And the values are changing for every query, so we cannot cache or record it at index time.

Br Nicolai

 
Thomas Larsen
Reply

I found a workaround/hack for this, by creating a matching facets that returns all possible values. And in that find min and max values.

                        var parameterName = i.GetString("Parameter.Name");
           var isRange = i.GetString("Parameter.Type").EndsWith("[]");

           if (isRange)
           {
              //Find matching facets by name <parametername>_Values
              //Matching facets are not displayed in the filters
              var valuesFacet = facetsLoop.Where(f => f.GetString("Facet.Name") == parameterName + "_Values").FirstOrDefault();
              int minValue = 0;
              int maxValue = 0;

              //If matching facet found 
              if (valuesFacet != null)
              {
                 //Get min and max from the options - Only works on integers, because lucene removes comma in double fields
                 maxValue = Math.Ceiling(valuesFacet.GetLoop("FacetOptions").Max(fo => fo.GetDouble("FacetOption.Value")));
                 minValue = Math.Floor(valuesFacet.GetLoop("FacetOptions").Min(fo => fo.GetDouble("FacetOption.Value")));
              }
           }


Unfortunately this only works with integer fields and not double fields, because the index removes alle commas. Do you have a solution for that?

 
Nicolai Pedersen
Reply

Hi Thomas

Ah, nice - thanks for sharing. You can probably use the NumericUtils in Lucene to handle doubles https://lucenenet.apache.org/docs/3.0.3/d6/d38/class_lucene_1_1_net_1_1_util_1_1_numeric_utils.html

BR Nicolai

 

You must be logged in to post in the forum