Skip to content

Commit

Permalink
[BUGFIX] Fixes multiple sortings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BastiLu authored and dkd-kaehm committed Oct 12, 2023
1 parent e2b725c commit 358c49f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public function process(SearchResultSet $resultSet): SearchResultSet
protected function parseSortingIntoObjects(SearchResultSet $resultSet): SearchResultSet
{
$configuration = $resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration();
$activeSortings = $resultSet->getUsedSearchRequest()->getSeperatedSortings();
$hasSorting = $resultSet->getUsedSearchRequest()->getHasSorting();
$activeSortingName = $resultSet->getUsedSearchRequest()->getSortingName();
$activeSortingDirection = $resultSet->getUsedSearchRequest()->getSortingDirection();

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

// when we have an active sorting in the request we compare the sortingName and mark is as active and
// use the direction from the request
if ($hasSorting && $activeSortingName == $sortingName) {
if ($hasSorting && array_key_exists($sortingName, $activeSortings)) {
$selected = true;
$direction = $activeSortingDirection;
$direction = $activeSortings[$sortingName];
}

$field = $sortingOptions['field'];
Expand Down
17 changes: 17 additions & 0 deletions Classes/Domain/Search/SearchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

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

/**
* Returns all sortings in the sorting string e.g. ['title' => 'asc', 'relevance' => 'desc']
*/
public function getSeperatedSortings(): array
{
$parsedSortings = [];
$explodedSortings = GeneralUtility::trimExplode(',', $this->getSorting(), true);

foreach ($explodedSortings as $sorting) {
$sortingSeperated = explode(' ', $sorting);
$parsedSortings[$sortingSeperated[0]] = $sortingSeperated[1];
}

return $parsedSortings;
}

public function getHasSorting(): bool
{
$path = $this->prefixWithNamespace('sort');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,9 @@ public function canReturnSortingsAndMarkedSelectedAsActive(): void
$usedSearchRequest->expects(self::any())->method('getHasSorting')->willReturn(true);
$usedSearchRequest->expects(self::any())->method('getSortingName')->willReturn('title');
$usedSearchRequest->expects(self::any())->method('getSortingDirection')->willReturn('desc');
$usedSearchRequest->expects(self::any())->method('getSeperatedSortings')->willReturn(
['title' => 'desc', 'relevance' => 'asc']
);

$processor = $this->getConfiguredReconstitutionProcessor($configuration, $searchResultSet);
$processor->process($searchResultSet);
Expand Down

0 comments on commit 358c49f

Please sign in to comment.