Search only for the currently active language How can I restrict the results from a default search in Drupal 7, to bring only the nodes that are in the current language?

My website has a three language switcher; the user chooses what language he wants to use when viewing the site. If he searches something, the result page bring results from other languages. Today I have only 3 enabled languages, but we plan to expand this to 6 or more.
There's a really elegant way to do this using the apparently undocumented hook_query_node_access_alter():

function yourmodule_query_node_access_alter(QueryAlterableInterface $query) {
  $search = FALSE;
  $node = FALSE;

  // Even though we know the node alias is going to be "n", by checking for the
  // search_index table we make sure we're on the search page. Omitting this step will
  // break the default admin/content page.
  foreach ($query-&gt;getTables() as $alias =&gt; $table) {
    if ($table['table'] == 'search_index') {
      $search = $alias;
    }
    elseif ($table['table'] == 'node') {
      $node = $alias;
    }
  }

  // Make sure we're on the search page.
  if ($node &amp;&amp; $search) {
    $db_and = db_and();
    // I guess you *could* use global $language here instead but this is safer.
    $language = i18n_language_interface();
    $lang = $language-&gt;language;

    $db_and-&gt;condition($node . '.language', $lang, '=');
    $query-&gt;condition($db_and);
  }
}


Note: this code is 100% based on the excellent Search Config module.

User's vs Content language

Some sites might have language detection configured to show the interface in the user's preferred language, while the page content is shown based on the URL or content language. 

In that case, consider replacing 

$language = i18n_language_interface();


with

$language = i18n_language_content();