Skip to content
Snippets Groups Projects
Commit 89e9a492 authored by Samuli Sillanpää's avatar Samuli Sillanpää Committed by Robert Lange
Browse files

Add support for configuring available sort options for facets (#1452)

parent 15471a34
No related merge requests found
......@@ -107,6 +107,22 @@ dateRange[] = publishDate
[CheckboxFacets]
;edition:1st* = "First Edition" ; Contrived hypothetical example
; Available sort options when listing all facets from Sidefacets.
;
; Each configuration option targets a search class and a facet field.
; All facet fields for a search class can be targeted using the wildcard '*'.
; Sort options are given as a comma-separated list of "<sort-field>=<label>" entries,
; where <sort-field> is either 'count' or 'index' and <label> the translation
; key for the option.
[AvailableFacetSortOptions]
; By default all Solr facets can be sorted by count and alphabetically.
; Example: sort Solr author_facet by count only.
; Solr[author_facet] = "count=sort_count"
; Example: sort Solr author_facet only alphabetically
; Solr[author_facet] = "index=sort_alphabetic"
; 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]
......
......@@ -718,7 +718,7 @@ class AbstractSearch extends AbstractBase
$facet = $this->params()->fromQuery('facet');
$page = (int)$this->params()->fromQuery('facetpage', 1);
$options = $results->getOptions();
$facetSortOptions = $options->getFacetSortOptions();
$facetSortOptions = $options->getFacetSortOptions($facet);
$sort = $this->params()->fromQuery('facetsort', null);
if ($sort === null || !in_array($sort, array_keys($facetSortOptions))) {
$sort = empty($facetSortOptions)
......
......@@ -292,6 +292,20 @@ abstract class Options implements TranslatorAwareInterface
{
$this->limitOptions = [$this->defaultLimit];
$this->setConfigLoader($configLoader);
$id = $this->getSearchClassId();
$facetSettings = $configLoader->get($this->facetsIni);
if (isset($facetSettings->AvailableFacetSortOptions[$id])) {
foreach ($facetSettings->AvailableFacetSortOptions[$id]->toArray()
as $facet => $sortOptions
) {
$this->facetSortOptions[$facet] = [];
foreach (explode(',', $sortOptions) as $fieldAndLabel) {
list($field, $label) = explode('=', $fieldAndLabel);
$this->facetSortOptions[$facet][$field] = $label;
}
}
}
}
/**
......@@ -473,13 +487,15 @@ abstract class Options implements TranslatorAwareInterface
}
/**
* Get an array of sort options for facets.
* Get an array of sort options for a facet.
*
* @param string $facet Facet
*
* @return array
*/
public function getFacetSortOptions()
public function getFacetSortOptions($facet = '*')
{
return $this->facetSortOptions;
return $this->facetSortOptions[$facet] ?? $this->facetSortOptions['*'] ?? [];
}
/**
......
......@@ -46,8 +46,7 @@ class Options extends \VuFind\Search\Base\Options
* @var array
*/
protected $facetSortOptions = [
'count' => 'sort_count',
'index' => 'sort_alphabetic'
'*' => ['count' => 'sort_count', 'index' => 'sort_alphabetic']
];
/**
......
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