Skip to content
Snippets Groups Projects

Issue #3190240: SliderProcessor adding results when nothing found

Open Issue #3190240: SliderProcessor adding results when nothing found
All threads resolved!
All threads resolved!
1 file
+ 35
16
Compare changes
  • Side-by-side
  • Inline
@@ -25,44 +25,63 @@ class SliderProcessor extends ProcessorPluginBase implements PostQueryProcessorI
* {@inheritdoc}
*/
public function postQuery(FacetInterface $facet) {
// Only consider facets with results.
$results = $facet->getResults();
if (empty($results)) {
return;
}
$widget = $facet->getWidgetInstance();
$config = $widget->getConfiguration();
$simple_results = [];
// Generate all the "results" between min and max, with the configured step.
foreach ($facet->getResults() as $result) {
$simple_results['f_' . (float) $result->getRawValue()] = [
'value' => (float) $result->getRawValue(),
$simple_results = [];
foreach ($results as $result) {
$rawValue = (float) $result->getRawValue();
$simple_results['f_' . $rawValue] = [
'value' => $rawValue,
'count' => (int) $result->getCount(),
];
}
uasort($simple_results, function ($a, $b) {
uasort($simple_results, static function ($a, $b) {
if ($a['value'] === $b['value']) {
return 0;
}
return $a['value'] < $b['value'] ? -1 : 1;
});
$step = $config['step'];
if ($config['min_type'] == 'fixed') {
// Compute min.
$min = reset($simple_results)['value'] ?? 0;
if (!empty($config['min_type']) && $config['min_type'] === 'fixed') {
$min = $config['min_value'];
}
// Compute max.
$max = end($simple_results)['value'] ?? 0;
if (!empty($config['max_type']) && $config['max_type'] === 'fixed') {
$max = $config['max_value'];
}
else {
$min = reset($simple_results)['value'] ?? 0;
$max = end($simple_results)['value'] ?? 0;
// If max is not divisible by step, we should add the remainder to max to
// make sure that we don't lose any possible values.
if ($max % $step !== 0) {
$max = $max + ($step - $max % $step);
}
// Compute step.
if (!empty($config['step']) && $config['step'] > 0) {
$step = $config['step'];
} else {
$step = max(1, ceil($max / 100));
}
// If max is not divisible by step, we should add the remainder to max to
// make sure that we don't lose any possible values.
if ($max % $step !== 0) {
$max += ($step - $max % $step);
}
// Creates an array of all results between min and max by the step from the
// configuration.
$new_results = [];
for ($i = $min; $i <= $max; $i += $step) {
$count = isset($simple_results['f_' . $i]) ? $simple_results['f_' . $i]['count'] : 0;
$new_result = $simple_results['f_' . $i] ?? NULL;
$count = $new_result !== NULL ? $new_result['count'] : 0;
$new_results[] = new Result($facet, (float) $i, (float) $i, $count);
}
Loading