Price Range Filter with Slider UI with Min & Max v

2019-07-21 23:07发布

问题:

I'm working on an Solr integration for an e-commerce site. I want to offer a jQuery Slide Range UI (refer http://jqueryui.com/slider/#range).

So visitor will be offered with a slider with min and max price on the page which they can use to define a range and accordingly the filter is applied.

On Solr side, I understand how to make a range filter query on this.

However, for displaying a range I need min and max price value. I'm not sure how to get this from Solr.

Moreover, when other facets are filtered, I need to change this min & max price. But I can not think about how this can be done with Solr. Does solr provide min & max price value in the same query?

How to do this?

Or what is the best practices to implement this with Solr?

回答1:

I believe you are already getting the facet values of current data set, so as for your range problem you have to sort the facet value on the client side and supply the min & max values to slider.

This way it resolves your other problem too, because with filters applied, the returned resultant values for facets will change too.

Moreover you can add an additional check for not showing sliders in case facets does n't return anything.

For large data ranges , i think you can use solr stats eg :

http://localhost:8983/solr/select?q=*:*&stats=true&stats.field=price&rows=0&indent=on

Read here about it : http://wiki.apache.org/solr/StatsComponent



回答2:

use stats of SOLR, pass stats parameter to your SOLR query, here i pass grand_total in stats field to get min,max,count,mean,deviation etc.

stats SOLR Wiki

http://<ip_address>:<port>/solr/<core_name>/select?wt=json&indent=true&q=*:*&start=0&rows=10&stats=true&stats.field=grand_total


回答3:

Solr version: 5.4 and above.

May be the post is old but definitely it will help some one.

I have a solution for this and I have implemented in my project.

You have to use json facet to achive the max and min value based on the facet result.

    json.facet={
   tags_group:{
      type:terms,
      field:tags,
      limit:-1,
      facet:{
         pricemin:{
            type:terms,
            field:price,
            limit:1,
            sort:{
               x:asc
            },
            facet:{
               x:"min(price)"
            }
         },
         pricemax:{
            type:terms,
            field:price,
            limit:1,
            sort:{
               y:desc
            },
            facet:{
               y:"max(price)"
            }
         }
      }
   }
}

In the above Json facet I have used tags as filed(multivalued) and this will create a bucket like this

<str name="val">Letter Holder</str>
<int name="count">2</int>
<lst name="pricemin">
    <arr name="buckets">
        <lst>
            <double name="val">899.0</double>
            <int name="count">1</int>
            <double name="x">899.0</double>
        </lst>
    </arr>
</lst>
<lst name="pricemax">
    <arr name="buckets">
        <lst>
            <double name="val">1299.0</double>
            <int name="count">1</int>
            <double name="y">1299.0</double>
        </lst>
    </arr>
</lst>