Search interface
Same name in other branches
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/my_module) so that users can easily find it.
See also
File
-
core/
modules/ search/ search.module, line 84
Functions
Title Sort descending | File name | Summary |
---|---|---|
hook_search_preprocess | core/ |
Preprocess text for search. |
search_excerpt | core/ |
Returns snippets from a piece of text, with search keywords highlighted. |
Classes
Title Sort descending | File name | Summary |
---|---|---|
Search | core/ |
Defines a Search type attribute for plugin discovery. |
SearchPlugin | core/ |
Defines a SearchPlugin type annotation object. |
Interfaces
Title Sort descending | File name | Summary |
---|---|---|
SearchIndexInterface | core/ |
Provides search index management functions. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.