search.api.php

  1. 7.x drupal/modules/search/search.api.php
  2. 8.x drupal/core/modules/search/search.api.php

Hooks provided by the Search module.

Functions

Namesort descending Description
hook_search_plugin_alter Alter search plugin definitions.
hook_search_preprocess Preprocess text for search.

File

drupal/core/modules/search/search.api.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Search module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Preprocess text for search.
  12. *
  13. * This hook is called to preprocess both the text added to the search index
  14. * and the keywords users have submitted for searching.
  15. *
  16. * Possible uses:
  17. * - Adding spaces between words of Chinese or Japanese text.
  18. * - Stemming words down to their root words to allow matches between, for
  19. * instance, walk, walked, walking, and walks in searching.
  20. * - Expanding abbreviations and acronymns that occur in text.
  21. *
  22. * @param $text
  23. * The text to preprocess. This is a single piece of plain text extracted
  24. * from between two HTML tags or from the search query. It will not contain
  25. * any HTML entities or HTML tags.
  26. * @param $langcode
  27. * The language code of the entity that has been found.
  28. *
  29. * @return
  30. * The text after preprocessing. Note that if your module decides not to
  31. * alter the text, it should return the original text. Also, after
  32. * preprocessing, words in the text should be separated by a space.
  33. *
  34. * @ingroup search
  35. */
  36. function hook_search_preprocess($text, $langcode = NULL) {
  37. // If the langcode is set to 'en' then add variations of the word "testing"
  38. // which can also be found during English language searches.
  39. if (isset($langcode) && $langcode == 'en') {
  40. // Add the alternate verb forms for the word "testing".
  41. if ($text == 'we are testing') {
  42. $text .= ' test tested';
  43. }
  44. }
  45. return $text;
  46. }
  47. /**
  48. * Alter search plugin definitions.
  49. *
  50. * @param array $definitions
  51. * The array of search plugin definitions, keyed by plugin ID.
  52. *
  53. * @see \Drupal\search\Annotation\SearchPlugin
  54. * @see \Drupal\search\SearchPluginManager
  55. */
  56. function hook_search_plugin_alter(array &$definitions) {
  57. if (isset($definitions['node_search'])) {
  58. $definitions['node_search']['title'] = t('Nodes');
  59. }
  60. }