From ddbf059d7469622af6361e1a007feb2bf1c2dac8 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 14 Jun 2018 12:15:57 -0400
Subject: [PATCH] Fix bug: DefaultSortingByType and search memory
 incompatibility. - Previously, default sorting by type resulted in sort
 settings that were "too sticky." Now, whenever the user's choice matches the
 default choice for sorting, the memory is cleared to allow switching between
 types to act as expected.

---
 module/VuFind/src/VuFind/Search/Memory.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/module/VuFind/src/VuFind/Search/Memory.php b/module/VuFind/src/VuFind/Search/Memory.php
index c2b444ff464..bf7d3ee3614 100644
--- a/module/VuFind/src/VuFind/Search/Memory.php
+++ b/module/VuFind/src/VuFind/Search/Memory.php
@@ -113,10 +113,16 @@ class Memory
      */
     public function rememberParams(\VuFind\Search\Base\Params $params)
     {
+        // Since default sort may vary based on search handler, we don't want
+        // to force the sort value to stick unless the user chose a non-default
+        // option. Otherwise, if you switch between search types, unpredictable
+        // sort options may result.
+        $sort = $params->getSort();
+        $defaultSort = $params->getDefaultSort();
         $settings = [
             'hiddenFilters' => $params->getHiddenFilters(),
             'limit' => $params->getLimit(),
-            'sort' => $params->getSort(),
+            'sort' => $sort === $defaultSort ? null : $sort,
             'view' => $params->getView(),
         ];
         // Special case: RSS view should not be persisted:
-- 
GitLab