0

My goal is to get a document count for each month over the past year. Here is the faceted query I am using against Solr 1.4:

q=*:*
rows=0
facet=on
facet.date=myDateField
facet.date.start=NOW-11MONTH/MONTH
facet.date.end=NOW+1MONTH/MONTH
facet.date.gap=+1MONTH

The ranges this query produces are 2013-01-01T00:00:00Z to 2013-02-01T00:00:00Z, which is inclusive for the upper bound, meaning T00:00:00Z on the first of every month is being counted in 2 different ranges.

Solr 3.1 introduces the facet.date.include parameter that would solve my problem, except upgrading right now is not an option. Is there a workaround to achieving the same functionality? I tried facet.date.gap=+1MONTH-1SECOND which is close, but not close enough. It produces something like this where the end date is not correct:

2012-09-01T00:00:00Z
2012-09-30T23:59:59Z
2012-10-30T23:59:58Z
2012-11-30T23:59:57Z
2012-12-30T23:59:56Z
2013-01-30T23:59:55Z
2013-02-28T23:59:54Z
2013-03-28T23:59:53Z
2013-04-28T23:59:52Z
schmimd04
  • 1,444
  • 3
  • 14
  • 23

1 Answers1

0

What you are asking can be done with facet queries instead of facet range. Try something like this:

facet.query=myDateField:[NOW-11MONTH/MONTH TO NOW-10MONTH/MONTH] 
facet.query=myDateField:[NOW-10MONTH/MONTH TO NOW-9MONTH/MONTH] 
facet.query=myDateField:[NOW-9MONTH/MONTH TO NOW-8MONTH/MONTH] ... 

and so on.

Now you have ful control over any single facet, so you can do -1DAY in the last facet if you need to. Have a look at the reference for date math syntax: http://lucene.apache.org/solr/4_4_0/solr-core/org/apache/solr/util/DateMathParser.html

Maurizio In denmark
  • 4,226
  • 2
  • 30
  • 64
  • that still creates a range with an upper bound of the first day of the next month, inclusively. output is the same as my original date facet example – schmimd04 Aug 19 '13 at 20:49
  • you have to work on the last facet. in this way you have full control over it. try to put -1day in the last facet like this: NOW+1MONTH-1DAY/MONTH – Maurizio In denmark Aug 20 '13 at 04:44
  • ah ok, I see now. I will accept your answer because it looks like it should work, but we opted to take a different route. We temporarily modified our data to add 1 second to midnight of the first of every month (ie 2013-08-01T00:00:01Z) to force it outside of the facet range. I know it's a pretty big hack, but it will serve our purpose until we can upgrade Solr. – schmimd04 Aug 20 '13 at 21:09