Skip to content

Commit

Permalink
TASK: Use mre fine-grained sanitation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daniellienert committed Jan 26, 2021
1 parent 1b707c1 commit 0c43a79
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Classes/Controller/SuggestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ protected function buildRequestForTerm(string $term, string $contextNodeIdentifi
$term = strtolower($term);

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

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

0 comments on commit 0c43a79

Please sign in to comment.