Same name and namespace in other branches
  1. 10 core/modules/search/search.api.php \hook_search_preprocess()
  2. 4.6.x developer/hooks/core.php \hook_search_preprocess()
  3. 4.7.x developer/hooks/core.php \hook_search_preprocess()
  4. 6.x developer/hooks/core.php \hook_search_preprocess()
  5. 7.x modules/search/search.api.php \hook_search_preprocess()
  6. 8.9.x core/modules/search/search.api.php \hook_search_preprocess()
  7. 9 core/modules/search/search.api.php \hook_search_preprocess()

Preprocess text for the search index.

This hook is called both for text added to the search index, as well as the keywords users have submitted for searching.

This is required for example to allow Japanese or Chinese text to be searched. As these languages do not use spaces, it needs to be split into separate words before it can be indexed. There are various external libraries for this.

Parameters

$text: The text to split. This is a single piece of plain-text that was extracted from between two HTML tags. Will not contain any HTML entities.

Return value

The text after processing.

Related topics

File

developer/hooks/core.php, line 1295
These are the hooks that are invoked by the Drupal core.

Code

function hook_search_preprocess($text) {

  // Do processing on $text
  return $text;
}