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

Updated recommendation modules to use search manager where appropriate.

parent 2244c3f0
No related merge requests found
<?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
......@@ -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
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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();
......
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