Skip to content
Snippets Groups Projects
Commit 437f017d authored by Frank Morgner's avatar Frank Morgner Committed by Demian Katz
Browse files

add sorting (by index) for single facets

parent e6e67da3
No related merge requests found
......@@ -85,6 +85,14 @@ top_cols = 3
; Do we want any facets to be collapsed by default?
;collapsedFacets = *
; This can be used to sort specific facet fields alphabetically by index value
; (which normally results in alphabetical order).
; Please note: This sorts natively in the Solr index using untranslated values,
; so if you are using facet translation, your values may not always display in
; the expected order.
;sorted_by_index[] = building;
;sorted_by_index[] = institution;
; The author home screen has different facets
[Author]
topic_facet = "Related Subjects"
......@@ -161,4 +169,4 @@ visual_facets = "callnumber-first,topic_facet"
; If you rename a facet field, you can map the old value to a new value in this
; section to ensure that legacy URLs continue to function.
[LegacyFields]
\ No newline at end of file
[LegacyFields]
......@@ -67,6 +67,13 @@ class Params extends \VuFind\Search\Base\Params
*/
protected $facetSort = null;
/**
* Sorting order of single facet by index
*
* @var array
*/
protected $facetSortedByIndex = null;
/**
* Fields for visual faceting
*
......@@ -83,7 +90,6 @@ class Params extends \VuFind\Search\Base\Params
public function __construct($options, \VuFind\Config\PluginManager $configLoader)
{
parent::__construct($options, $configLoader);
// Use basic facet limit by default, if set:
$config = $configLoader->get('facets');
if (isset($config->Results_Settings->facet_limit)
......@@ -91,6 +97,13 @@ class Params extends \VuFind\Search\Base\Params
) {
$this->setFacetLimit($config->Results_Settings->facet_limit);
}
if (isset($config->Results_Settings->sorted_by_index)
&& count($config->Results_Settings->sorted_by_index) > 0
) {
$this->setIndexSortedFacets(
$config->Results_Settings->sorted_by_index->toArray()
);
}
}
/**
......@@ -144,6 +157,7 @@ class Params extends \VuFind\Search\Base\Params
{
// Build a list of facets we want from the index
$facetSet = [];
if (!empty($this->facetConfig)) {
$facetSet['limit'] = $this->facetLimit;
foreach (array_keys($this->facetConfig) as $facetField) {
......@@ -167,6 +181,9 @@ class Params extends \VuFind\Search\Base\Params
// so making this explicit ensures consistent behavior.
$facetSet['sort'] = ($this->facetLimit > 0) ? 'count' : 'index';
}
if ($this->indexSortedFacets != null) {
$facetSet['indexSortedFacets'] = $this->indexSortedFacets;
}
}
return $facetSet;
}
......@@ -239,6 +256,18 @@ class Params extends \VuFind\Search\Base\Params
$this->facetSort = $s;
}
/**
* Set Index Facet Sorting
*
* @param array $s the facets sorted by index
*
* @return void
*/
public function setIndexSortedFacets(array $s)
{
$this->indexSortedFacets = $s;
}
/**
* Initialize facet settings for the specified configuration sections.
*
......@@ -446,8 +475,16 @@ class Params extends \VuFind\Search\Base\Params
$facets = $this->getFacetSettings();
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);
$backendParams->add("facet.{$key}", $value);
}
$backendParams->add('facet.mincount', 1);
}
......
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