Commit ac6b4dcc authored by mkalkbrenner's avatar mkalkbrenner Committed by borisson_

Issue #3018546 by andy_w, mkalkbrenner, borisson_, morenstrat, a.dmitriiev,...

Issue #3018546 by andy_w, mkalkbrenner, borisson_, morenstrat, a.dmitriiev, KarimB: Date items alongside Search API Solr version 2
parent 92d8ecc9
......@@ -3,6 +3,7 @@
namespace Drupal\facets\Plugin\facets\query_type;
use Drupal\facets\QueryType\QueryTypeRangeBase;
use Drupal\facets\Result\Result;
/**
* Basic support for numeric facets grouping by a granularity value.
......@@ -27,6 +28,39 @@ class SearchApiGranular extends QueryTypeRangeBase {
];
}
/**
* {@inheritdoc}
*/
public function build() {
// If there were no results or no query object, we can't do anything.
if (empty($this->results)) {
return $this->facet;
}
$supportedFeatures = array_flip($this->query
->getIndex()
->getServerInstance()
->getBackend()
->getSupportedFeatures());
// Range grouping is supported.
if (isset($supportedFeatures['search_api_granular'])) {
$query_operator = $this->facet->getQueryOperator();
$facet_results = [];
foreach ($this->results as $result) {
if ($result['count'] || $query_operator == 'or') {
$result_filter = trim($result['filter'], '"');
$facet_results[] = new Result($this->facet, $result_filter, $result_filter, $result['count']);
}
}
$this->facet->setResults($facet_results);
return $this->facet;
}
return parent::build();
}
/**
* {@inheritdoc}
*/
......
......@@ -61,34 +61,12 @@ abstract class QueryTypeRangeBase extends QueryTypePluginBase {
* {@inheritdoc}
*/
public function build() {
$query_operator = $this->facet->getQueryOperator();
// If there were no results or no query object, we can't do anything.
if (empty($this->results)) {
return $this->facet;
}
$supportedFeatures = array_flip($this->query
->getIndex()
->getServerInstance()
->getBackend()
->getSupportedFeatures());
// Range grouping is supported.
if (isset($supportedFeatures['search_api_granular'])) {
$facet_results = [];
foreach ($this->results as $result) {
if ($result['count'] || $query_operator == 'or') {
$result_filter = trim($result['filter'], '"');
$facet_results[] = new Result($this->facet, $result_filter, $result_filter, $result['count']);
}
}
$this->facet->setResults($facet_results);
return $this->facet;
}
// Non supported backend range grouping.
$query_operator = $this->facet->getQueryOperator();
$facet_results = [];
foreach ($this->results as $result) {
// Go through the results and add facet results grouped by filters
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment