Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

The purpose of http://api.drupal.org/api/function/hook_search_preprocess/7 is to allow stemming (and perhaps other) modules to pre-process text before it is added to the index in the search module, or used as input to a query on the search index. As it is currently in Drupal 6 and 7, the hook has only a single parameter, which is the text to be pre-processed.

This works fine for a single-language site, where you would likely only have a single stemming module. But for a multi-lingual site, with presumably multiple stemming modules, the stemming modules have no way of knowing which language the text is in.

The change that was committed fixes all the problematic parts above and does allow contrib modules to stem search content with language specific variables out of the box.

Drupal 7

function hook_search_preprocess($text) {
  // Do processing on $text
  return $text;
}

Drupal 8

function hook_search_preprocess($text, $langcode = NULL) {
   // Do processing on $text

  // $langcode example:
  // If the langcode is set and is 'en' then add 'en_text' to each $text. Using
  // this everything with $langcode 'en' will also be found by 'en_text'.
  if (isset($langcode) && $langcode == 'en') {
    $text .= 'en_text';
  }
  return $text;
}
Impacts: 
Module developers