Same name and namespace in other branches
  1. 10 core/modules/search/search.module \search
  2. 4.6.x modules/search.module \search
  3. 5.x modules/search/search.module \search
  4. 6.x modules/search/search.module \search
  5. 7.x modules/search/search.module \search
  6. 8.9.x core/modules/search/search.module \search
  7. 9 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 search.module, so this must be enabled for all of the search features to work.

There are three ways to interact with the search system:

  • Specifically for searching nodes, you can implement nodeapi('update index') and nodeapi('search result'). However, note that the search system already indexes all visible output of a node, i.e. everything displayed normally by hook_view() and hook_nodeapi('view'). This is usually sufficient. You should only use this mechanism if you want additional, non-visible data to be indexed.
  • Implement hook_search(). This will create a search tab for your module on the /search page with a simple keyword search form. You may optionally implement hook_search_item() to customize the display of your results.
  • Implement hook_update_index(). This allows your module to use Drupal's HTML indexing mechanism for searching full text efficiently.

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

File

modules/search.module, line 928
Enables site-wide keyword searching.

Functions

Namesort ascending Location Description
theme_search_theme_form modules/search.module Theme the theme search form.
theme_search_block_form modules/search.module Theme the block search form.
search_index modules/search.module Update the full-text search index for a particular item.
search_form_validate modules/search.module As the search form collates keys from other modules hooked in via hook_form_alter, the validation takes place in _submit. search_form_validate() is used solely to set the 'processed_keys' form value for the basic search form.
search_form_submit modules/search.module Process a search form submission.
search_form modules/search.module Render a search form.
search_excerpt modules/search.module Returns snippets from a piece of text, with certain keywords highlighted. Used for formatting search results.
search_data modules/search.module Perform a standard search on the given keys, and return the formatted results.
search_box_form_submit modules/search.module Process a block search form submission.
search_box modules/search.module Output a search form for the search block and the theme's search box.
hook_update_index developer/hooks/core.php Update Drupal's full-text index for this module.
hook_search developer/hooks/core.php Define a custom search routine.
do_search modules/search.module Do a query on the full-text search index for a word or words.