diff --git a/config/vufind/facets.ini b/config/vufind/facets.ini index 1e6faae18222fe81ab8ff87a357762a754eabe15..a25bf67a45c273513d0040ab0fc3c73d4204eb4f 100644 --- a/config/vufind/facets.ini +++ b/config/vufind/facets.ini @@ -70,7 +70,10 @@ dateRange[] = publishDate ; These settings affect the way the [Results] facets are displayed ; If using facets at the top of search results you have more room for text. [Results_Settings] -facet_limit = 30 ; how many values should we show for each facet? +; By default, how many values should we show for each facet? (-1 for no limit) +facet_limit = 30 +; Override facet_limit on a per-field basis using this array: +;facet_limit_by_field[format] = 50 ; Rows and columns for table used by top facets top_rows = 2 top_cols = 3 diff --git a/module/VuFind/src/VuFind/Search/Solr/Params.php b/module/VuFind/src/VuFind/Search/Solr/Params.php index 08bff9dab5c877795adc18653a14fa0b59baeab9..1b27627baec2ace7b4f000b04d457a3bc2cbb117 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Params.php +++ b/module/VuFind/src/VuFind/Search/Solr/Params.php @@ -40,12 +40,19 @@ use VuFindSearch\ParamBag; class Params extends \VuFind\Search\Base\Params { /** - * Facet result limit + * Default facet result limit * * @var int */ protected $facetLimit = 30; + /** + * Per-field facet result limit + * + * @var array + */ + protected $facetLimitByField = []; + /** * Offset for facet results * @@ -97,6 +104,11 @@ class Params extends \VuFind\Search\Base\Params ) { $this->setFacetLimit($config->Results_Settings->facet_limit); } + if (isset($config->Results_Settings->facet_limit_by_field)) { + foreach ($config->Results_Settings->facet_limit_by_field as $k => $v) { + $this->facetLimitByField[$k] = $v; + } + } if (isset($config->Results_Settings->sorted_by_index) && count($config->Results_Settings->sorted_by_index) > 0 ) { @@ -161,6 +173,10 @@ class Params extends \VuFind\Search\Base\Params if (!empty($this->facetConfig)) { $facetSet['limit'] = $this->facetLimit; foreach (array_keys($this->facetConfig) as $facetField) { + if (isset($this->facetLimitByField[$facetField])) { + $facetSet["f.{$facetField}.facet.limit"] + = $this->facetLimitByField[$facetField]; + } if ($this->getFacetOperator($facetField) == 'OR') { $facetField = '{!ex=' . $facetField . '_filter}' . $facetField; } @@ -182,7 +198,9 @@ class Params extends \VuFind\Search\Base\Params $facetSet['sort'] = ($this->facetLimit > 0) ? 'count' : 'index'; } if ($this->indexSortedFacets != null) { - $facetSet['indexSortedFacets'] = $this->indexSortedFacets; + foreach ($this->indexSortedFacets as $field) { + $facetSet["f.{$field}.facet.sort"] = 'index'; + } } } return $facetSet; @@ -476,15 +494,10 @@ class Params extends \VuFind\Search\Base\Params if (!empty($facets)) { $backendParams->add('facet', 'true'); - if (isset($facets['indexSortedFacets'])) { - foreach ($facets['indexSortedFacets'] as $field) { - $backendParams->add("f.{$field}.facet.sort", 'index'); - } - unset($facets['indexSortedFacets']); - } - foreach ($facets as $key => $value) { - $backendParams->add("facet.{$key}", $value); + // prefix keys with "facet" unless they already have a "f." prefix: + $fullKey = substr($key, 0, 2) == 'f.' ? $key : "facet.$key"; + $backendParams->add($fullKey, $value); } $backendParams->add('facet.mincount', 1); }