Commit 4249f2f4 authored by mkalkbrenner's avatar mkalkbrenner Committed by borisson_

Issue #2999788 by mkalkbrenner, borisson_: Support native range facets in the Solr Backend

parent 2c0601cb
......@@ -137,3 +137,12 @@ plugin.plugin_configuration.facets_processor.granularity_item:
max_value:
type: integer
label: 'Maximum value'
include_lower:
type: boolean
label: 'Include lower bounds'
include_upper:
type: boolean
label: 'Include upper bounds'
include_edges:
type: boolean
label: 'Include first lower and last upper bound'
......@@ -25,6 +25,14 @@ class GranularItemProcessor extends ProcessorPluginBase implements BuildProcesso
* {@inheritdoc}
*/
public function build(FacetInterface $facet, array $results) {
/** @var \Drupal\facets\Result\ResultInterface $result */
foreach ($results as $result) {
$value = $result->getRawValue();
if (is_numeric($value)) {
$result->setDisplayValue(((int) $value) . ' - ' . ((int) $value + $this->getConfiguration()['granularity']));
}
}
return $results;
}
......@@ -36,7 +44,10 @@ class GranularItemProcessor extends ProcessorPluginBase implements BuildProcesso
'granularity' => 1,
'min_value' => '',
'max_value' => '',
] + parent::defaultConfiguration();
'include_lower' => TRUE,
'include_upper' => FALSE,
'include_edges' => TRUE,
] + parent::defaultConfiguration();
}
/**
......@@ -69,6 +80,24 @@ class GranularItemProcessor extends ProcessorPluginBase implements BuildProcesso
'#size' => 10,
];
$build['include_lower'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include lower bounds'),
'#default_value' => $configuration['include_lower'],
];
$build['include_upper'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include upper bounds'),
'#default_value' => $configuration['include_upper'],
];
$build['include_edges'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include first lower and last upper bound'),
'#default_value' => $configuration['include_edges'],
];
return $build;
}
......
......@@ -51,9 +51,8 @@ class SearchApiGranular extends QueryTypeRangeBase {
* {@inheritdoc}
*/
protected function getFacetOptions() {
return parent::getFacetOptions() + [
'granularity' => $this->getGranularity(),
];
return $this->facet->getProcessors()['granularity_item']->getConfiguration()
+ parent::getFacetOptions();
}
/**
......
......@@ -93,6 +93,7 @@ abstract class QueryTypePluginBase extends PluginBase implements QueryTypeInterf
'operator' => $this->facet->getQueryOperator(),
'min_count' => $this->facet->getMinCount(),
'missing' => FALSE,
'query_type' => $this->getPluginId(),
];
}
......
......@@ -274,10 +274,10 @@ class ProcessorIntegrationTest extends FacetsTestBase {
// Check values.
$this->drupalGet('search-api-test-fulltext');
$this->assertFacetLabel('30 (1)');
$this->assertFacetLabel('35');
$this->assertFacetLabel('40');
$this->assertFacetLabel('100');
$this->assertFacetLabel('30 - 31 (1)');
$this->assertFacetLabel('35 - 36');
$this->assertFacetLabel('40 - 41');
$this->assertFacetLabel('100 - 101');
$form = [
'facet_settings[granularity_item][status]' => TRUE,
......@@ -287,10 +287,10 @@ class ProcessorIntegrationTest extends FacetsTestBase {
// Check values.
$this->drupalGet('search-api-test-fulltext');
$this->assertFacetLabel('30 (2)');
$this->assertEmpty($this->findFacetLink('35'));
$this->assertFacetLabel('40');
$this->assertFacetLabel('100');
$this->assertFacetLabel('30 - 40 (2)');
$this->assertEmpty($this->findFacetLink('35 - 36'));
$this->assertFacetLabel('40 - 50');
$this->assertFacetLabel('100 - 110');
}
/**
......
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