2 * Implements hook_search_execute().
4 function {{ machine_name }}_search_execute($keys = NULL, $conditions = NULL) {
5 // Build matching conditions
6 $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
7 $query->join('node', 'n', 'n.nid = i.sid');
9 ->condition('n.status', 1)
10 ->addTag('node_access')
11 ->searchExpression($keys, 'node');
13 // Insert special keywords.
14 $query->setOption('type', 'n.type');
15 $query->setOption('language', 'n.language');
16 if ($query->setOption('term', 'ti.tid')) {
17 $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
19 // Only continue if the first pass query matches.
20 if (!$query->executeFirstPass()) {
24 // Add the ranking expressions.
25 _node_rankings($query);
32 foreach ($find as $item) {
33 // Build the node body.
34 $node = node_load($item->sid);
35 node_build_content($node, 'search_result');
36 $node->body = drupal_render($node->content);
38 // Fetch comments for snippet.
39 $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);
40 // Fetch terms for snippet.
41 $node->rendered .= ' ' . module_invoke('taxonomy', 'node_update_index', $node);
43 $extra = module_invoke_all('node_search_result', $node);
46 'link' => url('node/' . $item->sid, array('absolute' => TRUE)),
47 'type' => check_plain(node_type_get_name($node)),
48 'title' => $node->title,
49 'user' => theme('username', array('account' => $node)),
50 'date' => $node->changed,
53 'score' => $item->calculated_score,
54 'snippet' => search_excerpt($keys, $node->body),