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-337: Added AggregationResultAwareInterface #212

Merged
merged 3 commits into from
May 21, 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
@@ -0,0 +1,14 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Repository\Values\Content\Search;

interface AggregationResultAwareInterface
{
public function getAggregations(): ?AggregationResultCollection;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* This class represents a search result.
*/
class SearchResult extends ValueObject implements IteratorAggregate
class SearchResult extends ValueObject implements IteratorAggregate, AggregationResultAwareInterface
{
/**
* The facets for this search.
Expand Down Expand Up @@ -86,6 +86,11 @@ public function __construct(array $properties = [])
parent::__construct($properties);
}

public function getAggregations(): ?AggregationResultCollection
{
return $this->aggregations;
}

public function getIterator(): Iterator
{
return new ArrayIterator($this->searchHits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getSlice($offset, $length)
$this->languageFilter
);

$this->aggregations = $searchResult->aggregations;
$this->aggregations = $searchResult->getAggregations();
$this->time = $searchResult->time;
$this->timedOut = $searchResult->timedOut;
$this->maxScore = $searchResult->maxScore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getSlice($offset, $length)

public function getAggregations(): AggregationResultCollection
{
return $this->searchResult->aggregations;
return $this->searchResult->getAggregations();
}

public function getTime(): ?float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testFindContentWithAggregation(
$expectedResult,
$searchService->findContent(
$this->createContentQuery($aggregation)
)->aggregations->first()
)->getAggregations()->first()
);
}

Expand All @@ -67,7 +67,7 @@ public function testFindLocationWithAggregation(
$expectedResult,
$searchService->findLocations(
$this->createLocationQuery($aggregation)
)->aggregations->first()
)->getAggregations()->first()
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Pagination/FixedSearchResultHitAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testFixedSearchResultHitAdapter(): void

$this->assertEquals($searchResult->totalCount, $adapter->getNbResults());
$this->assertEquals($searchResult->searchHits, $adapter->getSlice(0, 10));
$this->assertEquals($searchResult->aggregations, $adapter->getAggregations());
$this->assertSame($searchResult->getAggregations(), $adapter->getAggregations());
$this->assertEquals($searchResult->maxScore, $adapter->getMaxScore());
$this->assertEquals($searchResult->time, $adapter->getTime());
$this->assertEquals($searchResult->timedOut, $adapter->getTimedOut());
Expand Down