21 July 2011

By placing this code to your themes template.php file, you get search results grouped by node/content type.

Source code viewer
  1. function HOOK_preprocess_search_results(&$variables) {
  2. $variables['search_results'] = '';
  3. $resultTypes = array();
  4.  
  5. // Divide results
  6. foreach ($variables['results'] as $result) {
  7. $resultTypes[$result['type']][] = $result;
  8. }
  9.  
  10. // Create fieldsets
  11. foreach ($resultTypes as $resultType => $resultTypeResults) {
  12. $value = '';
  13.  
  14. foreach ($resultTypeResults as $result) {
  15. $value .= theme('search_result', array('result' => $result, 'module' => $variables['module']));
  16. }
  17.  
  18. $variables['search_results'] .= theme('fieldset', array('element' => array('#title' => $resultType, '#value' => $value)));
  19. }
  20. }
Programming Language: PHP