From b4785a6df10b24750e1194acaa04f08cbbe7dfab Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 7 Sep 2012 10:36:02 -0400
Subject: [PATCH] Two inter-related changes:

1. fixed bug where Search Manager would load incorrect objects because state had been changed in between calls (i.e. $params object may use Search Manager, changing its state before $results object can be created -- to avoid, we need more explicit calls to setSearchClassId())

2. refactored record drivers in preparation for plugin manager (moved constructor parameter to setRawData method).  This allowed more common functionality to be moved to the abstract base class.  Renamed getAllFields() to getRawData() for consistency.

Small bonus change: turned off highlighting/spellchecking/recommendations in BrowseController for improved performance.
---
 .../VuFind/src/VuFind/Autocomplete/Solr.php   |  8 ++---
 .../src/VuFind/Controller/AbstractSearch.php  | 10 ++++--
 .../src/VuFind/Controller/AjaxController.php  | 24 +++++++-------
 .../VuFind/Controller/BrowseController.php    |  9 +++--
 .../Controller/MyResearchController.php       |  9 ++---
 .../VuFind/Controller/SearchController.php    | 20 +++++------
 .../VuFind/Controller/SummonController.php    |  9 ++---
 module/VuFind/src/VuFind/OAI/Server.php       |  9 ++---
 .../src/VuFind/Recommend/AuthorFacets.php     |  4 +--
 .../VuFind/Recommend/AuthorityRecommend.php   |  6 ++--
 .../src/VuFind/Recommend/SearchObject.php     |  3 +-
 .../src/VuFind/Recommend/SummonDatabases.php  |  6 ++--
 module/VuFind/src/VuFind/Record/Loader.php    |  4 +--
 .../src/VuFind/RecordDriver/AbstractBase.php  | 26 ++++++++++++---
 .../src/VuFind/RecordDriver/Missing.php       | 11 ++-----
 .../src/VuFind/RecordDriver/SolrDefault.php   | 24 +++-----------
 .../src/VuFind/RecordDriver/SolrMarc.php      | 17 ++++++----
 .../VuFind/src/VuFind/RecordDriver/Summon.php |  6 +---
 .../src/VuFind/RecordDriver/TestHarness.php   | 12 -------
 .../src/VuFind/RecordDriver/WorldCat.php      | 33 ++++++++++++-------
 module/VuFind/src/VuFind/Search/Minified.php  |  5 ++-
 .../VuFind/src/VuFind/Search/Solr/Results.php |  4 ++-
 .../src/VuFind/Search/SolrAuth/Results.php    |  7 ++--
 .../VuFind/Search/SolrReserves/Results.php    |  7 ++--
 .../src/VuFind/Search/Summon/Results.php      |  5 +--
 .../src/VuFind/Search/WorldCat/Results.php    |  5 +--
 .../tests/Theme/Root/Helper/CitationTest.php  |  3 +-
 .../Theme/Root/Helper/ResultFeedTest.php      |  6 ++--
 .../SolrDefault/tab-details.phtml             |  2 +-
 .../SolrDefault/tab-details.phtml             |  2 +-
 30 files changed, 152 insertions(+), 144 deletions(-)

