From 3fb25613a6d372cd0c946f02963f6f043ce5ef06 Mon Sep 17 00:00:00 2001
From: solotandem <jim@boombatower.com>
Date: Tue, 17 Nov 2015 12:07:39 -0600
Subject: [PATCH 2/2] Issue #2617448 by solotandem: Set 'multiple' key in
 search field information based on field cardinality.

  Current default makes all fields multi-valued.
  This renders void the ability to sort on a single-valued field
    which seems an undesirable side effect to say the least.
---
 apachesolr.module | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/apachesolr.module b/apachesolr.module
index fcd7d84..0865412 100644
--- a/apachesolr.module
+++ b/apachesolr.module
@@ -2140,9 +2140,16 @@ function apachesolr_entity_fields($entity_type = 'node') {
 
         // Cardinality: The number of values the field can hold. Legal values
         // are any positive integer or FIELD_CARDINALITY_UNLIMITED.
-        if ($row['field']['cardinality'] != 1) {
-          $row['multiple'] = TRUE;
-        }
+
+        // By default in apachesolr_get_field_mappings(), the 'multiple' key is
+        // set to TRUE. The previous code does not change it to FALSE based on
+        // cardinality; it does nothing unless a contributed module had set it
+        // to FALSE even though cardinality != 1.
+
+        // A default of TRUE renders void the ability to sort on a single value
+        // field which seems an undesirable side effect to say the least.
+
+        $row['multiple'] = $row['field']['cardinality'] != 1;
 
         // @todo: for fields like taxonomy we are indexing multiple Solr fields
         // per entity field, but are keying on a single Solr field name here.
-- 
2.1.4

