@@ -, +, @@ --- C4/Search.pm | 5 ++++- Koha/SearchEngine/Elasticsearch/Search.pm | 5 +++++ .../atomicupdate/bug_28826_add_FacetSort_syspref.perl | 9 +++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/searching.pref | 9 +++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_28826_add_FacetSort_syspref.perl --- a/C4/Search.pm +++ a/C4/Search.pm @@ -586,7 +586,10 @@ sub getRecords { # This sorts the facets into alphabetical order if (@facets_loop) { foreach my $f (@facets_loop) { - $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ]; + if( C4::Context->preference('FacetOrder') eq 'Alphabetical' ){ + $f->{facets} = + [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ]; + } } } --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ a/Koha/SearchEngine/Elasticsearch/Search.pm @@ -500,9 +500,14 @@ sub _convert_facets { type_link_value => $type, }; } + if( C4::Context->preference('FacetOrder') eq 'Alphabetical' ){ + @{ $facet->{facets} } = + sort { $a->{facet_label_value} cmp $b->{facet_label_value} } @{ $facet->{facets} }; + } push @facets, $facet if exists $facet->{facets}; } + @facets = sort { $a->{order} <=> $b->{order} } @facets; return \@facets; } --- a/installer/data/mysql/atomicupdate/bug_28826_add_FacetSort_syspref.perl +++ a/installer/data/mysql/atomicupdate/bug_28826_add_FacetSort_syspref.perl @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + INSERT IGNORE INTO systempreferences + ( variable, value, options, explanation, type ) VALUES + ('FacetOrder','Alphabetical','Alphabetical|Usage','Specify the order of facets within each category','Choice') + }); + NewVersion( $DBversion, 28826, "Add system preference FacetOrder"); +} --- a/installer/data/mysql/mandatory/sysprefs.sql +++ a/installer/data/mysql/mandatory/sysprefs.sql @@ -210,6 +210,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ExtendedPatronAttributes','1',NULL,'Use extended patron IDs and attributes','YesNo'), ('FacetLabelTruncationLength','20',NULL,'Specify the facet max length in OPAC','Integer'), ('FacetMaxCount','20',NULL,'Specify the max facet count for each category','Integer'), +('FacetOrder','Alphabetical','Alphabetical|Usage','Specify the order of facets within each category','Choice'), ('FailedLoginAttempts','','','Number of login attempts before lockout the patron account','Integer'), ('FallbackToSMSIfNoEmail', 0, 'Enable|Disable', 'Send messages by SMS if no patron email is defined', 'YesNo'), ('FeeOnChangePatronCategory','1','','If set, when a patron changes to a category with enrolment fee, a fee is charged','YesNo'), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -231,6 +231,15 @@ Searching: class: integer default: 20 - facets for each category. + - + - Sort facets + - pref: FacetOrder + type: choice + choices: + Alphabetical: "alphabetically" + Usage: "by usage count" + default: Alphabetical + - for each category. - - By default, show - pref: OPACnumSearchResults --