Skip to content

Commit 0c43a79

Browse files
committed
TASK: Use mre fine-grained sanitation
The previously used `[[:^alnum:]]` strips german umlauts and valid characters of other languages which leeds to strange query results. This is more fine grained approach to sanitize the search word based on elasticsearch recommendations.
1 parent 1b707c1 commit 0c43a79

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Classes/Controller/SuggestController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ protected function buildRequestForTerm(string $term, string $contextNodeIdentifi
114114
$term = strtolower($term);
115115

116116
// The suggest function only works well with one word
117-
// and the term is trimmed to alnum characters to avoid errors
118-
$suggestTerm = preg_replace('/[[:^alnum:]]/', '', explode(' ', $term)[0]);
117+
// special search characters are escaped
118+
$suggestTerm = str_replace(['=', '>', '<', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '\\', '/'], ['', '', '', '(', '\)', '\{', '\}', '[', '\]', '\^', '\"', '\~', '\*', '\?', '\:', '\\\\', '\/'], explode(' ', $term)[0]);
119119

120120
if (!$this->elasticSearchQueryTemplateCache->has($cacheKey)) {
121121
$contentContext = $this->createContentContext('live', $dimensionCombination ? json_decode($dimensionCombination, true) : []);

0 commit comments

Comments
 (0)