Bugzilla – Attachment 183726 Details for
Bug 36947
Sort Elasticsearch/Zebra facets according to configurable locale instead of using Perl's stringwise/bytewise sort
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36947: Use ncmp
Bug-36947-Use-ncmp.patch (text/plain), 3.51 KB, created by
Jonathan Druart
on 2025-07-03 09:17:40 UTC
(
hide
)
Description:
Bug 36947: Use ncmp
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-07-03 09:17:40 UTC
Size:
3.51 KB
patch
obsolete
>From e27e2cb7da9fd9e53e786d4810461f97b7ec3242 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 3 Jul 2025 11:15:43 +0200 >Subject: [PATCH] Bug 36947: Use ncmp > >--- > C4/Search.pm | 20 ++++---------------- > Koha/SearchEngine/Elasticsearch/Search.pm | 21 +++------------------ > 2 files changed, 7 insertions(+), 34 deletions(-) > >diff --git a/C4/Search.pm b/C4/Search.pm >index bf0a485286f..41df0ec9161 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -16,6 +16,7 @@ package C4::Search; > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >+use feature qw(fc); > use C4::Context; > use C4::Biblio qw( TransformMarcToKoha GetMarcFromKohaField GetFrameworkCode GetAuthorisedValueDesc GetBiblioData ); > use C4::Koha >@@ -40,8 +41,7 @@ use URI::Escape; > use Business::ISBN; > use MARC::Record; > use MARC::Field; >-use POSIX qw(setlocale LC_COLLATE); >-use Unicode::Collate::Locale; >+use Sort::Naturally qw(ncmp); > > our ( @ISA, @EXPORT_OK ); > >@@ -304,20 +304,8 @@ Sorts facets using a configurable locale for Zebra search engine. > sub _sort_facets_zebra { > my ( $facets, $locale ) = @_; > >- if ( !$locale ) { >- >- # Get locale from system preference, falling back to system LC_COLLATE >- $locale = C4::Context->preference('FacetSortingLocale') || 'default'; >- if ( $locale eq 'default' || !$locale ) { >- >- #NOTE: When setlocale is run with only the 1st parameter, it is a "get" not a "set" function. >- $locale = setlocale(LC_COLLATE) || 'default'; >- } >- } >- >- my $collator = Unicode::Collate::Locale->new( locale => $locale ); >- if ( $collator && $facets ) { >- my @sorted_facets = sort { $collator->cmp( $a->{facet_label_value}, $b->{facet_label_value} ) } @{$facets}; >+ if ($facets) { >+ my @sorted_facets = sort { ncmp( $a->{facet_label_value}, $b->{facet_label_value} ) } @$facets; > if (@sorted_facets) { > return \@sorted_facets; > } >diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm >index f9383c379fb..6e543ab3879 100644 >--- a/Koha/SearchEngine/Elasticsearch/Search.pm >+++ b/Koha/SearchEngine/Elasticsearch/Search.pm >@@ -53,9 +53,7 @@ use MARC::Record; > use MARC::File::XML; > use MIME::Base64 qw( decode_base64 ); > use JSON; >- >-use POSIX qw(setlocale LC_COLLATE); >-use Unicode::Collate::Locale; >+use Sort::Naturally qw(ncmp); > > Koha::SearchEngine::Elasticsearch::Search->mk_accessors(qw( store )); > >@@ -467,22 +465,9 @@ Sorts facets using a locale. > sub _sort_facets { > my ( $self, $args ) = @_; > my $facets = $args->{facets}; >- my $locale = $args->{locale}; >- >- if ( !$locale ) { >- >- # Get locale from system preference, falling back to system LC_COLLATE >- $locale = C4::Context->preference('FacetSortingLocale') || 'default'; >- if ( $locale eq 'default' || !$locale ) { >- >- #NOTE: When setlocale is run with only the 1st parameter, it is a "get" not a "set" function. >- $locale = setlocale(LC_COLLATE) || 'default'; >- } >- } > >- my $collator = Unicode::Collate::Locale->new( locale => $locale ); >- if ( $collator && $facets ) { >- my @sorted_facets = sort { $collator->cmp( $a->{facet_label_value}, $b->{facet_label_value} ) } @{$facets}; >+ if ($facets) { >+ my @sorted_facets = sort { ncmp( $a->{facet_label_value}, $b->{facet_label_value} ) } @$facets; > if (@sorted_facets) { > return \@sorted_facets; > } >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36947
:
167110
|
167125
|
167141
|
167142
|
167143
|
167145
|
167146
|
167188
|
167198
|
167880
|
168488
|
170489
|
183551
|
183552
|
183553
|
183563
|
183564
|
183565
|
183566
|
183567
|
183568
|
183726
|
183727