function node_ds_search_execute in Display Suite 7
Same name and namespace in other branches
- 7.2 modules/ds_search/ds_search.module \node_ds_search_execute()
Search on behalf of Drupal Core.
File
- modules/
ds_search/ ds_search.module, line 594 - Display Suite search.
Code
function node_ds_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');
$query
->condition('n.status', 1)
->addTag('node_access')
->searchExpression($keys, 'node');
// Language.
if (variable_get('ds_search_language', FALSE)) {
global $language;
$query
->condition('n.language', $language->language);
}
// 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(variable_get('ds_search_node_limit', 10))
->execute();
$results = array();
foreach ($find as $item) {
$node = node_load($item->sid);
$node->search_extra = module_invoke_all('node_search_result', $node);
// Only build a node search snippet if this field is actually being used.
$fields = ds_get_field_settings('node', $node->type, 'search_result');
if (!empty($fields) && isset($fields['search_snippet'])) {
// Because the 'search_result' display is being built right now (and because it is being overridden by Display Suite),
// it is necessary to use the 'search_index' display for rendered field content.
$build = node_view($node, 'search_index');
unset($build['#theme']);
// Render the node.
$rendered = drupal_render($build);
// Attach extra information to the rendered output.
$rendered .= ' ' . $node->search_extra;
// Generate the snippet based on rendered content.
$node->snippet = search_excerpt($keys, $rendered);
}
$results[$item->sid] = $node;
}
return $results;
}