Skip to content

Commit

Permalink
[BUGFIX] Allow multiple orderBy parts
Browse files Browse the repository at this point in the history
Make it possible to have multiple "orderBy"
parts in the search result query in TYPO3 13.

Additionally, add a special treatment for
the ke_search_premium "Custom Ranking"
feature in the search result query
"orderBy" part.
  • Loading branch information
christianbltr committed Dec 13, 2024
1 parent f82bc02 commit 8f85784
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 33 additions & 2 deletions Classes/Lib/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/***************************************************************
Expand Down Expand Up @@ -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']);
Expand Down

0 comments on commit 8f85784

Please sign in to comment.