diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index c0352e7..d61ee35 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -15,7 +15,7 @@ * * This hook is called to preprocess both the text added to the search index * and the keywords users have submitted for searching. The same processing - * needs to be applied to both so that searches will return results. + * needs to be applied to both so that searches will find matches. * * Possible uses: * - Adding spaces between words of Chinese or Japanese text. @@ -47,9 +47,14 @@ * @ingroup search */ function hook_search_preprocess($text, $langcode = NULL) { + // If the language is not set, get it from the language manager. + if (!isset($langcode)) { + $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); + } + // If the langcode is set to 'en' then add variations of the word "testing" // which can also be found during English language searches. - if (isset($langcode) && $langcode == 'en') { + if ($langcode == 'en') { // Add the alternate verb forms for the word "testing". if ($text == 'we are testing') { $text .= ' test tested';