I am using apache solr search with my drupal 6 website and seek a modification in the facets being displayed.

Instead of the yearly facets like this:

enter image description here

to somewhat like this:

last hour
last 24 hours
last week
last month
last year

I found http://searchhub.org/dev/2012/02/23/date-math-now-and-filter-queries/ saying that i can use fq=date:[NOW/DAY-7DAYS TO NOW/DAY+1DAY] in a custom module of my own to do this.

I tried this in my own module and figured out that its the $fq variable of apachesolr.module that should be overriden to achieve this.

I dont think I was able to use it successfully.

Can someone please tell me the exact function and variable to override.


If i clearly understand you will have to use facets date.

And using Solr there's a issue where you cannot do multiple facets on the same field in the same query... This issue is now marked as fixed Solr backlog but the release is not ready yet i believe last time i checked. In my case since the fixed was not ready i created in the schema new field that are copyfields and i do the appropriate query.

Therefore you will have something like that :

Last hour


Last 24 hours


Last 48 hours


Last Week



Hi hope that helps you!!! Cuz i've look so long to figured out myself ;)

  • What about for "Today" means if i want to get record for today date ignore time from date field. – Rikin Patel Jul 22 '14 at 7:24

I'm aware of the question actually has been asked over a year ago. However, I found it on Google and it pointed me in the wrong direction.

There is another way how you can achieve multiple date ranges without using copy fields in Solr. At first I thought this would be possible by specifing multiple facet.range.gap values. However, according to this issue, it is not possible (yet): https://issues.apache.org/jira/browse/SOLR-2366

So how am I doing it? By specifing multiple facet.query parameters this works:

facet.query=modified:[NOW-1DAY TO NOW]
facet.query=modified:[NOW-7DAY TO NOW]
facet.query=modified:[NOW-31DAY TO NOW]
facet.query=modified:[NOW-365DAY TO NOW]

The response will therefor look like this:

facet_counts: {
facet_queries: {
modified:[NOW-1DAY TO NOW]: 0,
modified:[NOW-7DAY TO NOW]: 27,
modified:[NOW-31DAY TO NOW]: 619,
modified:[NOW-365DAY TO NOW]: 9732
facet_fields: {} ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.