function search_by_page_search_execute in Search by Page 7
Same name and namespace in other branches
- 8 search_by_page.module \search_by_page_search_execute()
Implements hook_search_execute().
File
- ./
search_by_page.module, line 657 - Main module file for Drupal module Search by Page.
Code
function search_by_page_search_execute($keys = NULL, $conditions = NULL) {
global $pager_page_array, $pager_total, $pager_total_items;
global $language;
$lang = $language->language;
// Extract environment and clear from keys.
$environment = search_expression_extract($keys, 'environment');
$keys = search_expression_insert($keys, 'environment');
if (!$environment) {
$environment = variable_get('search_by_page_default_environment', 1);
}
// Set up query for Search module.
$query = db_select('search_index', 'i', array(
'target' => 'slave',
))
->extend('SearchQuery')
->extend('PagerDefault');
$query
->searchExpression($keys, 'search_by_page')
->join('sbp_path', 'sp', 'i.sid = sp.pid');
$query
->condition('sp.environment', $environment)
->condition('sp.language', $lang);
// Set number of results per page.
$num = intval(search_by_page_setting_get('results_per_page', $environment, 10));
if ($num > 0) {
$query
->limit($num);
}
// Get sub-modules' search modifications.
$or = db_or();
$or
->where('0=1');
foreach (module_implements('sbp_query_modify') as $module) {
$cond = module_invoke($module, 'sbp_query_modify', $environment, $query);
$cond
->condition('sp.from_module', $module);
$or
->condition($cond);
}
$query
->condition($or);
// Perform the search.
if (!$query
->executeFirstPass()) {
return array();
}
$stuff = $query
->execute();
// Create array of formatted results for Search
$results = array();
foreach ($stuff as $item) {
$info = _search_by_page_lookup($item->sid);
// Figure out the URL to this page.
$parts = search_by_page_path_parts($info->page_path);
$args = array(
'absolute' => TRUE,
);
if (isset($parts[1])) {
$args['query'] = array();
parse_str($parts[1], $args['query']);
}
// Special case: if this is a file, we need to use the File API to get
// the URL. Otherwise, use the normal Drupal URL function.
if (file_uri_scheme($parts[0])) {
// This is a file with scheme://filename.
$link = file_create_url($parts[0]);
}
else {
$link = url($parts[0], $args);
}
$res = array(
'link' => $link,
);
// Merge URL with information provided by module from hook_sbp_details()
$res2 = module_invoke($info->from_module, 'sbp_details', $info->modid, $environment, $keys);
if (is_array($res2)) {
$res = array_merge($res, $res2);
}
// Make sure we have a title
if (!$res['title']) {
$res['title'] = $link;
}
$results[] = $res;
}
return $results;
}