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
Ports: #3628
  • Loading branch information
BastiLu authored and dkd-kaehm committed Oct 12, 2023
1 parent 729324f commit fafc824
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 @@ -96,9 +96,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 @@ -116,9 +115,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 @@ -339,6 +340,22 @@ public function getHasFacetValue(string $facetName, $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;
}

/**
* @return bool
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,9 @@ public function canReturnSortingsAndMarkedSelectedAsActive()
$searchResultSet->getUsedSearchRequest()->expects(self::any())->method('getHasSorting')->willReturn(true);
$searchResultSet->getUsedSearchRequest()->expects(self::any())->method('getSortingName')->willReturn('title');
$searchResultSet->getUsedSearchRequest()->expects(self::any())->method('getSortingDirection')->willReturn('desc');
$searchResultSet->getUsedSearchRequest()->expects(self::any())->method('getSeperatedSortings')->willReturn(
['title' => 'desc', 'relevance' => 'asc']
);

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

0 comments on commit fafc824

Please sign in to comment.