? SolrPhpClient
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.111.2.87
diff -u -p -r1.1.2.6.2.111.2.87 apachesolr_search.module
--- apachesolr_search.module	3 Sep 2010 18:22:48 -0000	1.1.2.6.2.111.2.87
+++ apachesolr_search.module	3 Sep 2010 18:30:12 -0000
@@ -528,23 +528,32 @@ function apachesolr_search_add_boost_par
 function apachesolr_search_process_response($response, $query, $params) {
   $results = array();
   // We default to getting snippets from the body.
-  $hl_fl = isset($params['hl.fl']) ? $params['hl.fl'] : 'body';
+  $hl_fl = isset($params['hl.fl']) ? explode(',', $params['hl.fl']) : array('body');
   $total = $response->response->numFound;
   apachesolr_pager_init($total, $params['rows']);
   if ($total > 0) {
     foreach ($response->response->docs as $doc) {
       $extra = array();
 
+      // Start with an empty snippets array.
+      $snippets = array();
+
       // Find the nicest available snippet.
-      if (isset($response->highlighting->{$doc->id}->$hl_fl)) {
-        $snippet = theme('apachesolr_search_snippets', $doc, $response->highlighting->{$doc->id}->$hl_fl);
-      }
-      elseif (isset($doc->teaser)) {
-        $snippet = theme('apachesolr_search_snippets', $doc, array(truncate_utf8($doc->teaser, 256, TRUE)));
+      foreach ($hl_fl as $hl_param) {
+        if (isset($response->highlighting->{$doc->id}->$hl_param)) {
+          // Merge arrays preserving keys.
+          foreach ($response->highlighting->{$doc->id}->$hl_param as $values) {
+            $snippets[$hl_param] = $values;
+          }
+        }
       }
-      else {
-        $snippet = '';
+      // If there's no snippet at this point, add the teaser.
+      if (strlen($snippet) == 0) {
+        if (isset($doc->teaser)) {
+          $snippets[] = truncate_utf8($doc->teaser, 256, TRUE);
+        }
       }
+      $snippet = theme('apachesolr_search_snippets', $doc, $snippets);
 
       if (!isset($doc->body)) {
         $doc->body = $snippet;
@@ -1332,7 +1341,7 @@ function apachesolr_search_theme() {
       'arguments' => array('total_found' => NULL, 'links' => NULL),
     ),
     'apachesolr_search_snippets' => array(
-      'arguments' => array('doc' => NULL, 'snippets' => NULL),
+      'arguments' => array('doc' => NULL, 'snippets' => array()),
     ),
     'apachesolr_search_noresults' => array(
       'arguments' => array(),
@@ -1455,10 +1464,22 @@ function theme_apachesolr_currentsearch(
  * @param array $snippets
  *
  */
-function theme_apachesolr_search_snippets($doc, $snippets) {
-  return implode(' ... ', $snippets) .' ...';
+function theme_apachesolr_search_snippets($doc, $snippets = array()) {
+  $result = '';
+  if (isset($snippets['body'])) {
+    $result .= $snippets['body'];
+    unset($snippets['body']);
+  }
+  if (isset($snippets['teaser'])) {
+    $result .= (strlen($result) > 0) ? ' ... ' : '';
+    $result .= $snippets['teaser'];
+    unset($snippets['teaser']);
+  }
+  $result .= (strlen($result) > 0) ? ' ... ' : '';
+  return $result . implode(' ... ', $snippets) . ' ...';
 }
 
+
 /**
  * Brief message to display when no results match the query.
  *
