public function ApacheSolrFacetapiDate::execute in Apache Solr Search 8
Same name and namespace in other branches
- 6.3 plugins/facetapi/query_type_date.inc \ApacheSolrFacetapiDate::execute()
- 7 plugins/facetapi/query_type_date.inc \ApacheSolrFacetapiDate::execute()
Adds the filter to the query object.
Parameters
DrupalSolrQueryInterface $query: An object containing the query in the backend's native API.
File
- plugins/
facetapi/ query_type_date.inc, line 29 - Date query type plugin for the Apache Solr adapter.
Class
- ApacheSolrFacetapiDate
- Plugin for "date" query types.
Code
public function execute($query) {
// Gets the data range in formats that Solr understands.
$date_range = $this
->getDateRange($query);
if (empty($date_range)) {
return NULL;
}
list($start, $end, $gap) = $date_range;
$query
->addParam('facet.date', $this->facet['field']);
$query
->addParam('f.' . $this->facet['field'] . '.facet.date.start', $start);
$query
->addParam('f.' . $this->facet['field'] . '.facet.date.end', $end);
$query
->addParam('f.' . $this->facet['field'] . '.facet.date.gap', $gap);
// Adds "hard limit" parameter to prevent too many return values.
$settings = $this->adapter
->getFacet($this->facet)
->getSettings();
$limit = empty($settings->settings['hard_limit']) ? 20 : (int) $settings->settings['hard_limit'];
$query
->addParam('f.' . $this->facet['field'] . '.facet.limit', $limit);
$active = $this->adapter
->getActiveItems($this->facet);
// Date filters don't support OR operator.
foreach ($active as $value => $item) {
$query
->addFilter($this->facet['field'], $value);
}
}