From 0a1f0ab8b89f6820b58132df74befef6613280fe Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 7 Sep 2012 15:05:04 -0400 Subject: [PATCH] All search object generation is now done through the search manager; factored out old \VuFind\Search\Options class now that it is obsolete. --- .../VuFind/src/VuFind/Search/Base/Params.php | 11 +-- module/VuFind/src/VuFind/Search/Manager.php | 3 - module/VuFind/src/VuFind/Search/Options.php | 72 ------------------- .../VuFind/src/VuFind/Search/Solr/Results.php | 17 ++--- 4 files changed, 10 insertions(+), 93 deletions(-) delete mode 100644 module/VuFind/src/VuFind/Search/Options.php diff --git a/module/VuFind/src/VuFind/Search/Base/Params.php b/module/VuFind/src/VuFind/Search/Base/Params.php index a9558886bb3..29ca8e077d2 100644 --- a/module/VuFind/src/VuFind/Search/Base/Params.php +++ b/module/VuFind/src/VuFind/Search/Base/Params.php @@ -26,8 +26,7 @@ * @link http://www.vufind.org Main Page */ namespace VuFind\Search\Base; -use VuFind\Config\Reader as ConfigReader, VuFind\Search\Options as SearchOptions, - VuFind\Translator\Translator, +use VuFind\Config\Reader as ConfigReader, VuFind\Translator\Translator, Zend\ServiceManager\ServiceLocatorAwareInterface, Zend\ServiceManager\ServiceLocatorInterface; @@ -93,14 +92,9 @@ class Params implements ServiceLocatorAwareInterface // If no options have been set, use defaults: if (null === $this->options) { // Create a copy of the default configuration: - /* TODO: change after Search Manager refactoring $default = $this->getSearchManager() ->setSearchClassId($this->getSearchClassId())->getOptionsInstance(); $this->options = clone($default); - */ - $this->options = clone( - SearchOptions::getInstance($this->getSearchClassId()) - ); } return $this->options; } @@ -136,10 +130,7 @@ class Params implements ServiceLocatorAwareInterface */ public function getSearchClassId() { - /* TODO: change this when Search Manager refactoring is done: return $this->getSearchManager()->extractSearchClassId(get_class($this)); - */ - return SearchOptions::extractSearchClassId(get_class($this)); } /** diff --git a/module/VuFind/src/VuFind/Search/Manager.php b/module/VuFind/src/VuFind/Search/Manager.php index 462f1de0363..8c96cf0c295 100644 --- a/module/VuFind/src/VuFind/Search/Manager.php +++ b/module/VuFind/src/VuFind/Search/Manager.php @@ -141,7 +141,6 @@ class Manager implements ServiceLocatorAwareInterface */ public function getOptionsInstance() { - /* TODO -- uncomment this when \VuFind\Search\Options has been factored out if (!isset($this->optionsStore[$this->classId])) { $class = $this->getOptionsClass(); $this->optionsStore[$this->classId] = new $class(); @@ -151,8 +150,6 @@ class Manager implements ServiceLocatorAwareInterface $this->injectDependencies($this->optionsStore[$this->classId]); } return $this->optionsStore[$this->classId]; - */ - return Options::getInstance($this->classId); } /** diff --git a/module/VuFind/src/VuFind/Search/Options.php b/module/VuFind/src/VuFind/Search/Options.php deleted file mode 100644 index 386f418038d..00000000000 --- a/module/VuFind/src/VuFind/Search/Options.php +++ /dev/null @@ -1,72 +0,0 @@ -<?php -/** - * Instance store for obtaining default search options objects. - * - * 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 Search - * @author Demian Katz <demian.katz@villanova.edu> - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link http://vufind.org Main Site - */ -namespace VuFind\Search; - -/** - * Instance store for obtaining default search options objects. - * - * @category VuFind2 - * @package Search - * @author Demian Katz <demian.katz@villanova.edu> - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link http://vufind.org Main Site - */ -class Options -{ - /** - * Basic get - * - * @param string $type The search type of the object to retrieve - * - * @return \VuFind\Search\Base\Options - */ - public static function getInstance($type) - { - static $store = array(); - - if (!isset($store[$type])) { - $class = 'VuFind\Search\\' . $type . '\Options'; - $store[$type] = new $class(); - } - return $store[$type]; - } - - /** - * Extract the name of the search class family from a class name. - * - * @param string $className Class name to examine. - * - * @return string - */ - public static function extractSearchClassId($className) - { - // Parse identifier out of class name of format VuFind\Search\[id]\Params: - $class = explode('\\', $className); - return $class[2]; - } -} \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Search/Solr/Results.php b/module/VuFind/src/VuFind/Search/Solr/Results.php index 21d060797f1..0127da9b693 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Results.php +++ b/module/VuFind/src/VuFind/Search/Solr/Results.php @@ -30,7 +30,6 @@ use VuFind\Config\Reader as ConfigReader, VuFind\Connection\Manager as ConnectionManager, VuFind\Exception\RecordMissing as RecordMissingException, VuFind\Search\Base\Results as BaseResults, - VuFind\Search\Options as SearchOptions, VuFind\Translator\Translator; /** @@ -62,7 +61,8 @@ class Results extends BaseResults // Turn on all shards by default if none are specified (we need to be sure // that any given ID will yield results, even if not all shards are on by // default). - $options = SearchOptions::getInstance($index); + $sm = $this->getSearchManager(); + $options = $sm->setSearchClassId($index)->getOptionsInstance(); $allShards = $options->getShards(); if (is_null($shards)) { $shards = array_keys($allShards); @@ -246,7 +246,6 @@ class Results extends BaseResults // submitting a second search for this. // Create a new search object - $myClass = get_class($this); $newParams = clone($this->getParams()); $newParams->getOptions()->useBasicDictionary(); @@ -256,7 +255,9 @@ class Results extends BaseResults $newParams->setLimit(0); $newParams->recommendationsEnabled(false); - $newSearch = new $myClass($newParams); + $sm = $this->getSearchManager(); + $sm->setSearchClassId($sm->extractSearchClassId(get_class($this))); + $newSearch = $sm->getResults($newParams); // Get the spelling results $newList = $newSearch->getRawSuggestions(); @@ -458,9 +459,9 @@ class Results extends BaseResults $solr = $this->getSolrConnection(); // Check if we need to apply hidden filters: - $options = SearchOptions::getInstance( - SearchOptions::extractSearchClassId(get_called_class()) - ); + $sm = $this->getSearchManager(); + $sm->setSearchClassId($sm->extractSearchClassId(get_class($this))); + $options = $sm->getOptionsInstance(); $filters = $options->getHiddenFilters(); $extras = empty($filters) ? array() : array('fq' => $filters); @@ -484,7 +485,7 @@ class Results extends BaseResults { // Figure out how many records to retrieve at the same time -- // we'll use either 100 or the ID request limit, whichever is smaller. - $sm = $this->getServiceLocator()->get('SearchManager'); + $sm = $this->getSearchManager(); $params = $sm->setSearchClassId('Solr')->getParams(); $pageSize = $params->getQueryIDLimit(); if ($pageSize < 1 || $pageSize > 100) { -- GitLab