Skip to content

Commit

Permalink
Strip elisions from search keywords
Browse files Browse the repository at this point in the history
Fixes #12467
  • Loading branch information
brianjhanson committed Dec 19, 2022
1 parent 9cf3beb commit d4ea8f3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/helpers/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public static function normalizeKeywords(array|string $str, array $ignore = [],
if ($processCharMap) {
$str = strtr($str, StringHelper::asciiCharMap(true, $language ?? Craft::$app->language));

$elisions = self::_getElisions();
$str = str_replace($elisions, '', $str);

// Remove punctuation and diacritics
$punctuation = self::_getPunctuation();
$str = str_replace(array_keys($punctuation), $punctuation, $str);
Expand All @@ -68,6 +71,36 @@ public static function normalizeKeywords(array|string $str, array $ignore = [],
return trim(preg_replace(['/[\n\r]+/u', '/\s{2,}/u'], ' ', $str));
}

/**
* Returns an array of [elisions](https://en.wikipedia.org/wiki/Elision) that will be stripped from search keywords.
*
* @return array
*/
private static function _getElisions(): array
{
static $elisions = [];

if (empty($elisions)) {
$elisions = [
"l'",
"m'",
"t'",
"qu'",
"n'",
"s'",
"j'",
"d'",
"c'",
"jusqu'",
"quoiqu'",
"lorsqu'",
"puisqu'",
];
}

return $elisions;
}

/**
* Returns the asciiPunctuation array.
*
Expand Down

0 comments on commit d4ea8f3

Please sign in to comment.