diff --git a/ChangeLog b/ChangeLog index 88a23b363..25f7d7230 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ ChangeLog Upcoming version [FEATURE] Show additional fields which are registered by other extensions in "Indexed content" function of the backend module +[BUGFIX] Make it possible to have multiple "orderBy" parts in the search result query in TYPO3 13 +[TASK] Add special treatment for the ke_search_premium "Custom Ranking" feature in the search result query "orderBy" part [TASK] Make it possible to add "having" in the search result query Version 6.1.2, 15 November 2024 diff --git a/Classes/Lib/Db.php b/Classes/Lib/Db.php index ac5c9cd62..a79ae43b1 100644 --- a/Classes/Lib/Db.php +++ b/Classes/Lib/Db.php @@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Log\Logger; use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; /*************************************************************** @@ -144,8 +145,38 @@ public function getSearchResultByMySQL() $resultQuery->groupBy($groupParts[0], $groupParts[1]); } if (!empty($queryParts['ORDERBY'])) { - $orderParts = explode(' ', $queryParts['ORDERBY']); - $resultQuery->orderBy($orderParts[0], $orderParts[1]); + $orderChain = explode(',', $queryParts['ORDERBY']); + $count = 0; + foreach ($orderChain as $order) { + $orderParts = explode(' ', $order); + $orderField = strtoupper($orderParts[0]); + $orderDirection = strtoupper($orderParts[1] ?? 'ASC'); + if ($count == 0) { + if (ExtensionManagementUtility::isLoaded('ke_search_premium') + && ($orderField == 'customranking')) { + // We cast `customranking` to integer because additionalFields in ke_search can only + // be string, so we cannot use an integer field, although it's a numeric value (can also be + // negative). + $resultQuery->getConcreteQueryBuilder()->orderBy( + 'CAST(' . $queryBuilder->quoteIdentifier($orderField) . ' AS SIGNED)', + $orderDirection + ); + } else { + $resultQuery->orderBy($orderField, $orderDirection); + } + } else { + if (ExtensionManagementUtility::isLoaded('ke_search_premium') + && ($orderField == 'customranking')) { + $resultQuery->getConcreteQueryBuilder()->addOrderBy( + 'CAST(' . $queryBuilder->quoteIdentifier($orderField) . ' AS SIGNED)', + $orderDirection + ); + } else { + $resultQuery->addOrderBy($orderField, $orderDirection); + } + } + $count++; + } } if (!empty($queryParts['HAVING'])) { $resultQuery->having($queryParts['HAVING']);