lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gwk <g...@eyefi.nl>
Subject Re: Numerical range faceting
Date Tue, 23 Jun 2009 11:25:03 GMT
gwk wrote:
> Hi,
>
> I'm currently using facet.query to do my numerical range faceting. I 
> basically use a fixed price range of €0 to €10000 in steps of €500 
> which means 20 facet.queries plus an extra facet.query for anything 
> above €10000. I use the inclusive/exclusive query as per my question 
> two days ago so the facets add up to the total number of products. 
> This is done so that the javascript on my search page can accurately 
> show the amount of products returned for a specified range before 
> submitting it to the server by adding up the facet counts for the 
> selected range.
>
> I'm a bit concerned about the amount and size of my request to the 
> server. Especially because there are other numerical values which 
> might be interesting to facet on and I've noticed the server won't 
> response correctly if I add (many) more facet.queries by decreasing 
> the step size. I was really hoping for faceting options for numerical 
> ranges similar to the date faceting options. The functionality would 
> be practically identical as far as I can tell (which isn't very far as 
> I know very little about the internals of Solr) so I was wondering if 
> such options are planned or if I'm overlooking something.
>
> Regards,
>
> gwk
Hello,

Well since I got no response, I flexed my severely atrophied 
Java-muscles (Last time I used the language Swing was new) and dove 
straight into the Solr code. Well, not really, mostly I did some 
copy-pasting and with some assistance from the API Reference I was able 
to add numerical faceting on sortable numerical fields (it seems to work 
for both integers and floating point numbers) with a similar syntax to 
the date faceting.  I also added an extra parameter for whether the 
ranges should be inclusive or exclusive (on either end). And it seems to 
work. Although the quality of my code is not of the same grade as the 
rest of the Solr code (I was amazed how easy it was for me to add this 
feature).
I was wondering if someone is interested in a patch file and if so, 
where should I post it?

Regards,

gwk



As an example, the following query:

http://localhost:8080/select/?q=*%3A*&echoParams=none&rows=0&indent=on&facet=true&
    facet.number=price&f.price.facet.number.start=0&
    f.price.facet.number.end=1000000&f.price.facet.number.gap=10000&
    f.price.facet.number.other=all&f.price.facet.number.exclusive=end

yields the following results:

<?xml version="1.0" encoding="UTF-8"?>
<response>

<lst name="responseHeader">
 <int name="status">0</int>
 <int name="QTime">3</int>
</lst>
<result name="response" numFound="63707" start="0"/>
<lst name="facet_counts">
 <lst name="facet_queries"/>
 <lst name="facet_fields"/>

 <lst name="facet_dates"/>
 <lst name="facet_numbers">
  <lst name="price">
    <int name="0.0">1820</int>
    <int name="10000.0">2697</int>
    <int name="20000.0">2588</int>
    <int name="30000.0">2622</int>

    <int name="40000.0">2459</int>
    <int name="50000.0">2455</int>
    <int name="60000.0">2597</int>
    <int name="70000.0">2530</int>
    <int name="80000.0">2518</int>
    <int name="90000.0">2389</int>

    <!-- SNIP -->

    <int name="940000.0">18</int>
    <int name="950000.0">54</int>
    <int name="960000.0">19</int>
    <int name="970000.0">23</int>
    <int name="980000.0">43</int>
    <int name="990000.0">67</int>

    <double name="gap">10000.0</double>
    <double name="end">1000000.0</double>
    <int name="before">0</int>
    <int name="after">2733</int>
    <int name="between">60974</int>
  </lst>

 </lst>
</lst>
</response>


Mime
View raw message