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 ji...@svensktnaringsliv.se on 2013/11/12 15:07:47 UTC

Date range faceting with various gap sizes?

Hi,

I'm experimenting with date range faceting, and would like to use different gaps depending on how old the date is. But I am not sure on how to do that.

This is what I have tried, using the java API Solrj 4.0.0 and Solr 4.1.0:

solrQuery.addDateRangeFacet("scheduledate_start_tdate", date1, date2, "+1YEAR");
solrQuery.addDateRangeFacet("scheduledate_start_tdate", date3, date4, "+1MONTH");
solrQuery.setFacetMinCount(1);

The first date interval is between 1990 and 2011, and the second interval is 2011 to 2014.

This results in this URL:

http://localhost:8080/solr/select?q=*:*&facet.range=scheduledate_start_tdate&facet.range=scheduledate_start_tdate&f.scheduledate_start_tdate.facet.range.start=1990-01-01T11%3A00%3A00.000Z&f.scheduledate_start_tdate.facet.range.start=2011-01-01T11%3A00%3A00.000Z&f.scheduledate_start_tdate.facet.range.end=2011-01-01T10%3A59%3A59.999Z&f.scheduledate_start_tdate.facet.range.end=2014-01-01T11%3A00%3A00.000Z&f.scheduledate_start_tdate.facet.range.gap=%2B1YEAR&f.scheduledate_start_tdate.facet.range.gap=%2B1MONTH&facet=true&facet.mincount=1&wt=xml&indent=true

And the response contains this:

<lst name="facet_ranges">
            <lst name="scheduledate_start_tdate">
                         <lst name="counts">
                                     <int name="2006-01-01T11:00:00Z">207</int>
                                     <int name="2007-01-01T11:00:00Z">818</int>
                                     <int name="2008-01-01T11:00:00Z">811</int>
                                     <int name="2009-01-01T11:00:00Z">618</int>
                                     <int name="2010-01-01T11:00:00Z">612</int>
                         </lst>
                         <str name="gap">+1YEAR</str>
                         <date name="start">1990-01-01T11:00:00Z</date>
                         <date name="end">2011-01-01T11:00:00Z</date>
            </lst>
            <lst name="scheduledate_start_tdate">
                         <lst name="counts">
                                     <int name="2006-01-01T11:00:00Z">207</int>
                                     <int name="2007-01-01T11:00:00Z">818</int>
                                     <int name="2008-01-01T11:00:00Z">811</int>
                                     <int name="2009-01-01T11:00:00Z">618</int>
                                     <int name="2010-01-01T11:00:00Z">612</int>
                         </lst>
                         <str name="gap">+1YEAR</str>
                         <date name="start">1990-01-01T11:00:00Z</date>
                         <date name="end">2011-01-01T11:00:00Z</date>
            </lst>
</lst>

Right away I notice that this is incorrect. The second facet range incorrectly uses the same gap, start and end-values as the first one. Can someone understand why? And is there a way to make this work?

Regards
/Jimi

Re: Date range faceting with various gap sizes?

Posted by Chris Hostetter <ho...@fucit.org>.

: I'm experimenting with date range faceting, and would like to use 
: different gaps depending on how old the date is. But I am not sure on 
: how to do that.

What you are trying to do is possible, but the SolrJ helper methods you 
are using predates the ability and doesn't currently work the way it 
should...

: solrQuery.addDateRangeFacet("scheduledate_start_tdate", date1, date2, "+1YEAR");
: solrQuery.addDateRangeFacet("scheduledate_start_tdate", date3, date4, "+1MONTH");

the "addDateRangeFacet" method you are calling is just syntactic sugar for 
the "add(String,String)" method called on the various params: facet.range, 
facet.range.start, etc....

You can see that in the resulting URL you got the params are duplicated -- 
the problem is that when expressed this way, Solr doesn't know when the 
different values of the start/end/gap params should be applied -- it just 
loops over each of the facet.range fields (in your case: the same field 
twice) and then looks for a coorisponding start/end/gap value and finds 
the first one since there are duplicates.

what you want to do can be accomplished (as of Solr 4.3 - see SOLR-1351) 
by using "local params" in the facet.range (or facet.date) params...

http://localhost:8983/solr/select?q=*:*&rows=0&facet=true&facet.range={!facet.range.start=NOW/MONTH%20facet.range.end=NOW/MONTH%2B1MONTH%20facet.range.gap=%2B1DAY}manufacturedate_dt&facet.range={!facet.range.start=NOW/MONTH%20facet.range.end=NOW/MONTH%2B1MONTH%20facet.range.gap=%2B5DAY}manufacturedate_dt

