Skip to content

Commit

Permalink
EZP-32107: Added integration test for score sort clause
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Oct 27, 2020
1 parent af95901 commit 762f985
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions eZ/Publish/API/Repository/Tests/SearchServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace eZ\Publish\API\Repository\Tests;

use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator;
use EzSystems\EzPlatformSolrSearchEngine\Tests\SetupFactory\LegacySetupFactory as LegacySolrSetupFactory;
use InvalidArgumentException;
Expand Down Expand Up @@ -5159,6 +5160,8 @@ public function testSortingByNumericFieldsWithValuesOfDifferentLength(

$result = $searchService->findLocations($query);

$this->assertSearchResultOrder($expectedOrderedIds, $result);

self::assertEquals(count($expectedOrderedIds), $result->totalCount);
$actualIds = array_map(
static function (SearchHit $searchHit) {
Expand Down Expand Up @@ -5224,4 +5227,92 @@ public function providerForTestSortingByNumericFieldsWithValuesOfDifferentLength
[15, 5],
];
}

/**
* @dataProvider providerForTestSortingByScore
*/
public function testSortingByScore(Query $query, array $expectedOrderedIds): void
{
$searchService = $this->getRepository()->getSearchService();

if (!$searchService->supports(SearchService::CAPABILITY_SCORING)) {
self::markTestSkipped("Search engine doesn't support scoring");
}

if ($query instanceof LocationQuery) {
$actualResults = $searchService->findLocations($query);
} else {
$actualResults = $searchService->findContent($query);
}

$this->assertSearchResultOrder($expectedOrderedIds, $actualResults);
}

public function providerForTestSortingByScore(): iterable
{
$query = new Criterion\FullText('User');

yield 'content asc' => [
new Query([
'query' => $query,
'sortClauses' => [
new SortClause\Score(Query::SORT_ASC),
new SortClause\ContentId(),
],
]),
[42, 10, 14],
];

yield 'content desc' => [
new Query([
'query' => $query,
'sortClauses' => [
new SortClause\Score(Query::SORT_DESC),
new SortClause\ContentId(),
],
]),
[10, 14, 42],
];

yield 'location asc' => [
new LocationQuery([
'query' => $query,
'sortClauses' => [
new SortClause\Score(Query::SORT_ASC),
new SortClause\ContentId(),
],
]),
[44, 45, 15],
];

yield 'location desc' => [
new LocationQuery([
'query' => $query,
'sortClauses' => [
new SortClause\Score(Query::SORT_DESC),
new SortClause\ContentId(),
],
]),
[45, 15, 44],
];
}

private function assertSearchResultOrder(
array $expectedOrderedIds,
SearchResult $actualSearchResults
): void {
self::assertEquals(
count($expectedOrderedIds),
$actualSearchResults->totalCount
);

$actualIds = array_map(
static function (SearchHit $searchHit) {
return $searchHit->valueObject->id;
},
$actualSearchResults->searchHits
);

self::assertEquals($expectedOrderedIds, $actualIds);
}
}

0 comments on commit 762f985

Please sign in to comment.