Implements hook_search_execute().
function node_search_execute($keys = NULL, $conditions = NULL) {
// Build matching conditions
$query = db_select('search_index', 'i', array(
'target' => 'slave',
))
->extend('Drupal\\search\\SearchQuery')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$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('langcode', 'n.langcode');
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.
_node_rankings($query);
// Load results.
$find = $query
->fields('i', array(
'langcode',
))
->limit(10)
->execute();
$results = array();
foreach ($find as $item) {
// Render the node.
$node = node_load($item->sid);
$build = node_view($node, 'search_result', $item->langcode);
unset($build['#theme']);
$node->rendered = drupal_render($build);
// Fetch comments for snippet.
$node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node, $item->langcode);
$extra = module_invoke_all('node_search_result', $node, $item->langcode);
$language = language_load($item->langcode);
$uri = $node
->uri();
$results[] = array(
'link' => url($uri['path'], array_merge($uri['options'], array(
'absolute' => TRUE,
'language' => $language,
))),
'type' => check_plain(node_get_type_label($node)),
'title' => $node
->label($item->langcode),
'user' => theme('username', array(
'account' => $node,
)),
'date' => $node
->get('changed', $item->langcode),
'node' => $node,
'extra' => $extra,
'score' => $item->calculated_score,
'snippet' => search_excerpt($keys, $node->rendered, $item->langcode),
'langcode' => $node->langcode,
);
}
return $results;
}