From 65d4b162a6644963bc6318ff48aade7e0c8b7b03 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 3 Oct 2012 12:23:02 -0400 Subject: [PATCH] Resolving VUFIND-348 (Configurable Homepage facets). --- config/vufind/facets.ini | 18 ++++++- .../VuFind/Controller/SearchController.php | 40 ++++++++++++--- .../VuFind/src/VuFind/Search/Solr/Params.php | 50 +++++++++++++++---- 3 files changed, 88 insertions(+), 20 deletions(-) diff --git a/config/vufind/facets.ini b/config/vufind/facets.ini index c0ecf997cca..46e1dbd6e79 100644 --- a/config/vufind/facets.ini +++ b/config/vufind/facets.ini @@ -58,7 +58,8 @@ callnumber-first = "Call Number" language = Language format = Format -; These settings affect the way the [Advanced] facets are displayed +; Most of these settings affect the way the [Advanced] facets are displayed; the +; translated_facets setting affects facets globally. [Advanced_Settings] facet_limit = 100 ; how many values should we show for each facet? @@ -78,4 +79,17 @@ special_facets = "illustrated,daterange" ; translated -- uncomment or add lines below to turn on this feature. ;translated_facets[] = institution ;translated_facets[] = building -translated_facets[] = format \ No newline at end of file +;translated_facets[] = format + +; These facets will be displayed on the Home Page. If this section is omitted, +; the [Advanced] section will be used instead. +[HomePage] +callnumber-first = "Call Number" +language = Language +format = Format + +; These settings affect the way the [HomePage] facets are displayed +[HomePage_Settings] +; how many values should we load for each facet? depending on the column layout +; of the homepage facet lists, we may not display all loaded values for every facet +facet_limit = 20 diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php index 2245f04c87e..8164eae37b7 100644 --- a/module/VuFind/src/VuFind/Controller/SearchController.php +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -278,7 +278,7 @@ class SearchController extends AbstractSearch public function homeAction() { return $this->createViewModel( - array('results' => $this->getAdvancedFacets()) + array('results' => $this->getHomePageFacets()) ); } @@ -489,24 +489,26 @@ class SearchController extends AbstractSearch } /** - * Return a Search Results object containing advanced facet information. This - * data may come from the cache, and it is currently shared between the Home - * page and the Advanced search screen. + * Return a Search Results object containing requested facet information. This + * data may come from the cache. + * + * @param string $initMethod Name of params method to use to request facets + * @param string $cacheName Cache key for facet data * * @return \VuFind\Search\Solr\Results */ - protected function getAdvancedFacets() + protected function getFacetResults($initMethod, $cacheName) { // Check if we have facet results cached, and build them if we don't. $cache = $this->getServiceLocator()->get('CacheManager')->getCache('object'); - if (!($results = $cache->getItem('solrSearchHomeFacets'))) { + if (!($results = $cache->getItem($cacheName))) { // Use advanced facet settings to get summary facets on the front page; // we may want to make this more flexible later. Also keep in mind that // the template is currently looking for certain hard-coded fields; this // should also be made smarter. $sm = $this->getSearchManager(); $params = $sm->setSearchClassId('Solr')->getParams(); - $params->initAdvancedFacets(); + $params->$initMethod(); // We only care about facet lists, so don't get any results (this helps // prevent problems with serialized File_MARC objects in the cache): @@ -518,7 +520,7 @@ class SearchController extends AbstractSearch // Temporarily remove the service manager so we can cache the // results (otherwise we'll get errors about serializing closures): $results->unsetServiceLocator(); - $cache->setItem('solrSearchHomeFacets', $results); + $cache->setItem($cacheName, $results); } // Restore the real service locator to the object: @@ -526,6 +528,28 @@ class SearchController extends AbstractSearch return $results; } + /** + * Return a Search Results object containing advanced facet information. This + * data may come from the cache. + * + * @return \VuFind\Search\Solr\Results + */ + protected function getAdvancedFacets() + { + return $this->getFacetResults('initAdvancedFacets', 'solrSearchAdvancedFacets'); + } + + /** + * Return a Search Results object containing homepage facet information. This + * data may come from the cache. + * + * @return \VuFind\Search\Solr\Results + */ + protected function getHomePageFacets() + { + return $this->getFacetResults('initHomePageFacets', 'solrSearchHomeFacets'); + } + /** * Handle OpenSearch. * diff --git a/module/VuFind/src/VuFind/Search/Solr/Params.php b/module/VuFind/src/VuFind/Search/Solr/Params.php index 03be2c5ad3d..5f67b91e914 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Params.php +++ b/module/VuFind/src/VuFind/Search/Solr/Params.php @@ -252,22 +252,50 @@ class Params extends BaseParams } /** - * Initialize facet settings for the advanced search screen. + * Initialize facet settings for the specified configuration sections. * - * @return void + * @param $facetList Config section containing fields to activate + * @param $facetSettings Config section containing related settings + * + * @return bool True if facets set, false if no settings found */ - public function initAdvancedFacets() + protected function initFacetList($facetList, $facetSettings) { $config = ConfigReader::getConfig('facets'); - if (isset($config->Advanced)) { - foreach ($config->Advanced as $key => $value) { - $this->addFacet($key, $value); - } + if (!isset($config->$facetList)) { + return false; + } + foreach ($config->$facetList as $key => $value) { + $this->addFacet($key, $value); } - if (isset($config->Advanced_Settings->facet_limit) - && is_numeric($config->Advanced_Settings->facet_limit) + if (isset($config->$facetSettings->facet_limit) + && is_numeric($config->$facetSettings->facet_limit) ) { - $this->setFacetLimit($config->Advanced_Settings->facet_limit); + $this->setFacetLimit($config->$facetSettings->facet_limit); + } + return true; + } + + /** + * Initialize facet settings for the advanced search screen. + * + * @return void + */ + public function initAdvancedFacets() + { + $this->initFacetList('Advanced', 'Advanced_Settings'); + } + + /** + * Initialize facet settings for the home page. + * + * @return void + */ + public function initHomePageFacets() + { + // Load Advanced settings if HomePage settings are missing (legacy support): + if (!$this->initFacetList('HomePage', 'HomePage_Settings')) { + $this->initAdvancedFacets(); } } @@ -346,9 +374,11 @@ class Params extends BaseParams // Based on preference, change the order of initialization to make sure // that preferred facet labels come in last. if ($preferredSection == 'Advanced') { + $this->initHomePageFacets(); $this->initBasicFacets(); $this->initAdvancedFacets(); } else { + $this->initHomePageFacets(); $this->initAdvancedFacets(); $this->initBasicFacets(); } -- GitLab