I've defined a facet for the field "Authored on". I'd like to create display filters like "current week", "current month", etc. on my website.

The creation of the links was no problem. I have facet links like this:

<a href="/news?period=current_week">Current week</a>

How can I manipulate the search query if a period has been selected? I need something like "get all search results, which are younger than tstamp of monday this week" or "get all search results between date X and date Y".

2 Answers 2


Afterwards here my solution: I've solved it with condition groups in the hook_search_api_query_alter() function:

function MYMODULE_search_api_query_alter($query) {

    $conditionGroup = $query->createConditionGroup('AND');
    $conditionGroup->addCondition('created', $firstDayOfYear, '>=');
    $conditionGroup->addCondition('created', $lastDayOfYear, '<=');


You cannot do this easily to my knowledge.

I recently looked at the Search API (7x) module for similar functionality and basically you can do preconfigured Ranges using these modules:

(7x) https://www.drupal.org/project/search_api_ranges this modules treats a range value as a numeric values, which dates are essentially not. Converting to timestamps is a pita.

(7x) the Search API does not support the BETWEEN operator of Solr yet directly for Views integration. See https://www.drupal.org/node/1783746

The only alternative I've found for date searching with Solr (using Search API) is basically 2 exposed filters in Views going off of an Indexed date field in Solr. And then configuring the filter to use the date_popup widget for a nice calendar with day, month and year selection options -- but it's not a simple range or slider widget.

You may get better mileage from the Apache Solr module instead of Search API but I use the Search API module because I can see with little effort it supports Solr 5.x in the module include files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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