I've opened a new issue to track fixing these sugar methods -- patches 
to improve this would certainly be welcome, but note that it regardless of 
hte SolrJ behavior you'll need to upgrade to at least Solr 4.3 for the 
server side piece to work, and you cna work arround hte client side 
behavior by calling add(String,String) directly.

https://issues.apache.org/jira/browse/SOLR-5443

-Hoss

SV: Date range faceting with various gap sizes?

Posted by ji...@svensktnaringsliv.se.
Directly after I sent my email, I tested using two different field names, instead of the same field name for both range facets. And then it worked.

So, it seems there is a bug that can't handle multiple range facets for the same field name. A workaround is to use a copyfield to another field, and do the second range facet for that second field name. But surely this is a bug in Solr, right? Maybe it has already been reported, but I couldn't find anything.

/Jimi

> -----Ursprungligt meddelande-----
> Från: jimi.hullegard@svensktnaringsliv.se
> [mailto:jimi.hullegard@svensktnaringsliv.se]
> Skickat: den 12 november 2013 15:08
> Till: solr-user@lucene.apache.org
> Ämne: Date range faceting with various gap sizes?
> 
> Hi,
> 
> I'm experimenting with date range faceting, and would like to use different
> gaps depending on how old the date is. But I am not sure on how to do that.
> 
> This is what I have tried, using the java API Solrj 4.0.0 and Solr 4.1.0:
> 
> solrQuery.addDateRangeFacet("scheduledate_start_tdate", date1, date2,
> "+1YEAR"); solrQuery.addDateRangeFacet("scheduledate_start_tdate",
> date3, date4, "+1MONTH"); solrQuery.setFacetMinCount(1);
> 
> The first date interval is between 1990 and 2011, and the second interval is
> 2011 to 2014.
> 
> This results in this URL:
> 
> http://localhost:8080/solr/select?q=*:*&facet.range=scheduledate_start_td
> ate&facet.range=scheduledate_start_tdate&f.scheduledate_start_tdate.fac
> et.range.start=1990-01-
> 01T11%3A00%3A00.000Z&f.scheduledate_start_tdate.facet.range.start=2011
> -01-
> 01T11%3A00%3A00.000Z&f.scheduledate_start_tdate.facet.range.end=2011
> -01-
> 01T10%3A59%3A59.999Z&f.scheduledate_start_tdate.facet.range.end=2014
> -01-
> 01T11%3A00%3A00.000Z&f.scheduledate_start_tdate.facet.range.gap=%2B1
> YEAR&f.scheduledate_start_tdate.facet.range.gap=%2B1MONTH&facet=tru
> e&facet.mincount=1&wt=xml&indent=true
> 
> And the response contains this:
> 
> <lst name="facet_ranges">
>             <lst name="scheduledate_start_tdate">
>                          <lst name="counts">
>                                      <int name="2006-01-01T11:00:00Z">207</int>
>                                      <int name="2007-01-01T11:00:00Z">818</int>
>                                      <int name="2008-01-01T11:00:00Z">811</int>
>                                      <int name="2009-01-01T11:00:00Z">618</int>
>                                      <int name="2010-01-01T11:00:00Z">612</int>
>                          </lst>
>                          <str name="gap">+1YEAR</str>
>                          <date name="start">1990-01-01T11:00:00Z</date>
>                          <date name="end">2011-01-01T11:00:00Z</date>
>             </lst>
>             <lst name="scheduledate_start_tdate">
>                          <lst name="counts">
>                                      <int name="2006-01-01T11:00:00Z">207</int>
>                                      <int name="2007-01-01T11:00:00Z">818</int>
>                                      <int name="2008-01-01T11:00:00Z">811</int>
>                                      <int name="2009-01-01T11:00:00Z">618</int>
>                                      <int name="2010-01-01T11:00:00Z">612</int>
>                          </lst>
>                          <str name="gap">+1YEAR</str>
>                          <date name="start">1990-01-01T11:00:00Z</date>
>                          <date name="end">2011-01-01T11:00:00Z</date>
>             </lst>
> </lst>
> 
> Right away I notice that this is incorrect. The second facet range incorrectly
> uses the same gap, start and end-values as the first one. Can someone
> understand why? And is there a way to make this work?
> 
> Regards
> /Jimi