Code example. See //<<<<<< >>>>>>
Probably it needs to turn off messages about redirection.
/**
* Main search function.
* Started with: http://drupal.org/node/12668
* Updated to be more similar to search_view
* Beware of messy code
*/
function search404_page() {
drupal_set_title(t(variable_get('search404_page_title', '')));
if (module_exists('search') && (user_access('search content') || user_access('search by page'))) {
$keys = "";
// if apachesolr_search or luceneapi is installed use them instead default node search
$type_search = (module_exists('apachesolr_search')) ? 'apachesolr_search' : ((module_exists('luceneapi_node')) ? 'luceneapi_node' : 'node');
if (variable_get('search404_use_search_engine', FALSE)) {
$keys = search404_search_engine_query();
}
if (!$keys) {
$keys = search404_get_keys();
}
if ($keys) {
// TODO: watchdog?
if (module_exists('search_by_page') && variable_get('search404_do_search_by_page', FALSE)) {
drupal_set_message(t('The page you requested does not exist. For your convenience, a search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
if (variable_get('search404_redirect_301', false)) {
drupal_goto('search_pages/' . $keys, NULL, NULL, 301);
}
else {
drupal_goto('search_pages/' . $keys);
}
// EVIL HAXX!
$oldgetq = $_GET['q'];
$olddestination = $_REQUEST['destination'];
unset($_REQUEST['destination']);
$_GET['q'] = "search/$type_search/$keys";
$results = theme('search_results', $results, 'node');
$_GET['q'] = $oldgetq;
$_REQUEST['destination'] = $olddestination;
// END OF EVIL HAXX!
}
elseif (module_exists('google') && user_access('search Google CSE') && variable_get('search404_do_google_cse', FALSE)) {
drupal_set_message(t('The page you requested does not exist. For your convenience, a google search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
$_REQUEST['destination'] = 'search/google/' . $keys;
if (variable_get('search404_redirect_301', false)) {
drupal_goto("", NULL, NULL, 301);
}
else {
drupal_goto();
}
}
else {
$results = module_invoke($type_search, 'search', 'search', $keys);
if (isset($results) && is_array($results) && count($results) == 1 && variable_get('search404_jump', FALSE)) {
// First, check to see if there is exactly 1 result
drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');
// overwrite $_REQUEST['destination'] because it is set by drupal_not_found()
$_REQUEST['destination'] = 'node/' . $results[0]['node']->nid;
if (variable_get('search404_redirect_301', false)) {
drupal_goto("", NULL, NULL, 301);
}
else {
drupal_goto();
}
}
elseif (isset($results) && is_array($results) && count($results) > 1 && variable_get('search404_first', FALSE)) {
drupal_set_message(t('The page you requested does not exist. A search for %keys resulted in this page.', array('%keys' => check_plain($keys))), 'status');
// overwrite $_REQUEST['destination'] because it is set by drupal_not_found()
$_REQUEST['destination'] = 'node/' . $results[0]['node']->nid;
if (variable_get('search404_redirect_301', false)) {
drupal_goto("", NULL, NULL, 301);
}
else {
drupal_goto();
}
}
else {
drupal_set_message(t('The page you requested does not exist. For your convenience, a search was performed using the query %keys.', array('%keys' => check_plain($keys))), 'error');
if (isset($results) && is_array($results) && count($results) > 0) {
drupal_add_css(drupal_get_path('module', 'search') . '/search.css', 'module', 'all', FALSE);
// EVIL HAXX!
$oldgetq = $_GET['q'];
$olddestination = $_REQUEST['destination'];
unset($_REQUEST['destination']);
$_GET['q'] = "search/$type_search/$keys";
$results = theme('search_results', $results, 'node');
$_GET['q'] = $oldgetq;
$_REQUEST['destination'] = $olddestination;
// END OF EVIL HAXX!
}
else {
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//Redirect to Did You Mean words search results
if (module_exists('luceneapi_dym') && $suggestions = luceneapi_dym_suggestions_get($keys)) {
$_REQUEST['destination'] = preg_replace('/^.*href="\/search\/luceneapi_node\/([^"]*)".*$/i', '$1', $suggestions);
// or '/^.*href="\/([^"]*)".*$/i' . Search404 or Search using.
drupal_goto(); // Maybe add 301 or 302 redirect. I don't think 301 is necessary here
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$results = search_help('search#noresults', drupal_help_arg());
}
$results = theme('box', t('Search results'), $results);
}
}
}
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//Add Did You Mean to results
if (module_exists('luceneapi_dym') && $suggestions = luceneapi_dym_suggestions_get($keys)) {
$results = theme('box', t('Did you mean'), $suggestions) . $results;
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Construct the search form.
$output = variable_get('search404_page_text', '') . drupal_get_form('search_form', NULL, $keys, $type_search) . $results;
}
/*
* Start EVIL HAXX 2
* This was done to display sidebars left and right of page, if the option is set from Search404
* Settings Page.
*/
if (variable_get('search404_block_show', FALSE)) {
print theme('page', $output);
drupal_page_footer();
unset($output);
exit(0);
}
else {
return $output;
}
// End of EVIL HAXX 2
}
Comments
Comment #1
zyxware commentedThis has been added to the latest dev version