From 889120eeabf55e9f0dbd88ff4d4da290a1d69eee Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Thu, 4 Jan 2018 14:24:20 +0200
Subject: [PATCH] Make empty search relevance override more robust (#1091)

- It now works when there are additional fields in the selected sort or *:* is specified as the search term.
---
 module/VuFind/src/VuFind/Search/Solr/Params.php | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/module/VuFind/src/VuFind/Search/Solr/Params.php b/module/VuFind/src/VuFind/Search/Solr/Params.php
index d47edc883df..c369b0f6605 100644
--- a/module/VuFind/src/VuFind/Search/Solr/Params.php
+++ b/module/VuFind/src/VuFind/Search/Solr/Params.php
@@ -548,9 +548,12 @@ class Params extends \VuFind\Search\Base\Params
         // Sort
         $sort = $this->getSort();
         if ($sort) {
-            // If we have an empty search with relevance sort, see if there is
-            // an override configured:
-            if ($sort == 'relevance' && $this->getQuery()->getAllTerms() == ''
+            // If we have an empty search with relevance sort as the primary sort
+            // field, see if there is an override configured:
+            $sortFields = explode(',', $sort);
+            $allTerms = trim($this->getQuery()->getAllTerms());
+            if ('relevance' === $sortFields[0]
+                && ('' === $allTerms || '*:*' === $allTerms)
                 && ($relOv = $this->getOptions()->getEmptySearchRelevanceOverride())
             ) {
                 $sort = $relOv;
-- 
GitLab