Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-6827: Aggregation API improvements #56

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\AbstractRangeAggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\AggregationResult;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\AggregationResult\RangeAggregationResult;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\AggregationResult\RangeAggregationResultEntry;
Expand Down Expand Up @@ -45,23 +44,20 @@ public function extract(Aggregation $aggregation, array $languageFilter, stdClas
$entries = [];

foreach ($data as $key => $bucket) {
if ($key === 'count') {
if ($key === 'count' || strpos($key, '_') === false) {
continue;
}

if (strpos($key, '_') === false) {
continue;
}
$values = explode('_', $key, 2);
$a = $this->keyMapper->map($aggregation, $languageFilter, $values[0]);
$b = $this->keyMapper->map($aggregation, $languageFilter, $values[1]);

list($from, $to) = explode('_', $key, 2);

$entries[] = new RangeAggregationResultEntry(
new Range(
$this->keyMapper->map($aggregation, $languageFilter, $from),
$this->keyMapper->map($aggregation, $languageFilter, $to),
),
$bucket->count
);
foreach ($aggregation->getRanges() as $range) {
if ($range->getFrom() == $a && $range->getTo() == $b) {
$entries[] = new RangeAggregationResultEntry($range, $bucket->count);
break;
}
}
}

$this->sort($aggregation, $entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function dataProviderForTestExtract(): iterable
{
$aggregation = $this->createMock(AbstractRangeAggregation::class);
$aggregation->method('getName')->willReturn(self::EXAMPLE_AGGREGATION_NAME);
$aggregation->method('getRanges')->willReturn([
new Range(Range::INF, 10, 'a'),
new Range(10, 100, 'b'),
new Range(100, Range::INF, 'c'),
]);

yield 'default' => [
$aggregation,
Expand All @@ -78,9 +83,9 @@ public function dataProviderForTestExtract(): iterable
new RangeAggregationResult(
self::EXAMPLE_AGGREGATION_NAME,
[
new RangeAggregationResultEntry(new Range(null, '10'), 10),
new RangeAggregationResultEntry(new Range('10', '100'), 100),
new RangeAggregationResultEntry(new Range('100', null), 1000),
new RangeAggregationResultEntry(new Range(Range::INF, '10', 'a'), 10),
new RangeAggregationResultEntry(new Range('10', '100', 'b'), 100),
new RangeAggregationResultEntry(new Range('100', Range::INF, 'c'), 1000),
]
),
];
Expand Down
Loading