7.x node.module node_search_execute($keys = NULL, $conditions = NULL)

Implements hook_search_execute().

3 calls to node_search_execute()
SearchRankingTestCase::testDoubleRankings in modules/search/search.test
Verifies that if we combine two rankings, search still works.
SearchRankingTestCase::testHTMLRankings in modules/search/search.test
Test rankings of HTML tags.
SearchRankingTestCase::testRankings in modules/search/search.test


modules/node/node.module, line 1699
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.


function node_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');
  ->condition('n.status', 1)
    ->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
  $results = array();
  foreach ($find as $item) {
    // Render the node.
    $node = node_load($item->sid);
    $build = node_view($node, 'search_result');
    $node->rendered = drupal_render($build);

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

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

    $uri = entity_uri('node', $node);
    $results[] = array(
      'link' => url($uri['path'], array_merge($uri['options'], 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->rendered),
      'language' => entity_language('node', $node),
  return $results;


rmshgu’s picture

i need conditions arguments.. or examples

kris-o3’s picture

i agree... $conditions is shown as an argument to this function, as well as to hook_search_execute, but not referenced anywhere in the body of the function?

juanjo_dv’s picture

It seems like a placeholder for those who made is own search function, some kind of copy & paste & "add contidions".

It's a shame that you can't alter search before its done.

kingandy’s picture

Yeah, it seems that $conditions is an optional part of the search system available for custom search modules. The node search system doesn't use it.

In your hook_search_info() you can define a 'conditions_callback' which will be called before the search is executed - this can be used to gather extra filters or custom data, eg from the query string, which will then be passed into the hook_search_execute as the $conditions field.

Why this can't just be done in hook_search_execute, and why it's not defined as a fixed hook_search_conditions(), I have no clear idea. Possibly it's intended that hook_search_execute should be able to run without access to the query string? Or I guess there could be performance reasons.