diff --git a/module/VuFind/src/VuFind/Autocomplete/Solr.php b/module/VuFind/src/VuFind/Autocomplete/Solr.php
index 1efe1406eb8..98190426b8f 100644
--- a/module/VuFind/src/VuFind/Autocomplete/Solr.php
+++ b/module/VuFind/src/VuFind/Autocomplete/Solr.php
@@ -96,13 +96,13 @@ class Solr implements AutocompleteInterface, ServiceLocatorAwareInterface
     {
         // Get the search manager:
         $sm = $this->getServiceLocator()->getServiceLocator()->get('SearchManager');
-        $sm->setSearchClassId($this->searchClassId);
 
         // Build a new search object:
-        $params = $sm->getParams();
+        $params = $sm->setSearchClassId($this->searchClassId)->getParams();
         $params->getOptions()->spellcheckEnabled(false);
         $params->recommendationsEnabled(false);
-        $this->searchObject = $sm->getResults($params);
+        $this->searchObject = $sm->setSearchClassId($this->searchClassId)
+            ->getResults($params);
     }
 
     /**
@@ -181,7 +181,7 @@ class Solr implements AutocompleteInterface, ServiceLocatorAwareInterface
     {
         $results = array();
         foreach ($searchResults as $object) {
-            $current = $object->getAllFields();
+            $current = $object->getRawData();
             foreach ($this->displayField as $field) {
                 if (isset($current[$field])) {
                     $bestMatch = $this->pickBestMatch(
diff --git a/module/VuFind/src/VuFind/Controller/AbstractSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSearch.php
index 8b4eeac0046..d3b82aff2a0 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractSearch.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractSearch.php
@@ -149,8 +149,8 @@ class AbstractSearch extends AbstractBase
             return $this->redirectToSavedSearch($savedId);
         }
 
-        $manager = $this->getSearchManager()->setSearchClassId($this->searchClassId);
-        $params = $manager->getParams();
+        $manager = $this->getSearchManager();
+        $params = $manager->setSearchClassId($this->searchClassId)->getParams();
         $params->recommendationsEnabled(true);
 
         // Send both GET and POST variables to search class:
@@ -164,7 +164,11 @@ class AbstractSearch extends AbstractBase
         // Attempt to perform the search; if there is a problem, inspect any Solr
         // exceptions to see if we should communicate to the user about them.
         try {
-            $results = $manager->getResults($params);
+            // We need to reset the searchClassId here because it may have been
+            // changed if recommendation modules initialized by the params object
+            // manipulated the shared search manager object.
+            $results = $manager->setSearchClassId($this->searchClassId)
+                ->getResults($params);
 
             // Explicitly execute search within controller -- this allows us to
             // catch exceptions more reliably:
diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php
index 343889fac9d..4ddbcb322b9 100644
--- a/module/VuFind/src/VuFind/Controller/AjaxController.php
+++ b/module/VuFind/src/VuFind/Controller/AjaxController.php
@@ -107,13 +107,13 @@ class AjaxController extends AbstractBase
         // Process recommendations -- for now, we assume Solr-based search objects,
         // since deferred recommendations work best for modules that don't care about
         // the details of the search objects anyway:
-        $sm = $this->getSearchManager()->setSearchClassId('Solr');
+        $sm = $this->getSearchManager();
         $rm = $this->getServiceLocator()->get('RecommendPluginManager');
         $module = clone($rm->get($this->params()->fromQuery('mod')));
         $module->setConfig($this->params()->fromQuery('params'));
-        $params = $sm->getParams();
+        $params = $sm->setSearchClassId('Solr')->getParams();
         $module->init($params, $this->getRequest()->getQuery());
-        $results = $sm->getResults($params);
+        $results = $sm->setSearchClassId('Solr')->getResults($params);
         $module->process($results);
 
         // Set headers:
@@ -669,10 +669,10 @@ class AjaxController extends AbstractBase
      */
     public function getMapData($fields = array('long_lat'))
     {
-        $sm = $this->getSearchManager()->setSearchClassId('Solr');
-        $params = $sm->getParams();
+        $sm = $this->getSearchManager();
+        $params = $sm->setSearchClassId('Solr')->getParams();
         $params->initFromRequest($this->getRequest()->getQuery());
-        $results = $sm->getResults($params);
+        $results = $sm->setSearchClassId('Solr')->getResults($params);
 
         $facets = $results->getFullFieldFacets($fields, false);
 
@@ -709,10 +709,10 @@ class AjaxController extends AbstractBase
         // Set layout to render the page inside a lightbox:
         $this->layout()->setTemplate('layout/lightbox');
 
-        $sm = $this->getSearchManager()->setSearchClassId('Solr');
-        $params = $sm->getParams();
+        $sm = $this->getSearchManager();
+        $params = $sm->setSearchClassId('Solr')->getParams();
         $params->initFromRequest($this->getRequest()->getQuery());
-        $results = $sm->getResults($params);
+        $results = $sm->setSearchClassId('Solr')->getResults($params);
 
         return $this->createViewModel(
             array(
@@ -736,10 +736,10 @@ class AjaxController extends AbstractBase
      */
     public function getVisData($fields = array('publishDate'))
     {
-        $sm = $this->getSearchManager()->setSearchClassId('Solr');
-        $params = $sm->getParams();
+        $sm = $this->getSearchManager();
+        $params = $sm->setSearchClassId('Solr')->getParams();
         $params->initFromRequest($this->getRequest()->getQuery());
-        $results = $sm->getResults($params);
+        $results = $sm->setSearchClassId('Solr')->getResults($params);
         $filters = $params->getFilters();
         $dateFacets = $this->params()->fromQuery('facetFields');
         $dateFacets = empty($dateFacets) ? array() : explode(':', $dateFacets);
diff --git a/module/VuFind/src/VuFind/Controller/BrowseController.php b/module/VuFind/src/VuFind/Controller/BrowseController.php
index 3aa3b2c4162..b1f68442dae 100644
--- a/module/VuFind/src/VuFind/Controller/BrowseController.php
+++ b/module/VuFind/src/VuFind/Controller/BrowseController.php
@@ -559,8 +559,8 @@ class BrowseController extends AbstractBase
     protected function getFacetList($facet, $category = null,
         $sort = 'count', $query = '[* TO *]'
     ) {
-        $sm = $this->getSearchManager()->setSearchClassId('Solr');
-        $params = $sm->getParams();
+        $sm = $this->getSearchManager();
+        $params = $sm->setSearchClassId('Solr')->getParams();
         $params->addFacet($facet);
         if ($category != null) {
             $query = $category . ':' . $query;
@@ -568,7 +568,10 @@ class BrowseController extends AbstractBase
             $query = $facet . ':' . $query;
         }
         $params->setOverrideQuery($query);
-        $searchObject = $sm->getResults($params);
+        $params->getOptions()->disableHighlighting();
+        $params->getOptions()->spellcheckEnabled(false);
+        $params->recommendationsEnabled(false);
+        $searchObject = $sm->setSearchClassId('Solr')->getResults($params);
         // Get limit from config
         $params->setFacetLimit($this->config->Browse->result_limit);
         $params->setLimit(0);
diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php
index 29f38853020..2f40ed866bb 100644
--- a/module/VuFind/src/VuFind/Controller/MyResearchController.php
+++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php
@@ -530,8 +530,8 @@ class MyResearchController extends AbstractBase
 
         // If we got this far, we just need to display the favorites:
         try {
-            $sm = $this->getSearchManager()->setSearchClassId('Favorites');
-            $params = $sm->getParams();
+            $sm = $this->getSearchManager();
+            $params = $sm->setSearchClassId('Favorites')->getParams();
             $params->setAuthManager($this->getAuthManager());
 
             // We want to merge together GET, POST and route parameters to
@@ -544,7 +544,7 @@ class MyResearchController extends AbstractBase
                 )
             );
 
-            $results = $sm->getResults($params);
+            $results = $sm->setSearchClassId('Favorites')->getResults($params);
             $results->performAndProcessSearch();
             return $this->createViewModel(array('results' => $results));
         } catch (ListPermissionException $e) {
@@ -732,7 +732,8 @@ class MyResearchController extends AbstractBase
             }
             $record = SolrResults::getRecord($current['id']);
         } catch (RecordMissingException $e) {
-            $record = new \VuFind\RecordDriver\Missing(
+            $record = new \VuFind\RecordDriver\Missing();
+            $record->setRawData(
                 array('id' => isset($current['id']) ? $current['id'] : null)
             );
         }
diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php
index 2dea03953a3..163ab32c620 100644
--- a/module/VuFind/src/VuFind/Controller/SearchController.php
+++ b/module/VuFind/src/VuFind/Controller/SearchController.php
@@ -343,8 +343,8 @@ class SearchController extends AbstractSearch
             $resultPages = 10;
         }
         $catalog = ConnectionManager::connectToCatalog();
-        $sm = $this->getSearchManager()->setSearchClassId('Solr');
-        $params = $sm->getParams();
+        $sm = $this->getSearchManager();
+        $params = $sm->setSearchClassId('Solr')->getParams();
         $perPage = $params->getLimit();
         $newItems = $catalog->getNewItems(1, $perPage * $resultPages, $range, $dept);
 
@@ -431,10 +431,10 @@ class SearchController extends AbstractSearch
      */
     public function reservessearchAction()
     {
-        $sm = $this->getSearchManager()->setSearchClassId('SolrReserves');
-        $params = $sm->getParams();
+        $sm = $this->getSearchManager();
+        $params = $sm->setSearchClassId('SolrReserves')->getParams();
         $params->initFromRequest($this->getRequest()->getQuery());
-        $results = $sm->getResults($params);
+        $results = $sm->setSearchClassId('SolrReserves')->getResults($params);
         return $this->createViewModel(array('results' => $results));
     }
 
@@ -458,8 +458,8 @@ class SearchController extends AbstractSearch
         $bibIDs = array_unique(array_map($callback, $result));
 
         // Truncate the list if it is too long:
-        $sm = $this->getSearchManager()->setSearchClassId('Solr');
-        $params = $sm->getParams();
+        $sm = $this->getSearchManager();
+        $params = $sm->setSearchClassId('Solr')->getParams();
         $limit = $params->getQueryIDLimit();
         if (count($bibIDs) > $limit) {
             $bibIDs = array_slice($bibIDs, 0, $limit);
@@ -505,15 +505,15 @@ class SearchController extends AbstractSearch
             // we may want to make this more flexible later.  Also keep in mind that
             // the template is currently looking for certain hard-coded fields; this
             // should also be made smarter.
-            $sm = $this->getSearchManager()->setSearchClassId('Solr');
-            $params = $sm->getParams();
+            $sm = $this->getSearchManager();
+            $params = $sm->setSearchClassId('Solr')->getParams();
             $params->initAdvancedFacets();
 
             // We only care about facet lists, so don't get any results (this helps
             // prevent problems with serialized File_MARC objects in the cache):
             $params->setLimit(0);
 
-            $results = $sm->getResults($params);
+            $results = $sm->setSearchClassId('Solr')->getResults($params);
             $results->getResults();                     // force processing for cache
 
             // Temporarily remove the service manager so we can cache the
diff --git a/module/VuFind/src/VuFind/Controller/SummonController.php b/module/VuFind/src/VuFind/Controller/SummonController.php
index 4a3de1e7c91..d52165428d9 100644
--- a/module/VuFind/src/VuFind/Controller/SummonController.php
+++ b/module/VuFind/src/VuFind/Controller/SummonController.php
@@ -127,16 +127,17 @@ class SummonController extends AbstractSearch
         // Check if we have facet results cached, and build them if we don't.
         $cache = CacheManager::getInstance()->getCache('object');
         if (!($results = $cache->getItem('summonSearchHomeFacets'))) {
-            $sm = $this->getSearchManager()->setSearchClassId('Summon');
-            $params = $sm->getParams();
+            $sm = $this->getSearchManager();
+            $params = $sm->setSearchClassId('Summon')->getParams();
             $params->addFacet('Language,or,1,20');
             $params->addFacet('ContentType,or,1,20', 'Format');
 
             // We only care about facet lists, so don't get any results:
             $params->setLimit(0);
 
-            $results = $sm->getResults($params);
-            $results->getResults();                     // force processing for cache
+            $results = $sm->setSearchClassId('Summon')->getResults($params);
+            // force processing for cache
+            $results->getResults();
 
             // Temporarily remove the service manager so we can cache the
             // results (otherwise we'll get errors about serializing closures):
diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php
index 200ecc4d3ce..1845be2367b 100644
--- a/module/VuFind/src/VuFind/OAI/Server.php
+++ b/module/VuFind/src/VuFind/OAI/Server.php
@@ -183,7 +183,7 @@ class Server
         }
 
         // Check for sets:
-        $fields = $record->getAllFields();
+        $fields = $record->getRawData();
         if (!is_null($this->setField) && !empty($fields[$this->setField])) {
             $sets = $fields[$this->setField];
         } else {
@@ -507,9 +507,10 @@ class Server
         // we'll assume that this list is short enough to load in a single response;
         // it may be necessary to implement a resumption token mechanism if this
         // proves not to be the case:
-        $this->searchManager->setSearchClassId($this->searchClassId);
-        $params = $this->searchManager->getParams();
-        $results = $this->searchManager->getResults($params);
+        $params = $this->searchManager->setSearchClassId($this->searchClassId)
+            ->getParams();
+        $results = $this->searchManager->setSearchClassId($this->searchClassId)
+            ->getResults($params);
         try {
             $facets = $results->getFullFieldFacets(array($this->setField));
         } catch (\Exception $e) {
diff --git a/module/VuFind/src/VuFind/Recommend/AuthorFacets.php b/module/VuFind/src/VuFind/Recommend/AuthorFacets.php
index a06a3bd588e..9183257677a 100644
--- a/module/VuFind/src/VuFind/Recommend/AuthorFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/AuthorFacets.php
@@ -141,11 +141,11 @@ class AuthorFacets extends AbstractSearchManagerAwareModule
 
         // Initialize an AuthorFacets search object using parameters from the
         // current Solr search object.
-        $params = $sm->getParams($options);
+        $params = $sm->setSearchClassId('SolrAuthorFacets')->getParams($options);
         $params->initFromRequest(new Parameters(array('lookfor' => $lookfor)));
 
         // Send back the results:
-        $results = $sm->getResults($params);
+        $results = $sm->setSearchClassId('SolrAuthorFacets')->getResults($params);
         return array(
             // Total authors (currently there is no way to calculate this without
             // risking out-of-memory errors or slow results, so we set this to
diff --git a/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php b/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php
index cbfe4aa57c9..3ad1c0f910e 100644
--- a/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php
+++ b/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php
@@ -135,13 +135,13 @@ class AuthorityRecommend extends AbstractSearchManagerAwareModule
         // Initialise and process search (ignore Solr errors -- no reason to fail
         // just because search syntax is not compatible with Authority core):
         try {
-            $sm = $this->getSearchManager()->setSearchClassId('SolrAuth');
-            $authParams = $sm->getParams();
+            $sm = $this->getSearchManager();
+            $authParams = $sm->setSearchClassId('SolrAuth')->getParams();
             $authParams->initFromRequest($request);
             foreach ($this->filters as $filter) {
                 $authParams->getOptions()->addHiddenFilter($filter);
             }
-            $authResults = $sm->getResults($authParams);
+            $authResults = $sm->setSearchClassId('SolrAuth')->getResults($authParams);
             $results = $authResults->getResults();
         } catch (SolrException $e) {
             return;
diff --git a/module/VuFind/src/VuFind/Recommend/SearchObject.php b/module/VuFind/src/VuFind/Recommend/SearchObject.php
index 7233f1d878a..470f3ccf0eb 100644
--- a/module/VuFind/src/VuFind/Recommend/SearchObject.php
+++ b/module/VuFind/src/VuFind/Recommend/SearchObject.php
@@ -85,7 +85,8 @@ abstract class SearchObject extends AbstractSearchManagerAwareModule
         $params->setBasicSearch($request->get($this->requestParam));
 
         // Perform the search:
-        $this->results = $sm->getResults($params);
+        $this->results = $sm->setSearchClassId($this->getSearchClassId())
+            ->getResults($params);
         $this->results->performAndProcessSearch();
     }
 
diff --git a/module/VuFind/src/VuFind/Recommend/SummonDatabases.php b/module/VuFind/src/VuFind/Recommend/SummonDatabases.php
index 2fb03d579eb..954279f29a9 100644
--- a/module/VuFind/src/VuFind/Recommend/SummonDatabases.php
+++ b/module/VuFind/src/VuFind/Recommend/SummonDatabases.php
@@ -97,10 +97,10 @@ class SummonDatabases extends AbstractSearchManagerAwareModule
         // to create a new Summon search object using the specified request 
         // parameter for search terms.
         if ($results->getParams()->getSearchClassId() != 'Summon') {
-            $sm = $this->getSearchManager()->setSearchClassId('Summon');
-            $params = $sm->getParams();
+            $sm = $this->getSearchManager();
+            $params = $sm->setSearchClassId('Summon')->getParams();
             $params->setBasicSearch($this->lookfor);
-            $results = $sm->getResults($params);
+            $results = $sm->setSearchClassId('Summon')->getResults($params);
             $results->performAndProcessSearch();
         }
         $this->databases = $results->getDatabaseRecommendations();
diff --git a/module/VuFind/src/VuFind/Record/Loader.php b/module/VuFind/src/VuFind/Record/Loader.php
index 63b7b33ece6..1c44cb02dca 100644
--- a/module/VuFind/src/VuFind/Record/Loader.php
+++ b/module/VuFind/src/VuFind/Record/Loader.php
@@ -133,8 +133,8 @@ class Loader
                 $fields = isset($details['extra_fields'])
                     ? $details['extra_fields'] : array();
                 $fields['id'] = $details['id'];
-                $retVal[$i]
-                    = new \VuFind\RecordDriver\Missing($fields);
+                $retVal[$i] = new \VuFind\RecordDriver\Missing();
+                $retVal[$i]->setRawData($fields);
             }
         }
 
diff --git a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php
index dbbdec8092a..87e2b9bc34b 100644
--- a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php
+++ b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php
@@ -52,18 +52,34 @@ abstract class AbstractBase
     protected $resourceSource = 'VuFind';   // Used for identifying database records
     protected $extraDetails = array();      // For storing extra data with record
     protected $recordIni = null;            // ini file for record settings
+    protected $fields = array();
 
     /**
-     * Constructor.
+     * Set raw data to initialize the object.
      *
-     * @param array|object $data Raw data representing the record; Record Model
+     * @param mixed $data Raw data representing the record; Record Model
      * objects are normally constructed by Record Driver objects using data
      * passed in from a Search Results object.  The exact nature of the data may
      * vary depending on the data source -- the important thing is that the
-     * Record Model + Record Driver + Search Results objects work together
-     * correctly.
+     * Record Driver + Search Results objects work together correctly.
+     *
+     * @return void
      */
-    abstract public function __construct($data);
+    public function setRawData($data)
+    {
+        $this->fields = $data;
+    }
+
+    /**
+     * Retrieve raw data from object (primarily for use in staff view and
+     * autocomplete; avoid using whenever possible).
+     *
+     * @return mixed
+     */
+    public function getRawData()
+    {
+        return $this->fields;
+    }
 
     /**
      * Get text that can be displayed to represent this record in breadcrumbs.
diff --git a/module/VuFind/src/VuFind/RecordDriver/Missing.php b/module/VuFind/src/VuFind/RecordDriver/Missing.php
index c6d774566c6..405e59241cc 100644
--- a/module/VuFind/src/VuFind/RecordDriver/Missing.php
+++ b/module/VuFind/src/VuFind/RecordDriver/Missing.php
@@ -42,17 +42,10 @@ class Missing extends SolrDefault
 {
     /**
      * Constructor.
-     *
-     * @param array $data Raw data from the Solr index representing the record;
-     * Solr Record Model objects are normally constructed by Solr Record Driver
-     * objects using data passed in from a Solr Search Results object.
      */
-    public function __construct($data = null)
+    public function __construct()
     {
-        if (!is_array($data)) {
-            $data = array();
-        }
-        parent::__construct($data);
         $this->resourceSource = 'missing';
+        parent::__construct();
     }
 }
diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php
index 0bd30b9ce46..9e5b89b0549 100644
--- a/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php
+++ b/module/VuFind/src/VuFind/RecordDriver/SolrDefault.php
@@ -43,8 +43,6 @@ use VuFind\Code\ISBN, VuFind\Config\Reader as ConfigReader;
  */
 class SolrDefault extends AbstractBase
 {
-    protected $fields;
-
     /**
      * These Solr fields should be used for snippets if available (listed in order
      * of preference).
@@ -93,15 +91,9 @@ class SolrDefault extends AbstractBase
 
     /**
      * Constructor.
-     *
-     * @param array $data Raw data from the Solr index representing the record;
-     * Solr Record Model objects are normally constructed by Solr Record Driver
-     * objects using data passed in from a Solr Search Results object.
      */
-    public function __construct($data)
+    public function __construct()
     {
-        $this->fields = $data;
-
         // Turn on highlighting/snippets as needed:
         $searchSettings = ConfigReader::getConfig('searches');
         $this->highlight = !isset($searchSettings->General->highlighting)
@@ -184,17 +176,6 @@ class SolrDefault extends AbstractBase
         return null;
     }
 
-    /**
-     * Get an associative array of all fields (primarily for use in staff view and
-     * autocomplete; avoid using whenever possible).
-     *
-     * @return array
-     */
-    public function getAllFields()
-    {
-        return $this->fields;
-    }
-
     /**
      * Get award notes for the record.
      *
@@ -1050,6 +1031,9 @@ class SolrDefault extends AbstractBase
      */
     public function getUniqueID()
     {
+        if (!isset($this->fields['id'])) {
+            throw new \Exception('ID not set!');
+        }
         return $this->fields['id'];
     }
 
diff --git a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
index c3151ebb0aa..ff4d19025fd 100644
--- a/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
+++ b/module/VuFind/src/VuFind/RecordDriver/SolrMarc.php
@@ -48,16 +48,19 @@ class SolrMarc extends SolrDefault
     protected $marcRecord;
 
     /**
-     * Constructor.
+     * Set raw data to initialize the object.
      *
-     * @param array $data Raw data from the Solr index representing the record;
-     * Solr Record Model objects are normally constructed by Solr Record Driver
-     * objects using data passed in from a Solr Search Results object.
+     * @param mixed $data Raw data representing the record; Record Model
+     * objects are normally constructed by Record Driver objects using data
+     * passed in from a Search Results object.  In this case, $data is a Solr record
+     * array containing MARC data in the 'fullrecord' field.
+     *
+     * @return void
      */
-    public function __construct($data)
+    public function setRawData($data)
     {
-        // Call the parent's constructor...
-        parent::__construct($data);
+        // Call the parent's set method...
+        parent::setRawData($data);
 
         // Also process the MARC record:
         $marc = trim($data['fullrecord']);
diff --git a/module/VuFind/src/VuFind/RecordDriver/Summon.php b/module/VuFind/src/VuFind/RecordDriver/Summon.php
index 1ba1ffd6ac0..71ab60c36c9 100644
--- a/module/VuFind/src/VuFind/RecordDriver/Summon.php
+++ b/module/VuFind/src/VuFind/RecordDriver/Summon.php
@@ -43,13 +43,9 @@ class Summon extends SolrDefault
 {
     /**
      * Constructor.
-     *
-     * @param array $data Raw data from the Summon index representing the record.
      */
-    public function __construct($data)
+    public function __construct()
     {
-        $this->fields = $data;
-
         // Turn on highlighting as needed:
         $searchSettings = ConfigReader::getConfig('Summon');
         $this->highlight = !isset($searchSettings->General->highlighting)
diff --git a/module/VuFind/src/VuFind/RecordDriver/TestHarness.php b/module/VuFind/src/VuFind/RecordDriver/TestHarness.php
index a03209644fe..8e0ceed187b 100644
--- a/module/VuFind/src/VuFind/RecordDriver/TestHarness.php
+++ b/module/VuFind/src/VuFind/RecordDriver/TestHarness.php
@@ -38,18 +38,6 @@ namespace VuFind\RecordDriver;
  */
 class TestHarness extends AbstractBase
 {
-    protected $fields;
-
-    /**
-     * Constructor.
-     *
-     * @param array $data Raw test data.
-     */
-    public function __construct($data = array())
-    {
-        $this->fields = $data;
-    }
-
     /**
      * Magic method to set/retrieve fields.
      *
diff --git a/module/VuFind/src/VuFind/RecordDriver/WorldCat.php b/module/VuFind/src/VuFind/RecordDriver/WorldCat.php
index 1b33cd5a52f..08a28521b39 100644
--- a/module/VuFind/src/VuFind/RecordDriver/WorldCat.php
+++ b/module/VuFind/src/VuFind/RecordDriver/WorldCat.php
@@ -42,11 +42,29 @@ class WorldCat extends SolrMarc
     protected $marcRecord;
 
     /**
-     * Constructor.
+     * Constructor
+     */
+    public function __construct()
+    {
+        // Set the correct resource source for database entries:
+        $this->resourceSource = 'WorldCat';
+
+        // Use the WorldCat.ini file instead of config.ini for loading record
+        // settings (i.e. "related" record handlers):
+        $this->recordIni = 'WorldCat';
+    }
+
+    /**
+     * Set raw data to initialize the object.
+     *
+     * @param mixed $data Raw data representing the record; Record Model
+     * objects are normally constructed by Record Driver objects using data
+     * passed in from a Search Results object.  In this case, $data is a MARCXML
+     * document.
      *
-     * @param array $data Raw data from WorldCat representing the record.
+     * @return void
      */
-    public function __construct($data)
+    public function setRawData($data)
     {
         // Make sure the XML has an appropriate header:
         if (strlen($data) > 2 && substr($data, 0, 2) != '<?') {
@@ -55,14 +73,7 @@ class WorldCat extends SolrMarc
 
         // Map the WorldCat response into a format that the parent Solr-based
         // record driver can understand.
-        parent::__construct(array('fullrecord' => $data));
-
-        // Set the correct resource source for database entries:
-        $this->resourceSource = 'WorldCat';
-
-        // Use the WorldCat.ini file instead of config.ini for loading record
-        // settings (i.e. "related" record handlers):
-        $this->recordIni = 'WorldCat';
+        parent::setRawData(array('fullrecord' => $data));
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Search/Minified.php b/module/VuFind/src/VuFind/Search/Minified.php
index a7743cc230e..fc9491c4ab8 100644
--- a/module/VuFind/src/VuFind/Search/Minified.php
+++ b/module/VuFind/src/VuFind/Search/Minified.php
@@ -132,10 +132,9 @@ class Minified
         $this->populateClassNames();
 
         // Deminify everything:
-        $manager->setSearchClassId($this->cl);
-        $params = $manager->getParams();
+        $params = $manager->setSearchClassId($this->cl)->getParams();
         $params->deminify($this);
-        $results = $manager->getResults($params);
+        $results = $manager->setSearchClassId($this->cl)->getResults($params);
         $results->deminify($this);
 
         return $results;
diff --git a/module/VuFind/src/VuFind/Search/Solr/Results.php b/module/VuFind/src/VuFind/Search/Solr/Results.php
index e12128633ee..189bb36f39a 100644
--- a/module/VuFind/src/VuFind/Search/Solr/Results.php
+++ b/module/VuFind/src/VuFind/Search/Solr/Results.php
@@ -550,7 +550,9 @@ class Results extends BaseResults
 
         // Build the object:
         if (class_exists($driver)) {
-            return new $driver($data);
+            $obj = new $driver();
+            $obj->setRawData($data);
+            return $obj;
         }
 
         throw new \Exception('Cannot find record driver -- ' . $driver);
diff --git a/module/VuFind/src/VuFind/Search/SolrAuth/Results.php b/module/VuFind/src/VuFind/Search/SolrAuth/Results.php
index fdeb771832d..239caa23a74 100644
--- a/module/VuFind/src/VuFind/Search/SolrAuth/Results.php
+++ b/module/VuFind/src/VuFind/Search/SolrAuth/Results.php
@@ -26,8 +26,7 @@
  * @link     http://www.vufind.org  Main Page
  */
 namespace VuFind\Search\SolrAuth;
-use VuFind\RecordDriver\SolrAuth as SolrAuthRecord,
-    VuFind\Search\Base\Params as BaseParams,
+use VuFind\Search\Base\Params as BaseParams,
     VuFind\Search\Solr\Results as SolrResults;
 
 /**
@@ -77,6 +76,8 @@ class Results extends SolrResults
      */
     protected static function initRecordDriver($data)
     {
-        return new SolrAuthRecord($data);
+        $driver = new \VuFind\RecordDriver\SolrAuth();
+        $driver->setRawData($data);
+        return $driver;
     }
 }
\ No newline at end of file
diff --git a/module/VuFind/src/VuFind/Search/SolrReserves/Results.php b/module/VuFind/src/VuFind/Search/SolrReserves/Results.php
index 01f2e17a51f..ba362f8961e 100644
--- a/module/VuFind/src/VuFind/Search/SolrReserves/Results.php
+++ b/module/VuFind/src/VuFind/Search/SolrReserves/Results.php
@@ -27,8 +27,7 @@
  * @link     http://www.vufind.org  Main Page
  */
 namespace VuFind\Search\SolrReserves;
-use VuFind\RecordDriver\SolrReserves as SolrReservesRecord,
-    VuFind\Search\Base\Params as BaseParams,
+use VuFind\Search\Base\Params as BaseParams,
     VuFind\Search\Solr\Results as SolrResults;
 
 /**
@@ -80,6 +79,8 @@ class Results extends SolrResults
      */
     protected static function initRecordDriver($data)
     {
-        return new SolrReservesRecord($data);
+        $driver = new \VuFind\RecordDriver\SolrReserves();
+        $driver->setRawData($data);
+        return $driver;
     }
 }
\ No newline at end of file
diff --git a/module/VuFind/src/VuFind/Search/Summon/Results.php b/module/VuFind/src/VuFind/Search/Summon/Results.php
index 89b374bc621..81eb07ed322 100644
--- a/module/VuFind/src/VuFind/Search/Summon/Results.php
+++ b/module/VuFind/src/VuFind/Search/Summon/Results.php
@@ -30,7 +30,6 @@ use VuFind\Config\Reader as ConfigReader,
     VuFind\Connection\Summon as SummonConnection,
     VuFind\Connection\Summon\Query as SummonQuery,
     VuFind\Exception\RecordMissing as RecordMissingException,
-    VuFind\RecordDriver\Summon as SummonRecord,
     VuFind\Search\Base\Results as BaseResults,
     VuFind\Translator\Translator;
 
@@ -159,7 +158,9 @@ class Results extends BaseResults
      */
     protected static function initRecordDriver($data)
     {
-        return new SummonRecord($data);
+        $driver = new \VuFind\RecordDriver\Summon();
+        $driver->setRawData($data);
+        return $driver;
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Search/WorldCat/Results.php b/module/VuFind/src/VuFind/Search/WorldCat/Results.php
index 930a663fbd9..eb5e232d605 100644
--- a/module/VuFind/src/VuFind/Search/WorldCat/Results.php
+++ b/module/VuFind/src/VuFind/Search/WorldCat/Results.php
@@ -29,7 +29,6 @@ namespace VuFind\Search\WorldCat;
 use VuFind\Config\Reader as ConfigReader,
     VuFind\Connection\WorldCat as WorldCatConnection,
     VuFind\Exception\RecordMissing as RecordMissingException,
-    VuFind\RecordDriver\WorldCat as WorldCatRecord,
     VuFind\Search\Base\Results as BaseResults;
 
 /**
@@ -128,7 +127,9 @@ class Results extends BaseResults
      */
     protected static function initRecordDriver($data)
     {
-        return new WorldCatRecord($data);
+        $driver = new \VuFind\RecordDriver\WorldCat();
+        $driver->setRawData($data);
+        return $driver;
     }
 
     /**
diff --git a/module/VuFind/tests/Theme/Root/Helper/CitationTest.php b/module/VuFind/tests/Theme/Root/Helper/CitationTest.php
index 9a4d6f653d3..61d49fe0774 100644
--- a/module/VuFind/tests/Theme/Root/Helper/CitationTest.php
+++ b/module/VuFind/tests/Theme/Root/Helper/CitationTest.php
@@ -285,8 +285,9 @@ class CitationTest extends \VuFind\Tests\ViewHelperTestCase
     {
         $citation = new Citation();
         $citation->setView($this->getPhpRenderer());
+        $driver = new \VuFind\RecordDriver\TestHarness();
         foreach ($this->citations as $current) {
-            $driver = new \VuFind\RecordDriver\TestHarness($current['raw']);
+            $driver->setRawData($current['raw']);
             $cb = $citation->__invoke($driver);
 
             // Normalize whitespace:
diff --git a/module/VuFind/tests/Theme/Root/Helper/ResultFeedTest.php b/module/VuFind/tests/Theme/Root/Helper/ResultFeedTest.php
index de7aa5a21c1..22c6f7a021e 100644
--- a/module/VuFind/tests/Theme/Root/Helper/ResultFeedTest.php
+++ b/module/VuFind/tests/Theme/Root/Helper/ResultFeedTest.php
@@ -70,11 +70,11 @@ class ResultFeedTest extends \VuFind\Tests\ViewHelperTestCase
         $request->set('sort', 'title');
         $request->set('view', 'rss');
 
-        $sm = $this->getSearchManager()->setSearchClassId('Solr');
-        $params = $sm->getParams();
+        $sm = $this->getSearchManager();
+        $params = $sm->setSearchClassId('Solr')->getParams();
         $params->initFromRequest($request);
 
-        $results = $sm->getResults($params);
+        $results = $sm->setSearchClassId('Solr')->getResults($params);
         $helper = new ResultFeed();
         $helper->setView($this->getPhpRenderer($this->getPlugins()));
         $mockTranslator = function ($str) {
diff --git a/themes/blueprint/templates/RecordDriver/SolrDefault/tab-details.phtml b/themes/blueprint/templates/RecordDriver/SolrDefault/tab-details.phtml
index 309c02c5979..b315fec63e0 100644
--- a/themes/blueprint/templates/RecordDriver/SolrDefault/tab-details.phtml
+++ b/themes/blueprint/templates/RecordDriver/SolrDefault/tab-details.phtml
@@ -3,7 +3,7 @@
     $this->headTitle($this->translate('Staff View') . ': ' . $this->driver->getBreadcrumb());
 ?>
 <table class="citation">
-  <? foreach ($this->driver->getAllFields() as $field => $values): ?>
+  <? foreach ($this->driver->getRawData() as $field => $values): ?>
     <tr>
       <th><?=$this->escapeHtml($field)?></th>
       <td>
diff --git a/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-details.phtml b/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-details.phtml
index 1f5eca6fea9..4420e0d0f2b 100644
--- a/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-details.phtml
+++ b/themes/jquerymobile/templates/RecordDriver/SolrDefault/tab-details.phtml
@@ -3,7 +3,7 @@
     $this->headTitle($this->translate('Staff View') . ': ' . $this->driver->getBreadcrumb());
 ?>
 <dl class="biblio" title="<?=$this->transEsc('Staff View')?>">
-  <? foreach ($this->driver->getAllFields() as $field => $values): ?>
+  <? foreach ($this->driver->getRawData() as $field => $values): ?>
     <dt><?=$this->escapeHtml($field)?></dt>
     <dd>
       <div style="width: 500px; overflow: auto;">
-- 
GitLab