Question

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
Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top