diff --git a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FullText.php b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FullText.php index 2b17830ac3..8c4e07d8e5 100644 --- a/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FullText.php +++ b/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/FullText.php @@ -146,17 +146,20 @@ protected function tokenizeString($string) */ protected function getWordExpression(QueryBuilder $query, string $token): string { - if ($this->configuration['enableWildcards'] && $token[0] === '*') { - return $query->expr()->like( - 'word', - $query->createNamedParameter('%' . substr($token, 1)) - ); - } + $hasLeadingWildcard = str_starts_with($token, '*'); + $hasTrailingWildcard = str_ends_with($token, '*'); + if ($this->configuration['enableWildcards'] && ($hasLeadingWildcard || $hasTrailingWildcard)) { + $token = $hasLeadingWildcard ? substr($token, 1) : $token; + $token = $hasTrailingWildcard ? substr($token, 0, -1) : $token; + + $token = str_replace('%', '\\%', $token); + + $token = $hasLeadingWildcard ? '%' . $token : $token; + $token = $hasTrailingWildcard ? $token . '%' : $token; - if ($this->configuration['enableWildcards'] && $token[strlen($token) - 1] === '*') { return $query->expr()->like( 'word', - $query->createNamedParameter(substr($token, 0, -1) . '%') + $query->createNamedParameter($token) ); } diff --git a/tests/integration/Core/Repository/SearchServiceFulltextTest.php b/tests/integration/Core/Repository/SearchServiceFulltextTest.php index a1af8b37a8..15725d4208 100644 --- a/tests/integration/Core/Repository/SearchServiceFulltextTest.php +++ b/tests/integration/Core/Repository/SearchServiceFulltextTest.php @@ -165,6 +165,10 @@ public function providerForTestFulltextSearchSolr7(): array 'qui*', [[1, 5, 6, 7, 11, 12, 13, 15]], ], + [ + '*row*', + [[2, 5, 8, 9, 11, 12, 14, 15]], + ], [ '+qui* +fox', [6, [11, 13], 15],