Chris@0: /** Chris@0: * Implements hook_search_execute(). Chris@0: */ Chris@0: function {{ machine_name }}_search_execute($keys = NULL, $conditions = NULL) { Chris@0: // Build matching conditions Chris@0: $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault'); Chris@0: $query->join('node', 'n', 'n.nid = i.sid'); Chris@0: $query Chris@0: ->condition('n.status', 1) Chris@0: ->addTag('node_access') Chris@0: ->searchExpression($keys, 'node'); Chris@0: Chris@0: // Insert special keywords. Chris@0: $query->setOption('type', 'n.type'); Chris@0: $query->setOption('language', 'n.language'); Chris@0: if ($query->setOption('term', 'ti.tid')) { Chris@0: $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid'); Chris@0: } Chris@0: // Only continue if the first pass query matches. Chris@0: if (!$query->executeFirstPass()) { Chris@0: return array(); Chris@0: } Chris@0: Chris@0: // Add the ranking expressions. Chris@0: _node_rankings($query); Chris@0: Chris@0: // Load results. Chris@0: $find = $query Chris@0: ->limit(10) Chris@0: ->execute(); Chris@0: $results = array(); Chris@0: foreach ($find as $item) { Chris@0: // Build the node body. Chris@0: $node = node_load($item->sid); Chris@0: node_build_content($node, 'search_result'); Chris@0: $node->body = drupal_render($node->content); Chris@0: Chris@0: // Fetch comments for snippet. Chris@0: $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node); Chris@0: // Fetch terms for snippet. Chris@0: $node->rendered .= ' ' . module_invoke('taxonomy', 'node_update_index', $node); Chris@0: Chris@0: $extra = module_invoke_all('node_search_result', $node); Chris@0: Chris@0: $results[] = array( Chris@0: 'link' => url('node/' . $item->sid, array('absolute' => TRUE)), Chris@0: 'type' => check_plain(node_type_get_name($node)), Chris@0: 'title' => $node->title, Chris@0: 'user' => theme('username', array('account' => $node)), Chris@0: 'date' => $node->changed, Chris@0: 'node' => $node, Chris@0: 'extra' => $extra, Chris@0: 'score' => $item->calculated_score, Chris@0: 'snippet' => search_excerpt($keys, $node->body), Chris@0: ); Chris@0: } Chris@0: return $results; Chris@0: }