Quantcast

How to Facet on a price range

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to Facet on a price range

jayant
I am able to facet on a particular field because I have index on that field. But I am not sure how to facet on a price range when I have the exact price in the 'price' field. Can anyone help here.
Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

iorixxx
> I am able to facet on a particular field because I have
> index on that field.
> But I am not sure how to facet on a price range when I have
> the exact price
> in the 'price' field. Can anyone help here.


Something like this:

&facet=on&facet.query=price:[* TO 500]&facet.query=price:[500 TO *]

Additionally you can get min and max price of your query results with http://wiki.apache.org/solr/StatsComponent


     
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

Peter
In reply to this post by jayant
  take a look here
http://stackoverflow.com/questions/33956/how-to-get-facet-ranges-in-solr-results

> I am able to facet on a particular field because I have index on that field.
> But I am not sure how to facet on a price range when I have the exact price
> in the 'price' field. Can anyone help here.
> Thanks



--
http://jetwick.com twitter search prototype

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

jayant
In reply to this post by jayant
Thank you both. Faceting is now working on a range.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

Jan Høydahl / Cominvent
Note that using many facet.query= parameters may be expensive.
Another way to solve this is to pre-compute the ranges as plain strings in another field during indexing.
This can be done in your app prior to indexing or by creating a new FieldType for your range. Here's a field type that computes the strings for you. Simply do a copyField from your "price" field to e.g. "price_s", and facet on "price_s" instead of "price":

<fieldtype name="priceclass" class="solr.TextField">
  <analyzer>
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.PatternReplaceFilterFactory" pattern="^([0-9]{0,2})([\.,][0-9]{1,2})?$" replacement="0 - 99" replace="all" />
    <filter class="solr.PatternReplaceFilterFactory" pattern="^(1[0-9][0-9]|2[0-4][0-9]|)([\.,][0-9]{1,2})?$" replacement="100 - 249" replace="all" />
    <filter class="solr.PatternReplaceFilterFactory" pattern="^(2[5-9][0-9]|[3-4][0-9][0-9])([\.,][0-9]{1,2})?$" replacement="250 - 499" replace="all" />
    <filter class="solr.PatternReplaceFilterFactory" pattern="^([5-9][0-9][0-9])([\.,][0-9]{1,2})?$" replacement="500 - 999" replace="all" />
    <filter class="solr.PatternReplaceFilterFactory" pattern="^([0-9]{4,5})([\.,][0-9]{1,2})?$" replacement="999 -" replace="all" />
  </analyzer>
</fieldtype>

It adds to your index size, but is optimized for query speed.

--
Jan Høydahl, search solution architect
Cominvent AS - www.cominvent.com

On 5. nov. 2010, at 16.03, jayant wrote:

>
> Thank you both. Faceting is now working on a range.
> --
> View this message in context: http://lucene.472066.n3.nabble.com/How-to-Facet-on-a-price-range-tp1846392p1848716.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

jayant
That was very well thought of and a clever solution. Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

britske
Just to add to this, if you want to allow the user more choice in his option
to select ranges, perhaps by using a 2-sided javasacript slider for the
pricerange (ala kayak.com) it may be very worthwhile to discretize the
allowed values for the slider (e.g: steps of 5 dolllar) Most js-slider
implementations allow for this easily.

This has the advantages of:
- having far fewer possible facetqueries and thus a far greater chance of
these facetqueries hitting the cache.
- a better user-experience, although that's debatable.

just to be clear: for this the Solr-side would still use:
&facet=on&facet.query=price:[50
TO *]&facet.query=price:[* TO 100] and not the optimized pre-computed
variant suggested above.

Geert-Jan

2010/11/9 jayant <[hidden email]>

>
> That was very well thought of and a clever solution. Thanks.
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/How-to-Facet-on-a-price-range-tp1846392p1869201.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

Gijs Kunze
Hi,

