Bug 41287: Add option to use simple Stringwise sorting for facets

This patch restores the previous perl sorting to restore speed. For English language libraries
this will be correct in most instances, and is much more performant.

To test:
1 - Apply patch, update database
2 - Perform some searches, note ordering of facets
3 - Update system preference 'FacetOrder' to 'simple alphabetical'
4 - Peform some searches, note ordering of facets, should be correct unless you have unicode characters
5 - Sign off

NOTE: Benchmarks attached as a comment, you can also enable NYTProf and view results for yourself:
https://wiki.koha-community.org/wiki/Profiling_with_Devel::NYTProf#NYTProf_with_Plack
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2025-12-12 13:18:35 +00:00 committed by Lucas Gass
parent 6d491b2d95
commit 66825efa06
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
5 changed files with 38 additions and 3 deletions

View File

@ -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} };
}
}
}

View File

@ -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};
}

View File

@ -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'";
},
};

View File

@ -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'),

View File

@ -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 <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=FacetSortingLocale">FacetSortingLocale</a> preference.
-
- By default, show
- pref: OPACnumSearchResults