From c6ff0b797edf96b50abf171de665be48bb9932f9 Mon Sep 17 00:00:00 2001 From: codebymikey <50924-codebymikey@users.noreply.drupalcode.org> Date: Tue, 21 Nov 2023 10:13:31 +0100 Subject: [PATCH] Issue #3402831 by codebymikey, mkalkbrenner: [sorting] Always set the multivalue's first value as long as it's not NULL --- src/Plugin/search_api/backend/SearchApiSolrBackend.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugin/search_api/backend/SearchApiSolrBackend.php b/src/Plugin/search_api/backend/SearchApiSolrBackend.php index dd273872..6e1910ad 100644 --- a/src/Plugin/search_api/backend/SearchApiSolrBackend.php +++ b/src/Plugin/search_api/backend/SearchApiSolrBackend.php @@ -1381,7 +1381,7 @@ public function getDocuments(IndexInterface $index, array $items, UpdateQuery $u } // Enable sorts in some special cases. - if ($first_value && !array_key_exists($name, $special_fields)) { + if (($first_value !== NULL) && !array_key_exists($name, $special_fields)) { if ( strpos($field_names[$name], 't') === 0 || strpos($field_names[$name], 's') === 0 @@ -2636,7 +2636,7 @@ protected function hasHierarchicalProperties(EntityDataDefinitionInterface $prop * @param array $boost_terms * Reference to an array where special boosts per term should be stored. * - * @return bool|float|int|string + * @return bool|float|int|string|null * The first value of $values that has been added to the index. */ protected function addIndexField(Document $doc, $key, array $values, $type, array &$boost_terms) { @@ -2647,11 +2647,11 @@ protected function addIndexField(Document $doc, $key, array $values, $type, arra if (empty($values)) { if ('text' !== $type || !$this->configuration['index_empty_text_fields']) { // Don't index empty values (i.e., when field is missing). - return ''; + return NULL; } } - $first_value = ''; + $first_value = NULL; // All fields. foreach ($values as $value) {