Skip to content

Commit 358c49f

Browse files
BastiLudkd-kaehm
authored andcommitted
[BUGFIX] Fixes multiple sortings
When multiple sorting options are passed as an argument the solr server response was not resolved correctly which lead to an TYPO3 Exception. Fixes: #3627
1 parent e2b725c commit 358c49f

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

Classes/Domain/Search/ResultSet/ResultSetReconstitutionProcessor.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ public function process(SearchResultSet $resultSet): SearchResultSet
6262
protected function parseSortingIntoObjects(SearchResultSet $resultSet): SearchResultSet
6363
{
6464
$configuration = $resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration();
65+
$activeSortings = $resultSet->getUsedSearchRequest()->getSeperatedSortings();
6566
$hasSorting = $resultSet->getUsedSearchRequest()->getHasSorting();
66-
$activeSortingName = $resultSet->getUsedSearchRequest()->getSortingName();
67-
$activeSortingDirection = $resultSet->getUsedSearchRequest()->getSortingDirection();
6867

6968
// no configuration available
7069
if (!isset($configuration)) {
@@ -82,9 +81,9 @@ protected function parseSortingIntoObjects(SearchResultSet $resultSet): SearchRe
8281

8382
// when we have an active sorting in the request we compare the sortingName and mark is as active and
8483
// use the direction from the request
85-
if ($hasSorting && $activeSortingName == $sortingName) {
84+
if ($hasSorting && array_key_exists($sortingName, $activeSortings)) {
8685
$selected = true;
87-
$direction = $activeSortingDirection;
86+
$direction = $activeSortings[$sortingName];
8887
}
8988

9089
$field = $sortingOptions['field'];

Classes/Domain/Search/SearchRequest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
2222
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
2323
use TYPO3\CMS\Core\Utility\ArrayUtility;
24+
use TYPO3\CMS\Core\Utility\GeneralUtility;
2425

2526
/**
2627
* The searchRequest is used to act as an api to the arguments that have been passed
@@ -264,6 +265,22 @@ public function getHasFacetValue(string $facetName, mixed $facetValue): bool
264265
return $this->activeFacetContainer->hasFacetValue($facetName, $facetValue);
265266
}
266267

268+
/**
269+
* Returns all sortings in the sorting string e.g. ['title' => 'asc', 'relevance' => 'desc']
270+
*/
271+
public function getSeperatedSortings(): array
272+
{
273+
$parsedSortings = [];
274+
$explodedSortings = GeneralUtility::trimExplode(',', $this->getSorting(), true);
275+
276+
foreach ($explodedSortings as $sorting) {
277+
$sortingSeperated = explode(' ', $sorting);
278+
$parsedSortings[$sortingSeperated[0]] = $sortingSeperated[1];
279+
}
280+
281+
return $parsedSortings;
282+
}
283+
267284
public function getHasSorting(): bool
268285
{
269286
$path = $this->prefixWithNamespace('sort');

Tests/Unit/Domain/Search/ResultSet/ResultSetReconstitutionProcessorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ public function canReturnSortingsAndMarkedSelectedAsActive(): void
10621062
$usedSearchRequest->expects(self::any())->method('getHasSorting')->willReturn(true);
10631063
$usedSearchRequest->expects(self::any())->method('getSortingName')->willReturn('title');
10641064
$usedSearchRequest->expects(self::any())->method('getSortingDirection')->willReturn('desc');
1065+
$usedSearchRequest->expects(self::any())->method('getSeperatedSortings')->willReturn(
1066+
['title' => 'desc', 'relevance' => 'asc']
1067+
);
10651068

10661069
$processor = $this->getConfiguredReconstitutionProcessor($configuration, $searchResultSet);
10671070
$processor->process($searchResultSet);

0 commit comments

Comments
 (0)