Snippet to exclude content-types from Drupal core search


/**
 * Implements hook_query_TAG_alter().
 *
 * Exclude some content-type from the search index
 */
function csz_query_node_access_alter(QueryAlterableInterface $query) {
  global $user;
  $search = FALSE;
  $node = FALSE;

  foreach ($query->getTables() as $alias => $table) {
    if ($table['table'] == 'search_index') {
      $search = $alias;
    }
    elseif ($table['table'] == 'node') {
      $node = $alias;
    }
  }

  if ($node && $search) {
    $excluded_content_types = array(
      'application_school',
      'application_studies',
      'dir_listing',
      'activity',
      'internship_locations',
      'accomodation',
    );

    if (!empty($excluded_content_types)) {
      $query->condition($node . '.type', array($excluded_content_types), 'NOT IN');
    }

    //dpq($query);
  }
}