function featured_content_do_search in Featured Content 7.2
Same name and namespace in other branches
- 7 featured_content.module \featured_content_do_search()
Based on the hook_search_execute function.
2 calls to featured_content_do_search()
- featured_content_get_filtered_nids in ./
featured_content.module - Get filtered node nids. Filter base on content types, users (authors) and taxonomy terms.
- featured_content_get_search_nids in ./
featured_content.module - Get search result node nids. Uses the title of the current node page to get the search results.
File
- ./
featured_content.module, line 2207 - Featured Content module for created related & featured content blocks.
Code
function featured_content_do_search($keys = NULL, $show_num = 20, $include_node = FALSE, $restrict_type = FALSE) {
$limit = $show_num * 2;
// Make sure there are enough results to use.
// Make sure it's not too big.
if ($limit > 100) {
$limit = 100;
}
// 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');
$this_node = _featured_content_load_node();
if (!empty($this_node)) {
if ($include_node === FALSE) {
$query
->condition('n.nid', $this_node->nid, '!=');
}
if ($restrict_type === TRUE) {
$query
->condition('n.type', $this_node->type, '=');
}
}
// 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.
_node_rankings($query);
// Load results.
$find = $query
->limit($limit)
->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);
if (isset($node->rendered)) {
// 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;
}