From d4770d987b8eb7f72d593d1d6c8912270a259499 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 5 Sep 2012 12:27:28 -0400
Subject: [PATCH] Simplified Solr autocomplete subclasses and adjusted base
 class to use Search Manager and to disable recommendations for better
 performance.

---
 .../VuFind/src/VuFind/Autocomplete/Solr.php   | 38 +++++++++++++++++--
 .../src/VuFind/Autocomplete/SolrAuth.php      | 15 +-------
 .../src/VuFind/Autocomplete/SolrReserves.php  | 16 +-------
 3 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/module/VuFind/src/VuFind/Autocomplete/Solr.php b/module/VuFind/src/VuFind/Autocomplete/Solr.php
index cc989178fbf..026e3f3661c 100644
--- a/module/VuFind/src/VuFind/Autocomplete/Solr.php
+++ b/module/VuFind/src/VuFind/Autocomplete/Solr.php
@@ -27,6 +27,8 @@
  * @link     http://vufind.org/wiki/autocomplete Wiki
  */
 namespace VuFind\Autocomplete;
+use Zend\ServiceManager\ServiceLocatorAwareInterface,
+    Zend\ServiceManager\ServiceLocatorInterface;
 
 /**
  * Solr Autocomplete Module
@@ -39,13 +41,14 @@ namespace VuFind\Autocomplete;
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://vufind.org/wiki/autocomplete Wiki
  */
-class Solr implements AutocompleteInterface
+class Solr implements AutocompleteInterface, ServiceLocatorAwareInterface
 {
     protected $handler;
     protected $displayField;
     protected $defaultDisplayField = 'title';
     protected $sortField;
     protected $filters;
+    protected $searchClassId = 'Solr';
     protected $searchObject;
 
 
@@ -91,10 +94,15 @@ class Solr implements AutocompleteInterface
      */
     protected function initSearchObject()
     {
+        // Get the search manager:
+        $sm = $this->getServiceLocator()->getServiceLocator()->get('SearchManager');
+        $sm->setSearchClassId($this->searchClassId);
+
         // Build a new search object:
-        $params = new \VuFind\Search\Solr\Params();
-        $this->searchObject = new \VuFind\Search\Solr\Results($params);
-        $this->searchObject->getOptions()->spellcheckEnabled(false);
+        $params = $sm->getParams();
+        $params->getOptions()->spellcheckEnabled(false);
+        $params->recommendationsEnabled(false);
+        $this->searchObject = $sm->getResults($params);
     }
 
     /**
@@ -279,4 +287,26 @@ class Solr implements AutocompleteInterface
         return true;
     }
 
+    /**
+     * Set the service locator.
+     *
+     * @param ServiceLocatorInterface $serviceLocator Locator to register
+     *
+     * @return Manager
+     */
+    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
+    {
+        $this->serviceLocator = $serviceLocator;
+        return $this;
+    }
+
+    /**
+     * Get the service locator.
+     *
+     * @return \Zend\ServiceManager\ServiceLocatorInterface
+     */
+    public function getServiceLocator()
+    {
+        return $this->serviceLocator;
+    }
 }
diff --git a/module/VuFind/src/VuFind/Autocomplete/SolrAuth.php b/module/VuFind/src/VuFind/Autocomplete/SolrAuth.php
index daa42eb352b..b8efbcda43d 100644
--- a/module/VuFind/src/VuFind/Autocomplete/SolrAuth.php
+++ b/module/VuFind/src/VuFind/Autocomplete/SolrAuth.php
@@ -47,19 +47,6 @@ class SolrAuth extends Solr
     public function __construct()
     {
         $this->defaultDisplayField = 'heading';
-    }
-
-    /**
-     * initSearchObject
-     *
-     * Initialize the search object used for finding recommendations.
-     *
-     * @return void
-     */
-    protected function initSearchObject()
-    {
-        // Build a new search object:
-        $params = new \VuFind\Search\SolrAuth\Params();
-        $this->searchObject = new \VuFind\Search\SolrAuth\Results($params);
+        $this->searchClassId = 'SolrAuth';
     }
 }
diff --git a/module/VuFind/src/VuFind/Autocomplete/SolrReserves.php b/module/VuFind/src/VuFind/Autocomplete/SolrReserves.php
index e6a91ec5a2c..73851191d25 100644
--- a/module/VuFind/src/VuFind/Autocomplete/SolrReserves.php
+++ b/module/VuFind/src/VuFind/Autocomplete/SolrReserves.php
@@ -47,20 +47,6 @@ class SolrReserves extends Solr
     public function __construct()
     {
         $this->defaultDisplayField = 'course';
-    }
-
-    /**
-     * initSearchObject
-     *
-     * Initialize the search object used for finding recommendations.
-     *
-     * @return void
-     */
-    protected function initSearchObject()
-    {
-        // Build a new search object:
-        $params = new \VuFind\Search\SolrReserves\Params();
-        $this->searchObject = new \VuFind\Search\SolrReserves\Results($params);
-        $this->searchObject->getOptions()->spellcheckEnabled(false);
+        $this->searchClassId = 'SolrReserves';
     }
 }
-- 
GitLab