diff --git a/C4/Search.pm b/C4/Search.pm index 5d6f3c6e33..df3a0ab592 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -593,6 +593,9 @@ sub getRecords { $f->{facets} = $sorted_facets; } } + if ( C4::Context->preference('FacetOrder') eq 'Stringwise' ) { + @{ $f->{facets} } = sort { $a->{facet_label_value} cmp $b->{facet_label_value} } @{ $f->{facets} }; + } } } diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index b0356ec8a5..ccf502c96c 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -575,6 +575,8 @@ sub _convert_facets { if ($sorted_facets) { $facet->{facets} = $sorted_facets; } + } elsif ( C4::Context->preference('FacetOrder') eq 'Stringwise' ) { + @{ $facet->{facets} } = sort { $a->{facet_label_value} cmp $b->{facet_label_value} } @{ $facet->{facets} }; } push @facets, $facet if exists $facet->{facets}; } diff --git a/installer/data/mysql/atomicupdate/bug_41287.pl b/installer/data/mysql/atomicupdate/bug_41287.pl new file mode 100755 index 0000000000..a3e4b61a6b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_41287.pl @@ -0,0 +1,29 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "41287", + description => "Add option for stringwise sorting of facets", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + # Do you stuffs here + $dbh->do( + q{ + INSERT IGNORE INTO systempreferences + ( variable, value, options, explanation, type ) VALUES + ('FacetOrder','Alphabetical','Alphabetical|Usage|Stringwise','Specify the order of facets within each category','Choice') + } + ); + $dbh->do( + q{ + UPDATE systempreferences + SET options = 'Alphabetical|Usage|Stringwise' + WHERE variable = 'FacetOrder' + } + ); + + say $out "Added new 'Stringwise' option to system preference 'FacetOrder'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 35a5d15dd8..734150ba93 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -281,7 +281,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'), +('FacetOrder','Alphabetical','Alphabetical|Usage|Stringwise','Specify the order of facets within each category','Choice'), ('FacetSortingLocale','default','','Choose the locale for sorting facet names when FacetOrder is set to Alphabetical. This enables proper Unicode-aware sorting of accented characters and locale-specific alphabetical ordering.','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'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref index 6c7e8d0e78..a8498f8ff4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -301,10 +301,11 @@ Searching: - pref: FacetOrder type: choice choices: - Alphabetical: "alphabetically" + Alphabetical: "alphabetically using locale" Usage: "by usage count" + Stringwise: "simple alphabetical" default: Alphabetical - - for each category. + - for each category. Locale can be set using the FacetSortingLocale preference. - - By default, show - pref: OPACnumSearchResults