function hook_search_preprocess

Same name in other branches
  1. 9 core/modules/search/search.api.php \hook_search_preprocess()
  2. 8.9.x core/modules/search/search.api.php \hook_search_preprocess()
  3. 10 core/modules/search/search.api.php \hook_search_preprocess()
  4. 11.x core/modules/search/search.api.php \hook_search_preprocess()

Preprocess text for search.

This hook is called to preprocess both the text added to the search index and the keywords users have submitted for searching.

Possible uses:

  • Adding spaces between words of Chinese or Japanese text.
  • Stemming words down to their root words to allow matches between, for instance, walk, walked, walking, and walks in searching.
  • Expanding abbreviations and acronymns that occur in text.

Parameters

$text: The text to preprocess. This is a single piece of plain text extracted from between two HTML tags or from the search query. It will not contain any HTML entities or HTML tags.

Return value

The text after preprocessing. Note that if your module decides not to alter the text, it should return the original text. Also, after preprocessing, words in the text should be separated by a space.

Related topics

1 invocation of hook_search_preprocess()
search_invoke_preprocess in modules/search/search.module
Invokes hook_search_preprocess() in modules.

File

modules/search/search.api.php, line 287

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.