diff --git a/module/FacetPrefix/config/module.config.php b/module/FacetPrefix/config/module.config.php index efdd777663..e4ec815ace 100644 --- a/module/FacetPrefix/config/module.config.php +++ b/module/FacetPrefix/config/module.config.php @@ -6,9 +6,11 @@ 'allow_override' => true, 'factories' => [ 'FacetPrefix\Search\Params\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', + 'FacetPrefix\Search\Results\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory', ], 'aliases' => [ 'VuFind\Search\Params\PluginManager' => 'FacetPrefix\Search\Params\PluginManager', + 'VuFind\Search\Results\PluginManager' => 'FacetPrefix\Search\Results\PluginManager', ], ], ]; diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Params/ParamsFactory.php b/module/FacetPrefix/src/FacetPrefix/Search/Params/ParamsFactory.php index 1c61dd3c4d..0f8bc83072 100644 --- a/module/FacetPrefix/src/FacetPrefix/Search/Params/ParamsFactory.php +++ b/module/FacetPrefix/src/FacetPrefix/Search/Params/ParamsFactory.php @@ -60,7 +60,7 @@ public function __invoke(ContainerInterface $container, $requestedName, ) { // Replace trailing "Params" with "Options" to get the options service: $optionsService = preg_replace('/Params$/', 'Options', $requestedName); - // Replace leading "FacetPrefix" with "VuFind" to get the VuFind options service: + // Replace leading "SearchKeys" with "VuFind" to get the VuFind options service: $optionsService = preg_replace('/^FacetPrefix/', 'VuFind', $optionsService); $optionsObj = $container->get('VuFind\Search\Options\PluginManager') ->get($optionsService); diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Params/PluginManager.php b/module/FacetPrefix/src/FacetPrefix/Search/Params/PluginManager.php index 2a786dcca1..6e38efa8b6 100644 --- a/module/FacetPrefix/src/FacetPrefix/Search/Params/PluginManager.php +++ b/module/FacetPrefix/src/FacetPrefix/Search/Params/PluginManager.php @@ -112,6 +112,22 @@ class PluginManager extends \VuFind\Search\Params\PluginManager public function __construct($configOrContainerInstance = null, array $v3config = [] ) { + // These objects are not meant to be shared -- every time we retrieve one, + // we are building a brand new object. + $this->sharedByDefault = false; + + $this->addAbstractFactory('VuFind\Search\Params\PluginFactory'); parent::__construct($configOrContainerInstance, $v3config); } + + /** + * Return the name of the base class or interface that plug-ins must conform + * to. + * + * @return string + */ + protected function getExpectedInterface() + { + return 'VuFind\Search\Base\Params'; + } } diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Primo/Params.php b/module/FacetPrefix/src/FacetPrefix/Search/Primo/Params.php new file mode 100644 index 0000000000..a6a825344b --- /dev/null +++ b/module/FacetPrefix/src/FacetPrefix/Search/Primo/Params.php @@ -0,0 +1,67 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://github.com/subhh/beluga + */ +namespace FacetPrefix\Search\Primo; + +use Libraries\Libraries; +use VuFindSearch\ParamBag; + +class Params extends \Libraries\Search\Primo\Params +{ + + /** + * Constructor + * + * @param \VuFind\Search\Base\Options $options Options to use + * @param \VuFind\Config\PluginManager $configLoader Config loader + */ + public function __construct($options, \VuFind\Config\PluginManager $configLoader, + \VuFind\Search\Memory $searchMemory + ) { + parent::__construct($options, $configLoader); + } + + /** + * Return current facet configurations + * + * @return array $facetSet + */ + public function getFacetSettings() + { + $facetSet = parent::getFacetSettings(); + + $facetConfig = $this->configLoader->get('facets'); + if (isset($facetConfig->FacetPrefix)) { + foreach ($facetConfig->FacetPrefix as $facet => $prefix) { + $facetSet["f.{$facet}.facet.prefix"] = $prefix; + } + } + + return $facetSet; + } +} + diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Results/PluginManager.php b/module/FacetPrefix/src/FacetPrefix/Search/Results/PluginManager.php new file mode 100644 index 0000000000..019c81992f --- /dev/null +++ b/module/FacetPrefix/src/FacetPrefix/Search/Results/PluginManager.php @@ -0,0 +1,103 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki + */ +namespace FacetPrefix\Search\Results; + +/** + * Search results plugin manager + * + * @category VuFind + * @package Search + * @author Demian Katz + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki + */ +class PluginManager extends \Libraries\Search\Results\PluginManager +{ + /** + * Default plugin aliases. + * + * @var array + */ + protected $aliases = [ + 'browzine' => 'VuFind\Search\BrowZine\Results', + 'combined' => 'VuFind\Search\Combined\Results', + 'eds' => 'VuFind\Search\EDS\Results', + 'eit' => 'VuFind\Search\EIT\Results', + 'emptyset' => 'VuFind\Search\EmptySet\Results', + 'favorites' => 'VuFind\Search\Favorites\Results', + 'libguides' => 'VuFind\Search\LibGuides\Results', + 'mixedlist' => 'VuFind\Search\MixedList\Results', + 'pazpar2' => 'VuFind\Search\Pazpar2\Results', + 'primo' => 'VuFind\Search\Primo\Results', + 'search2' => 'VuFind\Search\Search2\Results', + 'solr' => 'VuFind\Search\Solr\Results', + 'solrauth' => 'VuFind\Search\SolrAuth\Results', + 'solrauthor' => 'VuFind\Search\SolrAuthor\Results', + 'solrauthorfacets' => 'VuFind\Search\SolrAuthorFacets\Results', + 'solrcollection' => 'VuFind\Search\SolrCollection\Results', + 'solrreserves' => 'VuFind\Search\SolrReserves\Results', + 'solrweb' => 'VuFind\Search\SolrWeb\Results', + 'summon' => 'VuFind\Search\Summon\Results', + 'tags' => 'VuFind\Search\Tags\Results', + 'worldcat' => 'VuFind\Search\WorldCat\Results', + ]; + + /** + * Default plugin factories. + * + * @var array + */ + protected $factories = [ + 'VuFind\Search\BrowZine\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\Combined\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\EDS\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\EIT\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\EmptySet\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\Favorites\Results' => + 'VuFind\Search\Favorites\ResultsFactory', + 'VuFind\Search\LibGuides\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\MixedList\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\Pazpar2\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\Primo\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\Search2\Results' => 'FacetPrefix\Search\Search2\ResultsFactory', + 'VuFind\Search\Solr\Results' => 'FacetPrefix\Search\Solr\ResultsFactory', + 'VuFind\Search\SolrAuth\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\SolrAuthor\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\SolrAuthorFacets\Results' => + 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\SolrCollection\Results' => + 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\SolrReserves\Results' => + 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\SolrWeb\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\Summon\Results' => 'VuFind\Search\Results\ResultsFactory', + 'VuFind\Search\Tags\Results' => 'VuFind\Search\Tags\ResultsFactory', + 'VuFind\Search\WorldCat\Results' => 'VuFind\Search\Results\ResultsFactory', + ]; + +} diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Results/ResultsFactory.php b/module/FacetPrefix/src/FacetPrefix/Search/Results/ResultsFactory.php new file mode 100644 index 0000000000..2105085c62 --- /dev/null +++ b/module/FacetPrefix/src/FacetPrefix/Search/Results/ResultsFactory.php @@ -0,0 +1,72 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace FacetPrefix\Search\Results; + +use Interop\Container\ContainerInterface; +use Zend\ServiceManager\Factory\FactoryInterface; + +/** + * Generic factory for search results objects. + * + * @category VuFind + * @package Search + * @author Demian Katz + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class ResultsFactory implements FactoryInterface +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + // Replace trailing "Results" with "Params" to get the params service: + $paramsService = preg_replace('/Results$/', 'Params', $requestedName); + $paramsService = preg_replace('/^VuFind/', 'FacetPrefix', $paramsService); + $params = $container->get('FacetPrefix\Search\Params\PluginManager') + ->get($paramsService); + $searchService = $container->get('VuFindSearch\Service'); + $recordLoader = $container->get('VuFind\Record\Loader'); + return new $requestedName( + $params, $searchService, $recordLoader, ...($options ?: []) + ); + } +} diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Search2/Params.php b/module/FacetPrefix/src/FacetPrefix/Search/Search2/Params.php index eccfe273e5..330025e809 100644 --- a/module/FacetPrefix/src/FacetPrefix/Search/Search2/Params.php +++ b/module/FacetPrefix/src/FacetPrefix/Search/Search2/Params.php @@ -27,11 +27,12 @@ */ namespace FacetPrefix\Search\Search2; +use Libraries\Libraries; use VuFindSearch\ParamBag; use VuFind\Search\Solr\HierarchicalFacetHelper; -use VuFind\Search\Search2\Params as BaseParams; +use SearchKeys\Search\SearchKeysHelper; -class Params extends BaseParams +class Params extends \Libraries\Search\Search2\Params { /** * Constructor @@ -40,9 +41,11 @@ class Params extends BaseParams * @param \VuFind\Config\PluginManager $configLoader Config loader */ public function __construct($options, \VuFind\Config\PluginManager $configLoader, - HierarchicalFacetHelper $facetHelper = null + HierarchicalFacetHelper $facetHelper = null, + SearchKeysHelper $searchKeysHelper, + \VuFind\Search\Memory $searchMemory ) { - parent::__construct($options, $configLoader, $facetHelper); + parent::__construct($options, $configLoader, $facetHelper, $searchKeysHelper, $searchMemory); } /** @@ -60,11 +63,13 @@ public function getFacetSettings() $facetSet["f.{$facet}.facet.prefix"] = $prefix; } } - if (isset($facetConfig->FacetMatches)) { + + if (isset($facetConfig->FacetMatches)) { foreach ($facetConfig->FacetMatches as $facet => $matches) { $facetSet["f.{$facet}.facet.matches"] = $matches; } } + return $facetSet; } } diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Search2/ParamsFactory.php b/module/FacetPrefix/src/FacetPrefix/Search/Search2/ParamsFactory.php index 8484a93ed9..5390ae32ee 100644 --- a/module/FacetPrefix/src/FacetPrefix/Search/Search2/ParamsFactory.php +++ b/module/FacetPrefix/src/FacetPrefix/Search/Search2/ParamsFactory.php @@ -61,6 +61,8 @@ public function __invoke(ContainerInterface $container, $requestedName, throw new \Exception('Unexpected options sent to factory.'); } $facetHelper = $container->get('VuFind\Search\Solr\HierarchicalFacetHelper'); - return parent::__invoke($container, $requestedName, [$facetHelper]); + $searchKeysHelper = $container->get('SearchKeys\Search\SearchKeysHelper'); + $searchMemory = $container->get('VuFind\Search\Memory'); + return parent::__invoke($container, $requestedName, [$facetHelper, $searchKeysHelper, $searchMemory]); } } diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Search2/ResultsFactory.php b/module/FacetPrefix/src/FacetPrefix/Search/Search2/ResultsFactory.php new file mode 100644 index 0000000000..ee32622b1a --- /dev/null +++ b/module/FacetPrefix/src/FacetPrefix/Search/Search2/ResultsFactory.php @@ -0,0 +1,67 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace FacetPrefix\Search\Search2; + +use Interop\Container\ContainerInterface; + +/** + * Factory for Search2 search results objects. + * + * @category VuFind + * @package Search_Search2 + * @author Demian Katz + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class ResultsFactory extends \FacetPrefix\Search\Results\ResultsFactory +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + $solr = parent::__invoke($container, $requestedName, $options); + $config = $container->get('VuFind\Config\PluginManager')->get('config'); + $solr->setSpellingProcessor( + new \VuFind\Search\Solr\SpellingProcessor($config->Spelling ?? null) + ); + return $solr; + } +} diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Solr/Params.php b/module/FacetPrefix/src/FacetPrefix/Search/Solr/Params.php index 63f29b39fd..51f607f33e 100644 --- a/module/FacetPrefix/src/FacetPrefix/Search/Solr/Params.php +++ b/module/FacetPrefix/src/FacetPrefix/Search/Solr/Params.php @@ -27,12 +27,17 @@ */ namespace FacetPrefix\Search\Solr; +use Libraries\Libraries; use VuFindSearch\ParamBag; use VuFind\Search\Solr\HierarchicalFacetHelper; -use VuFind\Search\Solr\Params as BaseParams; +use SearchKeys\Search\SearchKeysHelper; + +//use VuFind\Search\Solr\Params as BaseParams; +use Libraries\Search\Solr\Params as BaseParams; class Params extends BaseParams { + /** * Constructor * @@ -40,9 +45,11 @@ class Params extends BaseParams * @param \VuFind\Config\PluginManager $configLoader Config loader */ public function __construct($options, \VuFind\Config\PluginManager $configLoader, - HierarchicalFacetHelper $facetHelper = null + HierarchicalFacetHelper $facetHelper = null, + SearchKeysHelper $searchKeysHelper, + \VuFind\Search\Memory $searchMemory ) { - parent::__construct($options, $configLoader, $facetHelper); + parent::__construct($options, $configLoader, $facetHelper, $searchKeysHelper, $searchMemory); } /** @@ -60,11 +67,13 @@ public function getFacetSettings() $facetSet["f.{$facet}.facet.prefix"] = $prefix; } } - if (isset($facetConfig->FacetMatches)) { + + if (isset($facetConfig->FacetMatches)) { foreach ($facetConfig->FacetMatches as $facet => $matches) { $facetSet["f.{$facet}.facet.matches"] = $matches; } } + return $facetSet; } } diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Solr/ParamsFactory.php b/module/FacetPrefix/src/FacetPrefix/Search/Solr/ParamsFactory.php index 0f39a1c760..5a8ef00f38 100644 --- a/module/FacetPrefix/src/FacetPrefix/Search/Solr/ParamsFactory.php +++ b/module/FacetPrefix/src/FacetPrefix/Search/Solr/ParamsFactory.php @@ -61,6 +61,8 @@ public function __invoke(ContainerInterface $container, $requestedName, throw new \Exception('Unexpected options sent to factory.'); } $facetHelper = $container->get('VuFind\Search\Solr\HierarchicalFacetHelper'); - return parent::__invoke($container, $requestedName, [$facetHelper]); + $searchKeysHelper = $container->get('SearchKeys\Search\SearchKeysHelper'); + $searchMemory = $container->get('VuFind\Search\Memory'); + return parent::__invoke($container, $requestedName, [$facetHelper, $searchKeysHelper, $searchMemory]); } } diff --git a/module/FacetPrefix/src/FacetPrefix/Search/Solr/ResultsFactory.php b/module/FacetPrefix/src/FacetPrefix/Search/Solr/ResultsFactory.php new file mode 100644 index 0000000000..406c52ec65 --- /dev/null +++ b/module/FacetPrefix/src/FacetPrefix/Search/Solr/ResultsFactory.php @@ -0,0 +1,67 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace FacetPrefix\Search\Solr; + +use Interop\Container\ContainerInterface; + +/** + * Factory for Solr search results objects. + * + * @category VuFind + * @package Search_Solr + * @author Demian Katz + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +class ResultsFactory extends \FacetPrefix\Search\Results\ResultsFactory +{ + /** + * Create an object + * + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object + * + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + $solr = parent::__invoke($container, $requestedName, $options); + $config = $container->get('VuFind\Config\PluginManager')->get('config'); + $solr->setSpellingProcessor( + new \VuFind\Search\Solr\SpellingProcessor($config->Spelling ?? null) + ); + return $solr; + } +}