Search interface

  1. 7.x drupal/modules/search/search.module search
  2. 5.x drupal/modules/search/search.module search
  3. 6.x drupal/modules/search/search.module search
  4. 8.x drupal/core/modules/search/search.module search

The Drupal search interface manages a global search mechanism.

Modules may plug into this system to provide searches of different types of data. Most of the system is handled by the Search module, so this must be enabled for all of the search features to work.

There are two ways to interact with the search system:

  • Specifically for searching nodes, you can implement hook_node_update_index() and hook_node_search_result(). However, note that the search system already indexes all visible output of a node; i.e., everything displayed normally during node viewing. This is usually sufficient. You should only use this mechanism if you want additional, non-visible data to be indexed.
  • Define a plugin implementing \Drupal\search\Plugin\SearchInterface and annotated as \Drupal\search\Annotation\SearchPlugin. This will create a search page type that users can use to set up one or more search pages. Each of these corresponds to a tab on the /search page, which can be used to perform searches. You will also need to implement the execute() method from the interface to perform the search. A base class is provided in \Drupal\search\Plugin\SearchPluginBase. For more information about plugins, see the Plugin API topic.

If your module needs to provide a more complicated search form, then you need to implement it yourself. In that case, you may wish to define it as a local task (tab) under the /search page (e.g. /search/mymodule) so that users can easily find it.

See also

Plugin API

Annotations

Functions

Namesort descending Location Description
hook_search_preprocess drupal/core/modules/search/search.api.php Preprocess text for search.
search_excerpt drupal/core/modules/search/search.module Returns snippets from a piece of text, with search keywords highlighted.
search_index drupal/core/modules/search/search.module Updates the full-text search index for a particular item.

Classes

Namesort descending Location Description
SearchPlugin drupal/core/modules/search/src/Annotation/SearchPlugin.php Defines a SearchPlugin type annotation object.

File

drupal/core/modules/search/search.module, line 545
Enables site-wide keyword searching.