Exclude some content-type from the search index (Using Core Search)

Public

Implement hook_query_TAG_alter

</> CopyGet raw version
php
  1. <?php
  2.  
  3. /**
  4.  * Implements hook_query_TAG_alter() .
  5.  *
  6.  * Exclude some content-types from the search index
  7.  */
  8. function csz_query_node_access_alter(QueryAlterableInterface $query) {
  9. global $user;
  10.  
  11. // if ($user->uid == 1) {
  12. // return;
  13. // }
  14.  
  15. $search = FALSE;
  16. $node = FALSE;
  17.  
  18. foreach ($query->getTables() as $alias => $table) {
  19. if ($table['table'] == 'search_index') {
  20. $search = $alias;
  21. }
  22. elseif ($table['table'] == 'node') {
  23. $node = $alias;
  24. }
  25. }
  26.  
  27. if ($node && $search) {
  28. $excluded_content_types = array(
  29. 'application_school',
  30. 'application_studies',
  31. 'dir_listing',
  32. 'activity',
  33. 'internship_locations',
  34. 'accomodation',
  35. );
  36.  
  37. if (!empty($excluded_content_types)) {
  38. $query->condition($node . '.type', array($excluded_content_types), 'NOT IN');
  39. }
  40.  
  41. //dpq($query);
  42. }
  43. }