diff --git a/module/VuFind/src/VuFind/Recommend/AbstractSearchManagerAwareModule.php b/module/VuFind/src/VuFind/Recommend/AbstractSearchManagerAwareModule.php new file mode 100644 index 0000000000000000000000000000000000000000..76cb941a936a86071f616b335e1401a6fc1dc31d --- /dev/null +++ b/module/VuFind/src/VuFind/Recommend/AbstractSearchManagerAwareModule.php @@ -0,0 +1,80 @@ +<?php +/** + * Abstract base class for accessing the search manager for recommendation purposes. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Recommendations + * @author Demian Katz <demian.katz@villanova.edu> + * @author Chris Hallberg <challber@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/building_a_recommendations_module Wiki + */ +namespace VuFind\Recommend; +use Zend\ServiceManager\ServiceLocatorInterface, + Zend\ServiceManager\ServiceLocatorAwareInterface; + +/** + * Abstract base class for accessing the search manager for recommendation purposes. + * + * @category VuFind2 + * @package Recommendations + * @author Demian Katz <demian.katz@villanova.edu> + * @author Chris Hallberg <challber@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/building_a_recommendations_module Wiki + */ +abstract class AbstractSearchManagerAwareModule implements RecommendInterface, + ServiceLocatorAwareInterface +{ + protected $serviceLocator; + + /** + * 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; + } + + /** + * Get the search manager. + * + * @return \VuFind\Search\Manager + */ + public function getSearchManager() + { + return $this->getServiceLocator()->getServiceLocator()->get('SearchManager'); + } +} \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Recommend/AuthorFacets.php b/module/VuFind/src/VuFind/Recommend/AuthorFacets.php index 7acf6eb355f38653a30f49ff2edc332b7976ea7f..a06a3bd588e9d19f7592d14427338f82948071f9 100644 --- a/module/VuFind/src/VuFind/Recommend/AuthorFacets.php +++ b/module/VuFind/src/VuFind/Recommend/AuthorFacets.php @@ -27,10 +27,7 @@ * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ namespace VuFind\Recommend; -use VuFind\Search\SolrAuthorFacets\Options as SolrAuthorFacetsOptions, - VuFind\Search\SolrAuthorFacets\Params as SolrAuthorFacetsParams, - VuFind\Search\SolrAuthorFacets\Results as SolrAuthorFacetsResults, - Zend\Http\Request, Zend\StdLib\Parameters; +use Zend\Http\Request, Zend\StdLib\Parameters; /** * AuthorFacets Recommendations Module @@ -45,7 +42,7 @@ use VuFind\Search\SolrAuthorFacets\Options as SolrAuthorFacetsOptions, * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -class AuthorFacets implements RecommendInterface +class AuthorFacets extends AbstractSearchManagerAwareModule { protected $settings; protected $searchObject; @@ -138,16 +135,17 @@ class AuthorFacets implements RecommendInterface } // Set up a special limit for the AuthorFacets search object: - $options = new SolrAuthorFacetsOptions(); + $sm = $this->getSearchManager()->setSearchClassId('SolrAuthorFacets'); + $options = $sm->getOptionsInstance(); $options->setLimitOptions(array(10)); // Initialize an AuthorFacets search object using parameters from the // current Solr search object. - $params = new SolrAuthorFacetsParams($options); + $params = $sm->getParams($options); $params->initFromRequest(new Parameters(array('lookfor' => $lookfor))); // Send back the results: - $results = new SolrAuthorFacetsResults($params); + $results = $sm->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 2307403077d46981a64d07cd8b15ab2e0020f5ed..cbfe4aa57c95e3c889fd998bb29aaef5243e4930 100644 --- a/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php +++ b/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php @@ -30,8 +30,6 @@ */ namespace VuFind\Recommend; use VuFind\Exception\Solr as SolrException, - VuFind\Search\SolrAuth\Params as SolrAuthParams, - VuFind\Search\SolrAuth\Results as SolrAuthResults, Zend\Http\Request, Zend\StdLib\Parameters; /** @@ -50,7 +48,7 @@ use VuFind\Exception\Solr as SolrException, * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://www.vufind.org Main Page */ -class AuthorityRecommend implements RecommendInterface +class AuthorityRecommend extends AbstractSearchManagerAwareModule { protected $searchObject; protected $lookfor; @@ -137,12 +135,13 @@ class AuthorityRecommend implements RecommendInterface // Initialise and process search (ignore Solr errors -- no reason to fail // just because search syntax is not compatible with Authority core): try { - $authParams = new SolrAuthParams(); + $sm = $this->getSearchManager()->setSearchClassId('SolrAuth'); + $authParams = $sm->getParams(); $authParams->initFromRequest($request); foreach ($this->filters as $filter) { $authParams->getOptions()->addHiddenFilter($filter); } - $authResults = new SolrAuthResults($authParams); + $authResults = $sm->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 7c78ecd6bd05921373d81304b105ebdb53fc8dd8..7233f1d878a3a56a2ac985bf06e40d51f5440ac3 100644 --- a/module/VuFind/src/VuFind/Recommend/SearchObject.php +++ b/module/VuFind/src/VuFind/Recommend/SearchObject.php @@ -38,7 +38,7 @@ namespace VuFind\Recommend; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -abstract class SearchObject implements RecommendInterface +abstract class SearchObject extends AbstractSearchManagerAwareModule { protected $results; protected $limit; @@ -79,15 +79,13 @@ abstract class SearchObject implements RecommendInterface public function init($params, $request) { // Build a search parameters object: - $id = $this->getSearchClassId(); - $paramsClass = 'VuFind\Search\\' . $id . '\Params'; - $params = new $paramsClass(); + $sm = $this->getSearchManager()->setSearchClassId($this->getSearchClassId()); + $params = $sm->getParams(); $params->setLimit($this->limit); $params->setBasicSearch($request->get($this->requestParam)); // Perform the search: - $resultsClass = 'VuFind\Search\\' . $id . '\Results'; - $this->results = new $resultsClass($params); + $this->results = $sm->getResults($params); $this->results->performAndProcessSearch(); } diff --git a/module/VuFind/src/VuFind/Recommend/SummonDatabases.php b/module/VuFind/src/VuFind/Recommend/SummonDatabases.php index 6a01be66bacc83dfde311bdf30d789dd8a1919f4..2fb03d579ebe5993acb2576f707e8ff1ce7f58ab 100644 --- a/module/VuFind/src/VuFind/Recommend/SummonDatabases.php +++ b/module/VuFind/src/VuFind/Recommend/SummonDatabases.php @@ -26,8 +26,6 @@ * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ namespace VuFind\Recommend; -use VuFind\Search\Summon\Params as SummonParams, - VuFind\Search\Summon\Results as SummonResults; /** * SummonDatabases Recommendations Module @@ -40,7 +38,7 @@ use VuFind\Search\Summon\Params as SummonParams, * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ -class SummonDatabases implements RecommendInterface +class SummonDatabases extends AbstractSearchManagerAwareModule { protected $databases; protected $requestParam = 'lookfor'; @@ -99,9 +97,10 @@ class SummonDatabases implements RecommendInterface // to create a new Summon search object using the specified request // parameter for search terms. if ($results->getParams()->getSearchClassId() != 'Summon') { - $params = new SummonParams(); + $sm = $this->getSearchManager()->setSearchClassId('Summon'); + $params = $sm->getParams(); $params->setBasicSearch($this->lookfor); - $results = new SummonResults($params); + $results = $sm->getResults($params); $results->performAndProcessSearch(); } $this->databases = $results->getDatabaseRecommendations();