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

[BUGFIX] Fixes multiple sortings #3762

Merged
merged 1 commit into from
Oct 12, 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
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
Loading