From c21bb2c03f3719b82c638165ca17c7687e013ae1 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 5 Sep 2012 10:32:00 -0400
Subject: [PATCH] Updated abstract search controller to use search manager.

---
 .../src/VuFind/Controller/AbstractSearch.php  | 44 +++++++------------
 1 file changed, 17 insertions(+), 27 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/AbstractSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSearch.php
index 702a1160142..0b743cee05a 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractSearch.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractSearch.php
@@ -27,8 +27,7 @@
  */
 namespace VuFind\Controller;
 use VuFind\Db\Table\Search as SearchTable, VuFind\Record\Router as RecordRouter,
-    VuFind\Search\Memory, VuFind\Search\Options as SearchOptions,
-    Zend\Stdlib\Parameters;
+    VuFind\Search\Memory, Zend\Stdlib\Parameters;
 
 /**
  * VuFind Search Controller
@@ -71,6 +70,16 @@ class AbstractSearch extends AbstractBase
         return $view;
     }
 
+    /**
+     * Get the search manager.
+     *
+     * @return \VuFind\Search\Manager
+     */
+    public function getSearchManager()
+    {
+        return $this->getServiceLocator()->get('SearchManager');
+    }
+
     /**
      * Handle an advanced search
      *
@@ -79,7 +88,9 @@ class AbstractSearch extends AbstractBase
     public function advancedAction()
     {
         $view = $this->createViewModel();
-        $view->options = SearchOptions::getInstance($this->searchClassId);
+        $view->options = $this->getSearchManager()
+            ->setSearchClassId($this->searchClassId)
+            ->getOptionsInstance();
         if ($view->options->getAdvancedSearchAction() === false) {
             throw new \Exception('Advanced search not supported.');
         }
@@ -148,8 +159,8 @@ class AbstractSearch extends AbstractBase
             return $this->redirectToSavedSearch($savedId);
         }
 
-        $paramsClass = $this->getParamsClass();
-        $params = new $paramsClass();
+        $manager = $this->getSearchManager()->setSearchClassId($this->searchClassId);
+        $params = $manager->getParams();
         $params->recommendationsEnabled(true);
 
         // Send both GET and POST variables to search class:
@@ -163,8 +174,7 @@ 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 {
-            $resultsClass = $this->getResultsClass();
-            $results = new $resultsClass($params);
+            $results = $manager->getResults($params);
 
             // Explicitly execute search within controller -- this allows us to
             // catch exceptions more reliably:
@@ -264,26 +274,6 @@ class AbstractSearch extends AbstractBase
         return $this->redirect()->toRoute($details['route'], $details['params']);
     }
 
-    /**
-     * Get the name of the class used for setting search parameters.
-     *
-     * @return string
-     */
-    protected function getParamsClass()
-    {
-        return 'VuFind\Search\\' . $this->searchClassId . '\Params';
-    }
-
-    /**
-     * Get the name of the class used for retrieving search results.
-     *
-     * @return string
-     */
-    protected function getResultsClass()
-    {
-        return 'VuFind\Search\\' . $this->searchClassId . '\Results';
-    }
-
     /**
      * Either assign the requested search object to the view or display a flash
      * message indicating why the operation failed.
-- 
GitLab