diff --git a/config/vufind/facets.ini b/config/vufind/facets.ini index 589b9019ce3cf26f68a2872715f1135c0765f29a..2a9a800066e9f79ec7ab32188bc9f94d0ff9f7fa 100644 --- a/config/vufind/facets.ini +++ b/config/vufind/facets.ini @@ -256,6 +256,18 @@ translated_facets[] = callnumber-first:CallNumberFirst ; These facets will be displayed on the Home Page when FacetList is turned on in ; the content setting of the [HomePage] section of searches.ini. If this section ; is omitted, the [Advanced] section will be used instead. + +; Override the alphabetical sorting for individual facets and display them at the +; top of the limits on the advanced search page. As an example, this could be used +; to display the most commonly searched languages above the rest. All following +; limits display in the natural sorted order. +;limitOrderOverride[language] = Icelandic::English::Spanish +;limitOrderOverride[format] = CD::DVD + +; Optional delimiter to use in the limitOrderOverride settings above. When enabled, +; limits must be separated using the same character set here. +;limitDelimiter = "::" + [HomePage] callnumber-first = "Call Number" language = Language diff --git a/module/VuFind/src/VuFind/Search/Base/Options.php b/module/VuFind/src/VuFind/Search/Base/Options.php index 614df29e7f02c5fdfcbf3880d843e916bc9cb48c..50ee1f249190f5dacdcae4f054483aa7d9b2d517 100644 --- a/module/VuFind/src/VuFind/Search/Base/Options.php +++ b/module/VuFind/src/VuFind/Search/Base/Options.php @@ -982,4 +982,21 @@ abstract class Options implements TranslatorAwareInterface $this->autocompleteAutoSubmit = $searchSettings->Autocomplete->auto_submit ?? $this->autocompleteAutoSubmit; } + + /** + * Get advanced search limits that override the natural sorting to + * display at the top. + * + * @param string $limit advanced search limit + * + * @return array + */ + public function limitOrderOverride($limit) + { + $facetSettings = $this->configLoader->get($this->getFacetsIni()); + $limits = $facetSettings->Advanced_Settings->limitOrderOverride ?? null; + $delimiter = $facetSettings->Advanced_Settings->limitDelimiter ?? '::'; + $limitConf = $limits ? $limits->get($limit) : ''; + return array_map('trim', explode($delimiter, $limitConf)); + } } diff --git a/themes/bootstrap3/templates/search/advanced/solr.phtml b/themes/bootstrap3/templates/search/advanced/solr.phtml index a305515e0f22e130760ee1154269db8ef7605e2c..a53fa31f4884dff614c1f15f19345f2a993a418d 100644 --- a/themes/bootstrap3/templates/search/advanced/solr.phtml +++ b/themes/bootstrap3/templates/search/advanced/solr.phtml @@ -16,16 +16,34 @@ <?php endforeach; ?> <?php else: ?> <?php - // Sort the current facet list alphabetically; we'll use this data + // Sort the current facet list alphabetically and filter items to + // the top if they appear in the config; we'll use this data // along with the foreach below to display facet options in the // correct order. + $conf = $this->options->limitOrderOverride($field); $sorted = []; + $filtered = []; foreach ($list['list'] as $i => $value) { if (!empty($value['displayText'])) { - $sorted[$i] = $value['displayText']; + if (in_array($value['displayText'], $conf)) { + $filtered[$i] = $value['displayText']; + } else { + $sorted[$i] = $value['displayText']; + } } } natcasesort($sorted); + + // Order filtered items according to how they appear in the config. + $filterKeys = array_flip($conf); + uasort($filtered, function ($a, $b) use ($filterKeys) { + return $filterKeys[$a] <=> $filterKeys[$b]; + }); + + // Combine filtered and sorted arrays so that the items in the config + // appear in order at the top and all other items appear afterwards + // sorted by natcasesort. + $sorted = $filtered + $sorted; ?> <?php foreach ($sorted as $i => $display): ?> <?php $value = $list['list'][$i]; ?>