From 033a4ebc42d23bc091f5915c86f42bf5b5460a7b Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 5 Sep 2012 14:18:22 -0400 Subject: [PATCH] Updated recommendation modules to use search manager where appropriate. --- .../AbstractSearchManagerAwareModule.php | 80 +++++++++++++++++++ .../src/VuFind/Recommend/AuthorFacets.php | 14 ++-- .../VuFind/Recommend/AuthorityRecommend.php | 9 +-- .../src/VuFind/Recommend/SearchObject.php | 10 +-- .../src/VuFind/Recommend/SummonDatabases.php | 9 +-- 5 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 module/VuFind/src/VuFind/Recommend/AbstractSearchManagerAwareModule.php diff --git a/module/VuFind/src/VuFind/Recommend/AbstractSearchManagerAwareModule.php b/module/VuFind/src/VuFind/Recommend/AbstractSearchManagerAwareModule.php new file mode 100644 index 00000000000..76cb941a936 --- /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 7acf6eb355f..a06a3bd588e 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 2307403077d..cbfe4aa57c9 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 7c78ecd6bd0..7233f1d878a 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 6a01be66bac..2fb03d579eb 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(); -- GitLab