Index: apachesolr_biblio.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr_biblio/apachesolr_biblio.module,v
retrieving revision 1.2
diff -u -F '^function' -r1.2 apachesolr_biblio.module
--- apachesolr_biblio.module	7 Nov 2009 04:02:13 -0000	1.2
+++ apachesolr_biblio.module	7 Nov 2009 04:29:03 -0000
@@ -66,7 +66,26 @@ function apachesolr_biblio_apachesolr_up
       $value = NULL;
       if ($value = apachesolr_biblio_format_value($node->{$biblio['name']}, $biblio['index_type'])) {
         if (is_array($value)) {
+          // The $biblio_sort variable exists just to build the $sort_index_key.
+          // The $sort_index_key exists so that results can later be sorted
+          // by the first value of this field. Citations often have many
+          // values for fields and we therefore use the first value as the
+          // sort value, building a special field just for this purpose.
+          // TODO: Add a checkbox on the field configuration screen that
+          // indicates whether a field should have a sort, or not.
+          // TODO: Add sorts to the $query object.
+          $biblio_sort = FALSE;
+          if ($biblio['multiple']) {
+            $biblio_sort = $biblio;
+            $biblio_sort['multiple'] = FALSE;
+            $sort_index_key = apachesolr_index_key($biblio_sort);
+          }
+          $first = TRUE;
           foreach($value as $v) {
+            if ($first) {
+              $document->$sort_index_key = $v;
+              $first = FALSE;
+            }
             $document->setMultiValue($index_key, $v);
           }
         }
@@ -79,10 +98,19 @@ function apachesolr_biblio_apachesolr_up
   // Handle authors.
   if (variable_get('apachesolr_biblio_index_authors', 1)) {
     $value = array();
-    foreach ($node->biblio_contributors as $keys) {
-      foreach ($keys as $key) {
-        if (isset($key['name'])) {
-          $document->setMultiValue('sm_biblio_contributors', apachesolr_clean_text($key['name']));
+
+    foreach ($node->biblio_contributors as $arrays) {
+      $first = TRUE;
+      foreach ($arrays as $contributor_node) {
+        if (isset($contributor_node['name'])) {
+          if ($author = trim(apachesolr_clean_text($contributor_node['name']))) {
+            if ($first) {
+              // Set the first name to ss_biblio_first_author
+              $first = FALSE;
+              $document->ss_biblio_first_author = $author;
+            }
+            $document->setMultiValue('sm_biblio_contributors', $author);
+          }
         }
       }
     }
