function hook_search_execute


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 search.api.php hook_search_execute($keys = NULL, $conditions = NULL)
cle7 search.api.php hook_search_execute($keys = NULL, $conditions = NULL)
elmsmedia7 search.api.php hook_search_execute($keys = NULL, $conditions = NULL)
icor7 search.api.php hook_search_execute($keys = NULL, $conditions = NULL)
meedjum_blog7 search.api.php hook_search_execute($keys = NULL, $conditions = NULL)
mooc7 search.api.php hook_search_execute($keys = NULL, $conditions = NULL)

Execute a search for a set of key words.

Use database API with the 'PagerDefault' query extension to perform your search.

If your module uses hook_update_index() and search_index() to index its items, use table 'search_index' aliased to 'i' as the main table in your query, with the 'SearchQuery' extension. You can join to your module's table using the 'i.sid' field, which will contain the $sid values you provided to search_index(). Add the main keywords to the query by using method searchExpression(). The functions search_expression_extract() and search_expression_insert() may also be helpful for adding custom search parameters to the search expression.

See node_search_execute() for an example of a module that uses the search index, and user_search_execute() for an example that doesn't use the search index.


$keys: The search keywords as entered by the user.

$conditions: An optional array of additional conditions, such as filters.

Return value

An array of search results. To use the default search result display, each item should have the following keys':

  • 'link': Required. The URL of the found item.
  • 'type': The type of item (such as the content type).
  • 'title': Required. The name of the item.
  • 'user': The author of the item.
  • 'date': A timestamp when the item was last modified.
  • 'extra': An array of optional extra information items.
  • 'snippet': An excerpt or preview to show with the result (can be generated with search_excerpt()).
  • 'language': Language code for the item (usually two characters).

Related topics

7 functions implement hook_search_execute()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

advanced_help_search_execute in sites/all/modules/ulmus/advanced_help/advanced_help.module
Implements hook_search_execute().
ds_search_search_execute in sites/all/modules/ulmus/ds/modules/ds_search/ds_search.module
Implements hook_search_execute().
file_entity_search_execute in sites/all/modules/ulmus/file_entity/file_entity.module
Implements hook_search_execute().
node_ds_search_execute in sites/all/modules/ulmus/ds/modules/ds_search/ds_search.module
Search on behalf of Drupal Core.
node_search_execute in modules/node/node.module
Implements hook_search_execute().

... See full list

1 invocation of hook_search_execute()
search_data in modules/search/search.module
Performs a search by calling hook_search_execute().


modules/search/search.api.php, line 167
Hooks provided by the Search module.


function hook_search_execute($keys = NULL, $conditions = NULL) {
  // Build matching conditions
  $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
  $query->join('node', 'n', 'n.nid = i.sid');
  $query->condition('n.status', 1)->addTag('node_access')->searchExpression($keys, 'node');

  // Insert special keywords.
  $query->setOption('type', 'n.type');
  $query->setOption('language', 'n.language');
  if ($query->setOption('term', 'ti.tid')) {
    $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
  // Only continue if the first pass query matches.
  if (!$query->executeFirstPass()) {
    return array();

  // Add the ranking expressions.

  // Load results.
  $find = $query->limit(10)->execute();
  $results = array();
  foreach ($find as $item) {
    // Build the node body.
    $node = node_load($item->sid);
    node_build_content($node, 'search_result');
    $node->body = drupal_render($node->content);

    // Fetch comments for snippet.
    $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);
    // Fetch terms for snippet.
    $node->rendered .= ' ' . module_invoke('taxonomy', 'node_update_index', $node);

    $extra = module_invoke_all('node_search_result', $node);

    $results[] = array(
      'link' => url('node/' . $item->sid, array('absolute' => TRUE)),
      'type' => check_plain(node_type_get_name($node)),
      'title' => $node->title,
      'user' => theme('username', array('account' => $node)),
      'date' => $node->changed,
      'node' => $node,
      'extra' => $extra,
      'score' => $item->calculated_score,
      'snippet' => search_excerpt($keys, $node->body),
  return $results;



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.