From 1ff3fc6bbe3cd867662925a840db9ce13a397456 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Mon, 24 Feb 2020 15:47:31 +0100 Subject: [PATCH] Bug 24720: Strip special chars from search fields Strip all non alphanumerical characters from beginning of search field values so that sorting is performed on the first alphanumeric character and not special characters like "-" or "[". To test: 1. Prepend "[" to the title of a biblio and save 2. Perform a search that matches this biblio and at least one more biblio. 3. Sort alphabetically a-z. 4. The biblio with "[" should appear first 5. Apply the patch 6. Perform a full reindexing 7. Perform steps 2-3 again 8. The result should now be alphabetically sorted, ignoring the initial bracket in the title. --- Koha/SearchEngine/Elasticsearch.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 7322f84178..09422eb29b 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -554,6 +554,8 @@ sub marc_records_to_documents { if ($field =~ /__sort$/) { # Make sure to keep the sort field length sensible. 255 was chosen as a nice round value. $record_document->{$field} = [substr(join(' ', @{$record_document->{$field}}), 0, 255)]; + # Strip any initial non-word characters which don't make much sense to sort on + $record_document->{$field} = [map { s/^\W+//u; $_ } @{$record_document->{$field}}]; } } } -- 2.25.0