Skip to content

Commit

Permalink
Merge branch 'feature/elisions' into v3
Browse files Browse the repository at this point in the history
Fixes #12467
Resolves #12474
  • Loading branch information
brandonkelly committed Dec 23, 2022
2 parents 8e1018e + f0567ba commit 5524417
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
- Template caching is no longer enabled for tokenized requests. ([#12458](https://github.com/craftcms/cms/issues/12458))
- Elisions are now stripped from search keywords. ([#12467](https://github.com/craftcms/cms/issues/12467), [#12474](https://github.com/craftcms/cms/pull/12474))
- Fixed an error that could occur when processing template caches in a console request, if a globally-scoped template cache was processed before it.

## 3.7.62 - 2022-12-13
Expand Down
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($str, array $ignore = [], bool $process
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($str, array $ignore = [], bool $process
return trim(preg_replace(['/[\n\r]+/u', '/\s{2,}/u'], ' ', $str));
}

/**
* Returns an array of elisions to remove 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 5524417

Please sign in to comment.