From 1f954153eceb4898deb4bb9bb90fd44138363d5d Mon Sep 17 00:00:00 2001 From: Brian Hanson Date: Mon, 19 Dec 2022 15:15:33 -0600 Subject: [PATCH 1/3] Strip elisions from search keywords Fixes #12467 --- src/helpers/Search.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/helpers/Search.php b/src/helpers/Search.php index 1e79074aa72..04dbfefcad6 100644 --- a/src/helpers/Search.php +++ b/src/helpers/Search.php @@ -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); @@ -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](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. * From 36b18ab07c8e5fcd503afc67633f39270a0e4420 Mon Sep 17 00:00:00 2001 From: Brian Hanson Date: Mon, 19 Dec 2022 15:22:31 -0600 Subject: [PATCH 2/3] Remove link --- src/helpers/Search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/Search.php b/src/helpers/Search.php index 04dbfefcad6..6079a34a958 100644 --- a/src/helpers/Search.php +++ b/src/helpers/Search.php @@ -72,7 +72,7 @@ public static function normalizeKeywords($str, array $ignore = [], bool $process } /** - * Returns an array of [elisions](https://en.wikipedia.org/wiki/Elision) that will be stripped from search keywords. + * Returns an array of elisions to remove from search keywords. * * @return array */ From f0567bab64724ebe972c98117ec1f5059cccc368 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Fri, 23 Dec 2022 11:39:37 -0800 Subject: [PATCH 3/3] Release note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4a0e14102c..3c445c83a14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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