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

All search object generation is now done through the search manager; factored...

All search object generation is now done through the search manager; factored out old \VuFind\Search\Options class now that it is obsolete.
parent 4e109219
No related merge requests found
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
* @link http://www.vufind.org Main Page * @link http://www.vufind.org Main Page
*/ */
namespace VuFind\Search\Base; namespace VuFind\Search\Base;
use VuFind\Config\Reader as ConfigReader, VuFind\Search\Options as SearchOptions, use VuFind\Config\Reader as ConfigReader, VuFind\Translator\Translator,
VuFind\Translator\Translator,
Zend\ServiceManager\ServiceLocatorAwareInterface, Zend\ServiceManager\ServiceLocatorAwareInterface,
Zend\ServiceManager\ServiceLocatorInterface; Zend\ServiceManager\ServiceLocatorInterface;
...@@ -93,14 +92,9 @@ class Params implements ServiceLocatorAwareInterface ...@@ -93,14 +92,9 @@ class Params implements ServiceLocatorAwareInterface
// If no options have been set, use defaults: // If no options have been set, use defaults:
if (null === $this->options) { if (null === $this->options) {
// Create a copy of the default configuration: // Create a copy of the default configuration:
/* TODO: change after Search Manager refactoring
$default = $this->getSearchManager() $default = $this->getSearchManager()
->setSearchClassId($this->getSearchClassId())->getOptionsInstance(); ->setSearchClassId($this->getSearchClassId())->getOptionsInstance();
$this->options = clone($default); $this->options = clone($default);
*/
$this->options = clone(
SearchOptions::getInstance($this->getSearchClassId())
);
} }
return $this->options; return $this->options;
} }
...@@ -136,10 +130,7 @@ class Params implements ServiceLocatorAwareInterface ...@@ -136,10 +130,7 @@ class Params implements ServiceLocatorAwareInterface
*/ */
public function getSearchClassId() public function getSearchClassId()
{ {
/* TODO: change this when Search Manager refactoring is done:
return $this->getSearchManager()->extractSearchClassId(get_class($this)); return $this->getSearchManager()->extractSearchClassId(get_class($this));
*/
return SearchOptions::extractSearchClassId(get_class($this));
} }
/** /**
......
...@@ -141,7 +141,6 @@ class Manager implements ServiceLocatorAwareInterface ...@@ -141,7 +141,6 @@ class Manager implements ServiceLocatorAwareInterface
*/ */
public function getOptionsInstance() public function getOptionsInstance()
{ {
/* TODO -- uncomment this when \VuFind\Search\Options has been factored out
if (!isset($this->optionsStore[$this->classId])) { if (!isset($this->optionsStore[$this->classId])) {
$class = $this->getOptionsClass(); $class = $this->getOptionsClass();
$this->optionsStore[$this->classId] = new $class(); $this->optionsStore[$this->classId] = new $class();
...@@ -151,8 +150,6 @@ class Manager implements ServiceLocatorAwareInterface ...@@ -151,8 +150,6 @@ class Manager implements ServiceLocatorAwareInterface
$this->injectDependencies($this->optionsStore[$this->classId]); $this->injectDependencies($this->optionsStore[$this->classId]);
} }
return $this->optionsStore[$this->classId]; return $this->optionsStore[$this->classId];
*/
return Options::getInstance($this->classId);
} }
/** /**
......
<?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
...@@ -30,7 +30,6 @@ use VuFind\Config\Reader as ConfigReader, ...@@ -30,7 +30,6 @@ use VuFind\Config\Reader as ConfigReader,
VuFind\Connection\Manager as ConnectionManager, VuFind\Connection\Manager as ConnectionManager,
VuFind\Exception\RecordMissing as RecordMissingException, VuFind\Exception\RecordMissing as RecordMissingException,
VuFind\Search\Base\Results as BaseResults, VuFind\Search\Base\Results as BaseResults,
VuFind\Search\Options as SearchOptions,
VuFind\Translator\Translator; VuFind\Translator\Translator;
/** /**
...@@ -62,7 +61,8 @@ class Results extends BaseResults ...@@ -62,7 +61,8 @@ class Results extends BaseResults
// Turn on all shards by default if none are specified (we need to be sure // 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 // that any given ID will yield results, even if not all shards are on by
// default). // default).
$options = SearchOptions::getInstance($index); $sm = $this->getSearchManager();
$options = $sm->setSearchClassId($index)->getOptionsInstance();
$allShards = $options->getShards(); $allShards = $options->getShards();
if (is_null($shards)) { if (is_null($shards)) {
$shards = array_keys($allShards); $shards = array_keys($allShards);
...@@ -246,7 +246,6 @@ class Results extends BaseResults ...@@ -246,7 +246,6 @@ class Results extends BaseResults
// submitting a second search for this. // submitting a second search for this.
// Create a new search object // Create a new search object
$myClass = get_class($this);
$newParams = clone($this->getParams()); $newParams = clone($this->getParams());
$newParams->getOptions()->useBasicDictionary(); $newParams->getOptions()->useBasicDictionary();
...@@ -256,7 +255,9 @@ class Results extends BaseResults ...@@ -256,7 +255,9 @@ class Results extends BaseResults
$newParams->setLimit(0); $newParams->setLimit(0);
$newParams->recommendationsEnabled(false); $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 // Get the spelling results
$newList = $newSearch->getRawSuggestions(); $newList = $newSearch->getRawSuggestions();
...@@ -458,9 +459,9 @@ class Results extends BaseResults ...@@ -458,9 +459,9 @@ class Results extends BaseResults
$solr = $this->getSolrConnection(); $solr = $this->getSolrConnection();
// Check if we need to apply hidden filters: // Check if we need to apply hidden filters:
$options = SearchOptions::getInstance( $sm = $this->getSearchManager();
SearchOptions::extractSearchClassId(get_called_class()) $sm->setSearchClassId($sm->extractSearchClassId(get_class($this)));
); $options = $sm->getOptionsInstance();
$filters = $options->getHiddenFilters(); $filters = $options->getHiddenFilters();
$extras = empty($filters) ? array() : array('fq' => $filters); $extras = empty($filters) ? array() : array('fq' => $filters);
...@@ -484,7 +485,7 @@ class Results extends BaseResults ...@@ -484,7 +485,7 @@ class Results extends BaseResults
{ {
// Figure out how many records to retrieve at the same time -- // Figure out how many records to retrieve at the same time --
// we'll use either 100 or the ID request limit, whichever is smaller. // 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(); $params = $sm->setSearchClassId('Solr')->getParams();
$pageSize = $params->getQueryIDLimit(); $pageSize = $params->getQueryIDLimit();
if ($pageSize < 1 || $pageSize > 100) { if ($pageSize < 1 || $pageSize > 100) {
......
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