Skip to content
Snippets Groups Projects
Commit c21bb2c0 authored by Demian Katz's avatar Demian Katz
Browse files

Updated abstract search controller to use search manager.

parent 15766889
No related merge requests found
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
*/ */
namespace VuFind\Controller; namespace VuFind\Controller;
use VuFind\Db\Table\Search as SearchTable, VuFind\Record\Router as RecordRouter, use VuFind\Db\Table\Search as SearchTable, VuFind\Record\Router as RecordRouter,
VuFind\Search\Memory, VuFind\Search\Options as SearchOptions, VuFind\Search\Memory, Zend\Stdlib\Parameters;
Zend\Stdlib\Parameters;
/** /**
* VuFind Search Controller * VuFind Search Controller
...@@ -71,6 +70,16 @@ class AbstractSearch extends AbstractBase ...@@ -71,6 +70,16 @@ class AbstractSearch extends AbstractBase
return $view; return $view;
} }
/**
* Get the search manager.
*
* @return \VuFind\Search\Manager
*/
public function getSearchManager()
{
return $this->getServiceLocator()->get('SearchManager');
}
/** /**
* Handle an advanced search * Handle an advanced search
* *
...@@ -79,7 +88,9 @@ class AbstractSearch extends AbstractBase ...@@ -79,7 +88,9 @@ class AbstractSearch extends AbstractBase
public function advancedAction() public function advancedAction()
{ {
$view = $this->createViewModel(); $view = $this->createViewModel();
$view->options = SearchOptions::getInstance($this->searchClassId); $view->options = $this->getSearchManager()
->setSearchClassId($this->searchClassId)
->getOptionsInstance();
if ($view->options->getAdvancedSearchAction() === false) { if ($view->options->getAdvancedSearchAction() === false) {
throw new \Exception('Advanced search not supported.'); throw new \Exception('Advanced search not supported.');
} }
...@@ -148,8 +159,8 @@ class AbstractSearch extends AbstractBase ...@@ -148,8 +159,8 @@ class AbstractSearch extends AbstractBase
return $this->redirectToSavedSearch($savedId); return $this->redirectToSavedSearch($savedId);
} }
$paramsClass = $this->getParamsClass(); $manager = $this->getSearchManager()->setSearchClassId($this->searchClassId);
$params = new $paramsClass(); $params = $manager->getParams();
$params->recommendationsEnabled(true); $params->recommendationsEnabled(true);
// Send both GET and POST variables to search class: // Send both GET and POST variables to search class:
...@@ -163,8 +174,7 @@ class AbstractSearch extends AbstractBase ...@@ -163,8 +174,7 @@ class AbstractSearch extends AbstractBase
// Attempt to perform the search; if there is a problem, inspect any Solr // 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. // exceptions to see if we should communicate to the user about them.
try { try {
$resultsClass = $this->getResultsClass(); $results = $manager->getResults($params);
$results = new $resultsClass($params);
// Explicitly execute search within controller -- this allows us to // Explicitly execute search within controller -- this allows us to
// catch exceptions more reliably: // catch exceptions more reliably:
...@@ -264,26 +274,6 @@ class AbstractSearch extends AbstractBase ...@@ -264,26 +274,6 @@ class AbstractSearch extends AbstractBase
return $this->redirect()->toRoute($details['route'], $details['params']); 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 * Either assign the requested search object to the view or display a flash
* message indicating why the operation failed. * message indicating why the operation failed.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment