You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by PeterKerk <ve...@hotmail.com> on 2013/11/06 01:05:37 UTC

get min-max prices as facets

I want to provide my visitors with a price range slider when they can easily
filter on a min and max value. For this I need to know the lowest and
highest price of all the products found by my solr query.Since this is
dynamic, based on the query by the user, I can not simply get the min and
max values of all products in my data-config.xml.How can I get these lowest
and highest price for the current query?Thanks!



--
View this message in context: http://lucene.472066.n3.nabble.com/get-min-max-prices-as-facets-tp4099501.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: get min-max prices as facets

Posted by manju16832003 <ma...@gmail.com>.
Hey Peter,
Now I understood your requirement :-).

I come across this http://wiki.apache.org/solr/StatsComponent

have a look if it helps you :-).



--
View this message in context: http://lucene.472066.n3.nabble.com/get-min-max-prices-as-facets-tp4099501p4099737.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: get min-max prices as facets

Posted by Raymond Wiker <rw...@gmail.com>.
As far as I understand, the filter terms (fq parameters) should be automatically cached.

On 06 Nov 2013, at 19:08 , PeterKerk <ve...@hotmail.com> wrote:

> Hi Raymond,
> 
> Thanks.
> This caching of the main query you mention, is that done automatically or do
> I have to do something for that?
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/get-min-max-prices-as-facets-tp4099501p4099613.html
> Sent from the Solr - User mailing list archive at Nabble.com.


Re: get min-max prices as facets

Posted by PeterKerk <ve...@hotmail.com>.
Hi Raymond,

Thanks.
This caching of the main query you mention, is that done automatically or do
I have to do something for that?



--
View this message in context: http://lucene.472066.n3.nabble.com/get-min-max-prices-as-facets-tp4099501p4099613.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: get min-max prices as facets

Posted by Raymond Wiker <rw...@gmail.com>.
One way of getting the min/max values is to fire off two additional queries, using the current query and filter params, a field list ("fl") containing just the field you want to find min/max for, asking for a single hit (rows=1), and sorting by that field - asc in one query, desc in the other. This should be relatively cheap, assuming that you can re-use cached information from the main query.

Assuming that your price field is named "price", modifying your main query by appending

fl=price&rows=1&sort=price+asc

fl=price&rows=1&sort=price+desc

should give you the min and max values you require.

On 06 Nov 2013, at 12:42 , PeterKerk <ve...@hotmail.com> wrote:

> Thanks!
> I know how to fire a range query. However, what I want is to provide the
> visitor with a range filter. In this range filter the minimum and maximum
> value are already set to the lowest and highest price of the current
> resultset.
> 
> e.g.
> I sell cars. My cheapest car is 1,000 and the most expensive is 100,000
> A user comes on the site and all cars are shown, so the price range filter
> he sees is set to start at 1,000 and end at 100,000
> 
> Then the user filters on brand Audi.
> 
> The cheapest Audi is 40,000 and the most expensive 80,000
> In this case I the price range filter changes, and holds a minimum value of
> 40,000 and a max of 80,000. This will a) give the user an indication of all
> Audi prices and b) prevent him from selecting a price for which there is no
> car available.
> 
> I believe this is different then what you are suggesting right?
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/get-min-max-prices-as-facets-tp4099501p4099565.html
> Sent from the Solr - User mailing list archive at Nabble.com.


Re: get min-max prices as facets

Posted by PeterKerk <ve...@hotmail.com>.
Thanks!
I know how to fire a range query. However, what I want is to provide the
visitor with a range filter. In this range filter the minimum and maximum
value are already set to the lowest and highest price of the current
resultset.

e.g.
I sell cars. My cheapest car is 1,000 and the most expensive is 100,000
A user comes on the site and all cars are shown, so the price range filter
he sees is set to start at 1,000 and end at 100,000

Then the user filters on brand Audi.

The cheapest Audi is 40,000 and the most expensive 80,000
In this case I the price range filter changes, and holds a minimum value of
40,000 and a max of 80,000. This will a) give the user an indication of all
Audi prices and b) prevent him from selecting a price for which there is no
car available.

I believe this is different then what you are suggesting right?



--
View this message in context: http://lucene.472066.n3.nabble.com/get-min-max-prices-as-facets-tp4099501p4099565.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: get min-max prices as facets

Posted by manju16832003 <ma...@gmail.com>.
I'm not sure if my answer would help you :-).
Usually we do not need to know the min and max prices that our current
database or solr is holding for all the products. Even if you were to that,
would be complex and just make your business logic bigger and tedious. 

Instead, we would know what is the min price and what would be the max
price. Based on this you could create price buckets in solr using 
http://wiki.apache.org/solr/SimpleFacetParameters#Facet_by_Range

In others words, Lets say my site is about selling cars, I would mention min
price could be =0 and max price = 4000000 (4million just logical value)
could be more than that. So price range will fall between those two
logically defined fields. Based on that you could construct solr facet query
range, that Solr will automatically give you the price range (price bucket
what amazon calls it).

Hope that is helpful :-).



--
View this message in context: http://lucene.472066.n3.nabble.com/get-min-max-prices-as-facets-tp4099501p4099523.html
Sent from the Solr - User mailing list archive at Nabble.com.