Instead of all the facet queries, you can also make use of range facets
(http://wiki.apache.org/solr/SimpleFacetParameters#Facet_by_Range),
which is in trunk afaik, it should also be patchable into older versions
of Solr, although that should not be necessary.

We make use of it (http://www.mysecondhome.co.uk/search.html) to create
the nice sliders Geert-Jan describes. We've also used it to add the
sparklines above the sliders which give a nice indication of how the
current selection is spread out.

Regards,

gwk

On 11/9/2010 3:33 PM, Geert-Jan Brits wrote:

> Just to add to this, if you want to allow the user more choice in his option
> to select ranges, perhaps by using a 2-sided javasacript slider for the
> pricerange (ala kayak.com) it may be very worthwhile to discretize the
> allowed values for the slider (e.g: steps of 5 dolllar) Most js-slider
> implementations allow for this easily.
>
> This has the advantages of:
> - having far fewer possible facetqueries and thus a far greater chance of
> these facetqueries hitting the cache.
> - a better user-experience, although that's debatable.
>
> just to be clear: for this the Solr-side would still use:
> &facet=on&facet.query=price:[50
> TO *]&facet.query=price:[* TO 100] and not the optimized pre-computed
> variant suggested above.
>
> Geert-Jan
>
> 2010/11/9 jayant<[hidden email]>
>
>> That was very well thought of and a clever solution. Thanks.
>> --
>> View this message in context:
>> http://lucene.472066.n3.nabble.com/How-to-Facet-on-a-price-range-tp1846392p1869201.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

britske
@ http://www.mysecondhome.co.uk/search.htm<http://www.mysecondhome.co.uk/search.html>
-->
when you drag the sliders , an update of how many results would match is
immediately shown. I really like this. How did you do this? IS this
out-of-the-box available with the suggested Facet_by_range patch?

Thanks,
Geert-Jan

2010/11/9 gwk <[hidden email]>

> Hi,
>
> Instead of all the facet queries, you can also make use of range facets (
> http://wiki.apache.org/solr/SimpleFacetParameters#Facet_by_Range), which
> is in trunk afaik, it should also be patchable into older versions of Solr,
> although that should not be necessary.
>
> We make use of it (http://www.mysecondhome.co.uk/search.html) to create
> the nice sliders Geert-Jan describes. We've also used it to add the
> sparklines above the sliders which give a nice indication of how the current
> selection is spread out.
>
> Regards,
>
> gwk
>
>
> On 11/9/2010 3:33 PM, Geert-Jan Brits wrote:
>
>> Just to add to this, if you want to allow the user more choice in his
>> option
>> to select ranges, perhaps by using a 2-sided javasacript slider for the
>> pricerange (ala kayak.com) it may be very worthwhile to discretize the
>> allowed values for the slider (e.g: steps of 5 dolllar) Most js-slider
>> implementations allow for this easily.
>>
>> This has the advantages of:
>> - having far fewer possible facetqueries and thus a far greater chance of
>> these facetqueries hitting the cache.
>> - a better user-experience, although that's debatable.
>>
>> just to be clear: for this the Solr-side would still use:
>> &facet=on&facet.query=price:[50
>> TO *]&facet.query=price:[* TO 100] and not the optimized pre-computed
>> variant suggested above.
>>
>> Geert-Jan
>>
>> 2010/11/9 jayant<[hidden email]>
>>
>>  That was very well thought of and a clever solution. Thanks.
>>> --
>>> View this message in context:
>>>
>>> http://lucene.472066.n3.nabble.com/How-to-Facet-on-a-price-range-tp1846392p1869201.html
>>> Sent from the Solr - User mailing list archive at Nabble.com.
>>>
>>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

Gijs Kunze
On 11/9/2010 7:32 PM, Geert-Jan Brits wrote:
> when you drag the sliders , an update of how many results would match is
> immediately shown. I really like this. How did you do this? IS this
> out-of-the-box available with the suggested Facet_by_range patch?

Hi,

With the range facets you get the facet counts for every discrete step
of the slider, these values are requested in the AJAX request whenever
search criteria change and then someone uses the sliders we simply check
the range that is selected and add the discrete values of that range to
get the expected amount of results. So yes it is available, but as Solr
is just the search backend the frontend stuff you'll have to write yourself.

Regards,

gwk
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

britske
Ah I see: like you said it's part of the facet range implementation.
Frontend is already working, just need the 'update-on-slide' behavior.

Thanks
Geert-Jan

2010/11/10 gwk <[hidden email]>

> On 11/9/2010 7:32 PM, Geert-Jan Brits wrote:
>
>> when you drag the sliders , an update of how many results would match is
>> immediately shown. I really like this. How did you do this? IS this
>> out-of-the-box available with the suggested Facet_by_range patch?
>>
>
> Hi,
>
> With the range facets you get the facet counts for every discrete step of
> the slider, these values are requested in the AJAX request whenever search
> criteria change and then someone uses the sliders we simply check the range
> that is selected and add the discrete values of that range to get the
> expected amount of results. So yes it is available, but as Solr is just the
> search backend the frontend stuff you'll have to write yourself.
>
> Regards,
>
> gwk
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to Facet on a price range

Govind Kanshi
Kudos to Jan's pre-compute option and gwk's range facet answer.

On Wed, Nov 10, 2010 at 2:52 PM, Geert-Jan Brits <[hidden email]> wrote:

> Ah I see: like you said it's part of the facet range implementation.
> Frontend is already working, just need the 'update-on-slide' behavior.
>
> Thanks
> Geert-Jan
>
> 2010/11/10 gwk <[hidden email]>
>
> > On 11/9/2010 7:32 PM, Geert-Jan Brits wrote:
> >
> >> when you drag the sliders , an update of how many results would match is
> >> immediately shown. I really like this. How did you do this? IS this
> >> out-of-the-box available with the suggested Facet_by_range patch?
> >>
> >
> > Hi,
> >
> > With the range facets you get the facet counts for every discrete step of
> > the slider, these values are requested in the AJAX request whenever
> search
> > criteria change and then someone uses the sliders we simply check the
> range
> > that is selected and add the discrete values of that range to get the
> > expected amount of results. So yes it is available, but as Solr is just
> the
> > search backend the frontend stuff you'll have to write yourself.
> >
> > Regards,
> >
> > gwk
> >
>
Loading...