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 "Aswath Srinivasan (TMS)" <as...@toyota.com> on 2016/09/20 21:47:35 UTC
Month facet - possible bucket values are Jan, Feb, Mar,…. Nov, Dec
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
Re: Month facet - possible bucket values are Jan, Feb, Mar,…. Nov, Dec
Posted by Jan Høydahl <ja...@cominvent.com>.
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 <er...@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) <as...@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
>
Re: Month facet - possible bucket values are Jan, Feb, Mar,…. Nov, Dec
Posted by Erik Hatcher <er...@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) <as...@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