Reputation: 13
Looking to incorporate a date filter within a Solr Index View. Presently the only option is for the user to manually enter a text date to filter by date. It would be nice to expose a date filter and search by M/d/Y using the 'Between' function which is available in the 'Content' View. Creating a 'Solr Index' View seems to remove that functionality.
I noticed that the Between operator is missing from handler_filter.inc within the Search API module:
public function operator_options() {
return array(
'<' => t('Is smaller than'),
'<=' => t('Is smaller than or equal to'),
'=' => t('Is equal to'),
'<>' => t('Is not equal to'),
'>=' => t('Is greater than or equal to'),
'>' => t('Is greater than'),
);
}
What other code would we need to modify in order to get a more user-friendly date filter available for the user to query?
Upvotes: 0
Views: 1834
Reputation: 11
You can use something like that:
$or = $query->createFilter('AND');
$or->condition('created', $start_date, '>=');
$or->condition('created', $end_date, '<=');
$query->filter($or);
in hook_search_api_query_alter
.
Upvotes: 1