Skip navigation
Help

Search interface

  1. drupal
    1. 6 drupal/modules/search/search.module
    2. 7 drupal/modules/search/search.module

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 hook_nodeapi('update index') and hook_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.
  • 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.

Functions & methods

NameDescription
do_searchDo a query on the full-text search index for a word or words.
hook_searchDefine a custom search routine.
hook_update_indexUpdate Drupal's full-text index for this module.
search_boxForm builder; Output a search form for the search block and the theme's search box.
search_box_form_submitProcess a block search form submission.
search_dataPerform a standard search on the given keys, and return the formatted results.
search_excerptReturns snippets from a piece of text, with certain keywords highlighted. Used for formatting search results.
search_formRender a search form.
search_indexUpdate the full-text search index for a particular item.
template_preprocess_search_block_formProcess variables for search-block-form.tpl.php.
template_preprocess_search_theme_formProcess variables for search-theme-form.tpl.php.

File

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