Bugzilla – Attachment 168488 Details for
Bug 36947
Sort Elasticsearch facets according to system 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: Do a locale-based sort for ES facet names
Bug-36947-Do-a-locale-based-sort-for-ES-facet-name.patch (text/plain), 2.82 KB, created by
Martin Renvoize (ashimema)
on 2024-07-04 08:22:30 UTC
(
hide
)
Description:
Bug 36947: Do a locale-based sort for ES facet names
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-07-04 08:22:30 UTC
Size:
2.82 KB
patch
obsolete
>From 805e0865aed7f6116ad8bc8a19f50e96f247a960 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Mon, 27 May 2024 23:37:01 +0000 >Subject: [PATCH] Bug 36947: Do a locale-based sort for ES facet names >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This change uses a configurable locale-based collator to sort >the ES facet names. > >Test plan: >0. Apply the patch >1. vi "/etc/default/koha-common" >2. Add the following to the bottom of the file: >export LC_ALL=fi_FI.UTF-8 >3. koha-plack --restart koha-common >4. Setup some test records with authors with accented and unaccented names, > and different cases for the lead letter >e.g. Aa author, Ãa author2, aa author3, étienne >5. Switch to using Elasticsearch and reindex >koha-elasticsearch -b -v --rebuild kohadev >6. Do a test search > e.g. http://localhost:8081/cgi-bin/koha/catalogue/search.pl?q=test >7. Confirm the facet names are sorted in ascending order following >Finnish collation rules > e.g. >Aa author >aa author3 >étienne >Farley, David >Humble, Jez >Martin, Robert C. >Ãa author > >NOTE: Any collation and language can be used. Finnish is just >an example of a Latin-based script which has a different >alphabetical ordering than just A-Z > >Signed-off-by: Lari Strand <lari.strand@koha-suomi.fi> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/SearchEngine/Elasticsearch/Search.pm | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm >index f4a316345ad..1d4d8867b26 100644 >--- a/Koha/SearchEngine/Elasticsearch/Search.pm >+++ b/Koha/SearchEngine/Elasticsearch/Search.pm >@@ -54,6 +54,9 @@ use MARC::File::XML; > use MIME::Base64 qw( decode_base64 ); > use JSON; > >+use POSIX qw(setlocale LC_COLLATE); >+use Unicode::Collate::Locale; >+ > Koha::SearchEngine::Elasticsearch::Search->mk_accessors(qw( store )); > > =head2 search >@@ -504,8 +507,17 @@ sub _convert_facets { > }; > } > if( C4::Context->preference('FacetOrder') eq 'Alphabetical' ){ >- @{ $facet->{facets} } = >- sort { $a->{facet_label_value} cmp $b->{facet_label_value} } @{ $facet->{facets} }; >+ #Fetch locale as understood by Perl >+ #NOTE: Technically, we can define locale however we like, but this >+ #is a good default >+ my $locale = setlocale(LC_COLLATE); >+ >+ #Create locale-based collator >+ my $collator = Unicode::Collate::Locale->new( locale => $locale ); >+ if ($collator) { >+ @{ $facet->{facets} } = >+ sort { $collator->cmp( $a->{facet_label_value}, $b->{facet_label_value} ) } @{ $facet->{facets} }; >+ } > } > push @facets, $facet if exists $facet->{facets}; > } >-- >2.45.2
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