lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Høydahl <jan....@cominvent.com>
Subject Re: Month facet - possible bucket values are Jan, Feb, Mar,…. Nov, Dec
Date Wed, 21 Sep 2016 07:15:45 GMT
Extending on Erik’s proposal with facet.query, you could of course develop a custom Function
which takes a date field as input and returns the month number between 1-12.

When used in a facet you would need to select only one month value at a time, and frange QParser
could be used for that. It would look something like:
&facet.query={!frange l=1 u=1 key=Jan}month(cdate)
&facet.query={!frange l=2 u=2 key=Feb}month(cdate)
&facet.query={!frange l=3 u=3 key=Mar}month(cdate)
…

Have not tested this particular combination of facet.query, frange parser and function, but
it could work?

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

> 21. sep. 2016 kl. 01.11 skrev Erik Hatcher <erik.hatcher@gmail.com>:
> 
> Two options come to mind -
> 
>  * index a field for just the month names
>  * leverage facet.query…
> 
>      &facet.query={!key=Jan}cdate:[2003-01-01 TO 2003-01-31] OR cdate:[2004-01-01
TO 2004-01-31]…. 
> 
> I don’t know a way to select just “January’s” from a date field any more elegantly
than that.  
> 
> I’d really go with indexing the month names (in addition to the full date too).
> 
> 	Erik
> 
> 
>> On Sep 20, 2016, at 5:47 PM, Aswath Srinivasan (TMS) <aswath.srinivasan@toyota.com>
wrote:
>> 
>> Hello,
>> 
>> How to build a Month facet from a date field? The facet that I’m looking for should
have a maximum of only 12 buckets. The possible bucket values are Jan, Feb, Mar,…. Nov,
Dec.
>> 
>> http://localhost:8983/solr/collection1/select?facet=on&rows=0&indent=on&q=*:*&wt=json&json.facet.category={type:range,field:cdate,start:"2000-01-01T00:00:00Z",end:NOW,gap:"+1MONTH"}}<http://localhost:8983/solr/pqss_cis/select?facet=on&rows=0&indent=on&q=*:*&wt=json&json.facet.category=%7btype:range,field:cdate,start:%222003-01-01T00:00:00Z%22,end:NOW,gap:%22+1MONTH%22%7d%7d>
>> 
>> This is the query that I have so far but this doesn’t group the facet by Month,
obviously, because of the gap:"+1MONTH"
>> 
>> Really appreciate the help.
>> 
>> Aswath NS
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message