From 434425456ca379fa272026f7daf6c57deb2a92f7 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 1 Apr 2020 10:05:24 -0400
Subject: [PATCH] Simplify/standardize search backend ID handling. (#1599)

---
 .../VuFind/src/VuFind/Search/Base/Results.php   | 17 +++++++++++++++++
 .../src/VuFind/Search/BrowZine/Results.php      | 16 ++++------------
 module/VuFind/src/VuFind/Search/EDS/Results.php |  9 ++++++++-
 module/VuFind/src/VuFind/Search/EIT/Results.php |  9 ++++++++-
 .../src/VuFind/Search/LibGuides/Results.php     |  9 ++++++++-
 .../src/VuFind/Search/Pazpar2/Results.php       |  9 ++++++++-
 .../VuFind/src/VuFind/Search/Primo/Results.php  |  9 ++++++++-
 .../VuFind/src/VuFind/Search/Solr/Results.php   |  2 +-
 .../src/VuFind/Search/SolrAuth/Results.php      | 14 +++-----------
 .../src/VuFind/Search/SolrReserves/Results.php  | 14 +++-----------
 .../src/VuFind/Search/SolrWeb/Results.php       | 14 +++-----------
 .../VuFind/src/VuFind/Search/Summon/Results.php | 11 +++++++++--
 .../src/VuFind/Search/WorldCat/Results.php      |  9 ++++++++-
 13 files changed, 88 insertions(+), 54 deletions(-)

diff --git a/module/VuFind/src/VuFind/Search/Base/Results.php b/module/VuFind/src/VuFind/Search/Base/Results.php
index 0145551906c..c86c063f93c 100644
--- a/module/VuFind/src/VuFind/Search/Base/Results.php
+++ b/module/VuFind/src/VuFind/Search/Base/Results.php
@@ -59,6 +59,13 @@ abstract class Results
      */
     protected $resultTotal = null;
 
+    /**
+     * Search backend identifier.
+     *
+     * @var string
+     */
+    protected $backendId;
+
     /**
      * Override (only for use in very rare cases)
      *
@@ -403,6 +410,16 @@ abstract class Results
         return $this->errors;
     }
 
+    /**
+     * Basic 'getter' of search backend identifier.
+     *
+     * @return string
+     */
+    public function getBackendId()
+    {
+        return $this->backendId;
+    }
+
     /**
      * Basic 'getter' for ID of saved search.
      *
diff --git a/module/VuFind/src/VuFind/Search/BrowZine/Results.php b/module/VuFind/src/VuFind/Search/BrowZine/Results.php
index 4a77ad77bf5..8b68a1ee035 100644
--- a/module/VuFind/src/VuFind/Search/BrowZine/Results.php
+++ b/module/VuFind/src/VuFind/Search/BrowZine/Results.php
@@ -42,19 +42,11 @@ use VuFindSearch\Service as SearchService;
 class Results extends \VuFind\Search\Base\Results
 {
     /**
-     * Constructor
+     * Search backend identifier.
      *
-     * @param \VuFind\Search\Base\Params $params        Object representing user
-     * search parameters.
-     * @param SearchService              $searchService Search service
-     * @param Loader                     $recordLoader  Record loader
+     * @var string
      */
-    public function __construct(\VuFind\Search\Base\Params $params,
-        SearchService $searchService, Loader $recordLoader
-    ) {
-        parent::__construct($params, $searchService, $recordLoader);
-        $this->backendId = 'BrowZine';
-    }
+    protected $backendId = 'BrowZine';
 
     /**
      * Returns the stored list of facets for the last search
@@ -83,7 +75,7 @@ class Results extends \VuFind\Search\Base\Results
         $limit  = $this->getParams()->getLimit();
         $offset = $this->getStartRecord() - 1;
         $collection = $this->getSearchService()->search(
-            'BrowZine', $query, $offset, $limit
+            $this->backendId, $query, $offset, $limit
         );
 
         $this->resultTotal = $collection->getTotal();
diff --git a/module/VuFind/src/VuFind/Search/EDS/Results.php b/module/VuFind/src/VuFind/Search/EDS/Results.php
index 5e1cc555b68..dde62f39b43 100644
--- a/module/VuFind/src/VuFind/Search/EDS/Results.php
+++ b/module/VuFind/src/VuFind/Search/EDS/Results.php
@@ -38,6 +38,13 @@ namespace VuFind\Search\EDS;
  */
 class Results extends \VuFind\Search\Base\Results
 {
+    /**
+     * Search backend identifier.
+     *
+     * @var string
+     */
+    protected $backendId = 'EDS';
+
     /**
      * Support method for performAndProcessSearch -- perform a search based on the
      * parameters passed to the object.
@@ -51,7 +58,7 @@ class Results extends \VuFind\Search\Base\Results
         $offset = $this->getStartRecord() - 1;
         $params = $this->getParams()->getBackendParameters();
         $collection = $this->getSearchService()->search(
-            'EDS', $query, $offset, $limit, $params
+            $this->backendId, $query, $offset, $limit, $params
         );
         if (null != $collection) {
             $this->responseFacets = $collection->getFacets();
diff --git a/module/VuFind/src/VuFind/Search/EIT/Results.php b/module/VuFind/src/VuFind/Search/EIT/Results.php
index de7ee5a08a5..9ccc136b9d5 100644
--- a/module/VuFind/src/VuFind/Search/EIT/Results.php
+++ b/module/VuFind/src/VuFind/Search/EIT/Results.php
@@ -42,6 +42,13 @@ namespace VuFind\Search\EIT;
  */
 class Results extends \VuFind\Search\Base\Results
 {
+    /**
+     * Search backend identifier.
+     *
+     * @var string
+     */
+    protected $backendId = 'EIT';
+
     /**
      * Support method for performAndProcessSearch -- perform a search based on the
      * parameters passed to the object.
@@ -55,7 +62,7 @@ class Results extends \VuFind\Search\Base\Results
         $offset = $this->getStartRecord() - 1;
         $params = $this->getParams()->getBackendParameters();
         $collection = $this->getSearchService()
-            ->search('EIT', $query, $offset, $limit, $params);
+            ->search($this->backendId, $query, $offset, $limit, $params);
 
         $this->resultTotal = $collection->getTotal();
         $this->results = $collection->getRecords();
diff --git a/module/VuFind/src/VuFind/Search/LibGuides/Results.php b/module/VuFind/src/VuFind/Search/LibGuides/Results.php
index 73f8346ab4f..013ac46ae52 100644
--- a/module/VuFind/src/VuFind/Search/LibGuides/Results.php
+++ b/module/VuFind/src/VuFind/Search/LibGuides/Results.php
@@ -38,6 +38,13 @@ namespace VuFind\Search\LibGuides;
  */
 class Results extends \VuFind\Search\Base\Results
 {
+    /**
+     * Search backend identifier.
+     *
+     * @var string
+     */
+    protected $backendId = 'LibGuides';
+
     /**
      * Support method for performAndProcessSearch -- perform a search based on the
      * parameters passed to the object.
@@ -50,7 +57,7 @@ class Results extends \VuFind\Search\Base\Results
         $limit  = $this->getParams()->getLimit();
         $offset = $this->getStartRecord() - 1;
         $collection = $this->getSearchService()->search(
-            'LibGuides', $query, $offset, $limit
+            $this->backendId, $query, $offset, $limit
         );
 
         $this->resultTotal = $collection->getTotal();
diff --git a/module/VuFind/src/VuFind/Search/Pazpar2/Results.php b/module/VuFind/src/VuFind/Search/Pazpar2/Results.php
index eed844b0e3e..3bfcf1aeafc 100644
--- a/module/VuFind/src/VuFind/Search/Pazpar2/Results.php
+++ b/module/VuFind/src/VuFind/Search/Pazpar2/Results.php
@@ -38,6 +38,13 @@ namespace VuFind\Search\Pazpar2;
  */
 class Results extends \VuFind\Search\Base\Results
 {
+    /**
+     * Search backend identifier.
+     *
+     * @var string
+     */
+    protected $backendId = 'Pazpar2';
+
     /**
      * Support method for performAndProcessSearch -- perform a search based on the
      * parameters passed to the object.
@@ -51,7 +58,7 @@ class Results extends \VuFind\Search\Base\Results
         $offset = $this->getStartRecord() - 1;
         $params = $this->getParams()->getBackendParameters();
         $collection = $this->getSearchService()
-            ->search('Pazpar2', $query, $offset, $limit, $params);
+            ->search($this->backendId, $query, $offset, $limit, $params);
 
         $this->resultTotal = $collection->getTotal();
         $this->results = $collection->getRecords();
diff --git a/module/VuFind/src/VuFind/Search/Primo/Results.php b/module/VuFind/src/VuFind/Search/Primo/Results.php
index f2fac9cc386..6db5e9de938 100644
--- a/module/VuFind/src/VuFind/Search/Primo/Results.php
+++ b/module/VuFind/src/VuFind/Search/Primo/Results.php
@@ -38,6 +38,13 @@ namespace VuFind\Search\Primo;
  */
 class Results extends \VuFind\Search\Base\Results
 {
+    /**
+     * Search backend identifier.
+     *
+     * @var string
+     */
+    protected $backendId = 'Primo';
+
     /**
      * Support method for performAndProcessSearch -- perform a search based on the
      * parameters passed to the object.
@@ -51,7 +58,7 @@ class Results extends \VuFind\Search\Base\Results
         $offset = $this->getStartRecord() - 1;
         $params = $this->getParams()->getBackendParameters();
         $collection = $this->getSearchService()->search(
-            'Primo', $query, $offset, $limit, $params
+            $this->backendId, $query, $offset, $limit, $params
         );
 
         $this->responseFacets = $collection->getFacets();
diff --git a/module/VuFind/src/VuFind/Search/Solr/Results.php b/module/VuFind/src/VuFind/Search/Solr/Results.php
index 5d725772acd..41fcb383ef4 100644
--- a/module/VuFind/src/VuFind/Search/Solr/Results.php
+++ b/module/VuFind/src/VuFind/Search/Solr/Results.php
@@ -51,7 +51,7 @@ class Results extends \VuFind\Search\Base\Results
     protected $responseFacets = null;
 
     /**
-     * Search backend identifiers.
+     * Search backend identifier.
      *
      * @var string
      */
diff --git a/module/VuFind/src/VuFind/Search/SolrAuth/Results.php b/module/VuFind/src/VuFind/Search/SolrAuth/Results.php
index df86e8c891e..763bcc3dc0d 100644
--- a/module/VuFind/src/VuFind/Search/SolrAuth/Results.php
+++ b/module/VuFind/src/VuFind/Search/SolrAuth/Results.php
@@ -42,17 +42,9 @@ use VuFindSearch\Service as SearchService;
 class Results extends \VuFind\Search\Solr\Results
 {
     /**
-     * Constructor
+     * Search backend identifier.
      *
-     * @param \VuFind\Search\Base\Params $params        Object representing user
-     * search parameters.
-     * @param SearchService              $searchService Search service
-     * @param Loader                     $recordLoader  Record loader
+     * @var string
      */
-    public function __construct(\VuFind\Search\Base\Params $params,
-        SearchService $searchService, Loader $recordLoader
-    ) {
-        parent::__construct($params, $searchService, $recordLoader);
-        $this->backendId = 'SolrAuth';
-    }
+    protected $backendId = 'SolrAuth';
 }
diff --git a/module/VuFind/src/VuFind/Search/SolrReserves/Results.php b/module/VuFind/src/VuFind/Search/SolrReserves/Results.php
index 404b2357843..68d5d4c1342 100644
--- a/module/VuFind/src/VuFind/Search/SolrReserves/Results.php
+++ b/module/VuFind/src/VuFind/Search/SolrReserves/Results.php
@@ -44,17 +44,9 @@ use VuFindSearch\Service as SearchService;
 class Results extends \VuFind\Search\Solr\Results
 {
     /**
-     * Constructor
+     * Search backend identifier.
      *
-     * @param \VuFind\Search\Base\Params $params        Object representing user
-     * search parameters.
-     * @param SearchService              $searchService Search service
-     * @param Loader                     $recordLoader  Record loader
+     * @var string
      */
-    public function __construct(\VuFind\Search\Base\Params $params,
-        SearchService $searchService, Loader $recordLoader
-    ) {
-        parent::__construct($params, $searchService, $recordLoader);
-        $this->backendId = 'SolrReserves';
-    }
+    protected $backendId = 'SolrReserves';
 }
diff --git a/module/VuFind/src/VuFind/Search/SolrWeb/Results.php b/module/VuFind/src/VuFind/Search/SolrWeb/Results.php
index df4f375295c..a2d3954dc4f 100644
--- a/module/VuFind/src/VuFind/Search/SolrWeb/Results.php
+++ b/module/VuFind/src/VuFind/Search/SolrWeb/Results.php
@@ -42,17 +42,9 @@ use VuFindSearch\Service as SearchService;
 class Results extends \VuFind\Search\Solr\Results
 {
     /**
-     * Constructor
+     * Search backend identifier.
      *
-     * @param \VuFind\Search\Base\Params $params        Object representing user
-     * search parameters.
-     * @param SearchService              $searchService Search service
-     * @param Loader                     $recordLoader  Record loader
+     * @var string
      */
-    public function __construct(\VuFind\Search\Base\Params $params,
-        SearchService $searchService, Loader $recordLoader
-    ) {
-        parent::__construct($params, $searchService, $recordLoader);
-        $this->backendId = 'SolrWeb';
-    }
+    protected $backendId = 'SolrWeb';
 }
diff --git a/module/VuFind/src/VuFind/Search/Summon/Results.php b/module/VuFind/src/VuFind/Search/Summon/Results.php
index 24ca9fa5d32..30498f2e85c 100644
--- a/module/VuFind/src/VuFind/Search/Summon/Results.php
+++ b/module/VuFind/src/VuFind/Search/Summon/Results.php
@@ -66,6 +66,13 @@ class Results extends \VuFind\Search\Base\Results
      */
     protected $topicRecommendations = false;
 
+    /**
+     * Search backend identifier.
+     *
+     * @var string
+     */
+    protected $backendId = 'Summon';
+
     /**
      * Support method for performAndProcessSearch -- perform a search based on the
      * parameters passed to the object.
@@ -79,7 +86,7 @@ class Results extends \VuFind\Search\Base\Results
         $offset = $this->getStartRecord() - 1;
         $params = $this->getParams()->getBackendParameters();
         $collection = $this->getSearchService()->search(
-            'Summon', $query, $offset, $limit, $params
+            $this->backendId, $query, $offset, $limit, $params
         );
 
         $this->responseFacets = $collection->getFacets();
@@ -368,7 +375,7 @@ class Results extends \VuFind\Search\Base\Results
         }
         $params = $params->getBackendParameters();
         $collection = $this->getSearchService()->search(
-            'Summon', $query, 0, 0, $params
+            $this->backendId, $query, 0, 0, $params
         );
 
         $facets = $collection->getFacets();
diff --git a/module/VuFind/src/VuFind/Search/WorldCat/Results.php b/module/VuFind/src/VuFind/Search/WorldCat/Results.php
index 8b98ffa1802..6074036b01c 100644
--- a/module/VuFind/src/VuFind/Search/WorldCat/Results.php
+++ b/module/VuFind/src/VuFind/Search/WorldCat/Results.php
@@ -38,6 +38,13 @@ namespace VuFind\Search\WorldCat;
  */
 class Results extends \VuFind\Search\Base\Results
 {
+    /**
+     * Search backend identifier.
+     *
+     * @var string
+     */
+    protected $backendId = 'WorldCat';
+
     /**
      * Support method for performAndProcessSearch -- perform a search based on the
      * parameters passed to the object.
@@ -51,7 +58,7 @@ class Results extends \VuFind\Search\Base\Results
         $offset = $this->getStartRecord();
         $params = $this->getParams()->getBackendParameters();
         $collection = $this->getSearchService()
-            ->search('WorldCat', $query, $offset, $limit, $params);
+            ->search($this->backendId, $query, $offset, $limit, $params);
 
         $this->resultTotal = $collection->getTotal();
         $this->results = $collection->getRecords();
-- 
GitLab