public function ApacheSolrFacetapiDate::execute in Apache Solr Search 7
Same name and namespace in other branches
- 8 plugins/facetapi/query_type_date.inc \ApacheSolrFacetapiDate::execute()
- 6.3 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;
$facet_name = $query
->getSolrVersion() >= 6 ? 'facet.range' : 'facet.date';
$query
->addParam($facet_name, $this->facet['field']);
$query
->addParam('f.' . $this->facet['field'] . '.' . $facet_name . '.start', $start);
$query
->addParam('f.' . $this->facet['field'] . '.' . $facet_name . '.end', $end);
$query
->addParam('f.' . $this->facet['field'] . '.' . $facet_name . '.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);
}
}