From 08abd4c2f1eb5a171504f5c3f123451ab2a6faff Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Tue, 12 Nov 2019 17:15:14 +0100 Subject: [PATCH] Bug 23204: (follow-up) also sort by marc field Test plan : Launching script several times and see that marc field is alway ordered increasing Signed-off-by: Bernardo Gonzalez Kriegel Same order between runs Signed-off-by: Jonathan Druart --- Koha/SearchEngine/Elasticsearch.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 850a4373d1..ce762a00ce 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -263,10 +263,17 @@ sub raw_elasticsearch_mappings { my $mappings = {}; while ( my $search_field = $search_fields->next ) { - my $marc_to_fields = $schema->resultset('SearchMarcToField')->search( { search_field_id => $search_field->id } ); + my $marc_to_fields = $schema->resultset('SearchMarcToField')->search( + { search_field_id => $search_field->id }, + { + join => 'search_marc_map', + order_by => { -asc => 'search_marc_map.marc_field' } + } + ); while ( my $marc_to_field = $marc_to_fields->next ) { - my $marc_map = Koha::SearchMarcMaps->find( $marc_to_field->search_marc_map_id ); + + my $marc_map = $marc_to_field->search_marc_map; next if $marc_type && $marc_map->marc_type ne $marc_type; -- 2.20.1