Kuan
Kuan

Reputation: 11389

How to do a grouping(or range query) in Solr facet

All:

[UPDATE] Thanks for Andrea's answer, currently I am using this way:

If you send also a facet.mincount=1 then the start bound is just an indication because Solr will return only those values (i.e. ranges) that have at least 1 document inside. So for instance you could indicate a very low value as start.

Note: This is only proved works for my case, so use your judgement

&facet=true&facet.range=createDate&facet.range.gap=%2B2DAY&facet.range.end=NOW&facet.range.start=NOW-1000DAY&facet.mincount=1


I am pretty new to Solr facet. Suppose that I have some documents which has createDate:

"2015-03-23T17:59:00Z",
"2015-03-23T22:13:00Z",
"2015-03-17T20:48:00Z",
"2015-03-19T17:43:00Z",
"2015-03-19T21:58:00Z",
"2015-03-16T19:13:00Z",
"2015-03-16T22:26:00Z",
"2015-03-13T21:33:00Z",
"2015-03-13T21:39:00Z",
"2015-03-13T23:27:00Z",
"2015-03-16T16:46:00Z",
"2015-03-18T17:44:00Z",
"2015-03-18T18:10:00Z",
"2015-03-18T18:11:00Z"
.......

My questions are :

[1] How to get the result range by DAY?

[2] How to get facet result grouped by WEEK( or let us say 7 days)?

Thanks

Upvotes: 0

Views: 1158

Answers (1)

Andrea
Andrea

Reputation: 2764

It is called range faceting. I suggest you to read the Solr wiki but in the meantime:

facet.range=(field name)
facet.range.start=(start date or value)
facet.range.end=(end date or value)
facet.range.gap=(interval value or expression)

In your case you should use +1DAY or +7DAYS as facet.range.gap. There are also other parmeters so it's better if you have a look at the wiki

Upvotes: 3

Related Questions