Commit f0eba627 authored by Markus Klein's avatar Markus Klein Committed by Daniel Goerz
Browse files

[TASK] Adjust search syntax for suggest wizard

Use double quotes for exact phrases and space as delimiter
for multiple words/phrases.

Also allow to search for numbers.

Resolves: #89170
Releases: master, 9.5
Change-Id: I5346e8fb54946c5dc4c415507b6c773f0854afbd
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61703

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarSteffen Frese <steffenf14@gmail.com>
Tested-by: default avatarFelix P. <f.pachowsky@neusta.de>
Tested-by: default avatarJulian Geils <j_geils@web.de>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: default avatarSteffen Frese <steffenf14@gmail.com>
Reviewed-by: default avatarFelix P. <f.pachowsky@neusta.de>
Reviewed-by: default avatarJulian Geils <j_geils@web.de>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent b858d635
......@@ -255,36 +255,34 @@ class SuggestWizardDefaultReceiver
protected function buildConstraintBlock(string $searchString)
{
$expressionBuilder = $this->queryBuilder->expr();
$selectParts = $expressionBuilder->orX();
if (MathUtility::canBeInterpretedAsInteger($searchString) && (int)$searchString > 0) {
$searchClause = $expressionBuilder->eq('uid', (int)$searchString);
} else {
$searchWholePhrase = !isset($this->config['searchWholePhrase']) || $this->config['searchWholePhrase'];
$likeCondition = ($searchWholePhrase ? '%' : '') . $this->queryBuilder->escapeLikeWildcards($searchString) . '%';
// Search in all fields given by label or label_alt
$selectFieldsList = ($GLOBALS['TCA'][$this->table]['ctrl']['label'] ?? '') . ',' . ($GLOBALS['TCA'][$this->table]['ctrl']['label_alt'] ?? '') . ',' . $this->config['additionalSearchFields'];
$selectFields = GeneralUtility::trimExplode(',', $selectFieldsList, true);
$selectFields = array_unique($selectFields);
$selectParts = $expressionBuilder->orX();
foreach ($selectFields as $field) {
$selectParts->add($expressionBuilder->like($field, $this->queryBuilder->createPositionalParameter($likeCondition)));
}
$searchClause = $expressionBuilder->orX($selectParts);
$selectParts->add($expressionBuilder->eq('uid', (int)$searchString));
}
return $searchClause;
$searchWholePhrase = !isset($this->config['searchWholePhrase']) || $this->config['searchWholePhrase'];
$likeCondition = ($searchWholePhrase ? '%' : '') . $this->queryBuilder->escapeLikeWildcards($searchString) . '%';
// Search in all fields given by label or label_alt
$selectFieldsList = ($GLOBALS['TCA'][$this->table]['ctrl']['label'] ?? '') . ',' . ($GLOBALS['TCA'][$this->table]['ctrl']['label_alt'] ?? '') . ',' . $this->config['additionalSearchFields'];
$selectFields = GeneralUtility::trimExplode(',', $selectFieldsList, true);
$selectFields = array_unique($selectFields);
foreach ($selectFields as $field) {
$selectParts->add($expressionBuilder->like($field, $this->queryBuilder->createPositionalParameter($likeCondition)));
}
return $selectParts;
}
/**
* Splits the search string by +
* This allows searching for "elements+basic" and will find results like
* "elements rte basic
* Splits the search string by space
* This allows searching for 'elements basic' and will find results like "elements rte basic"
* To search for whole phrases enclose by double-quotes: '"elements basic"', results in empty result
*
* @param string $searchString
* @return array
*/
protected function splitSearchString(string $searchString): array
{
$spitStrings = GeneralUtility::trimExplode('+', $searchString, true);
return $spitStrings;
return str_getcsv($searchString, ' ');
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment