Created
November 2, 2012 13:23
-
-
Save rafinskipg/4001350 to your computer and use it in GitHub Desktop.
Drupal 7 Default query search alter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mymodule_query_alter(QueryAlterableInterface $query){ | |
$is_search = FALSE; | |
foreach ($query->getTables() as $table) { | |
if ($table['table'] == 'search_index') { | |
$is_search = TRUE; | |
} | |
} | |
if ($is_search) { | |
global $language; | |
$db_or = db_or(); | |
$db_or->condition('n.type', 'event', '='); | |
$db_or->condition('n.type', 'real_sitio', '='); | |
$query->condition($db_or); | |
$query->condition('n.language' , $language->language, '='); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a bit performance killer so there's a patch for drupal at http://drupal.org/node/1435834 that adds a hook for making the alter directly in the search query:
So finally it would look like:
function mymodule_search_query_search_node_alter(&$query) {
$query->condition('n.type', 'article', '=');
}