1

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.

2

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

f.date1.facet.range.start=NOW-1HOUR&f.date1.facet.range.end=NOW&f.date1.facet.range.gap=+1HOUR&

Last 24 hours

f.date2.facet.range.start=NOW-24HOUR&f.date2.facet.range.end=NOW&f.date2.facet.range.gap=+24HOUR&

Last 48 hours

f.date3.facet.range.start=NOW-48HOUR&f.date3.facet.range.end=NOW&f.date3.facet.range.gap=+48HOUR&

Last Week

f.date4.facet.range.start=NOW-7DAY&f.date4.facet.range.end=NOW&f.date4.facet.range.gap=+7DAY&

facet.range=date&facet.range=date2&facet.range=date3&facet.range=date4

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
1

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.