@@ -, +, @@ occurrences --- C4/Search.pm | 9 +++++++++ Koha/SearchEngine/Elasticsearch/Search.pm | 24 ++++++++++++++---------- catalogue/search.pl | 6 ------ opac/opac-search.pl | 8 -------- 4 files changed, 23 insertions(+), 24 deletions(-) --- a/C4/Search.pm +++ a/C4/Search.pm @@ -625,6 +625,15 @@ sub getRecords { } } ); + + # This sorts the facets into alphabetical order + if (@facets_loop) { + foreach my $f (@facets_loop) { + $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ]; + } + @facets_loop = sort {$a->{expand} cmp $b->{expand}} @facets_loop; + } + return ( undef, $results_hashref, \@facets_loop ); } --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ a/Koha/SearchEngine/Elasticsearch/Search.pm @@ -391,13 +391,14 @@ sub _convert_facets { # These should correspond to the ES field names, as opposed to the CCL # things that zebra uses. + # TODO let the library define the order using the interface. my %type_to_label = ( - author => 'Authors', - location => 'Location', - itype => 'ItemTypes', - se => 'Series', - subject => 'Topics', - 'su-geo' => 'Places', + author => { order => 1, label => 'Authors', }, + itype => { order => 2, label => 'ItemTypes', }, + location => { order => 3, label => 'Location', }, + 'su-geo' => { order => 4, label => 'Places', }, + se => { order => 5, label => 'Series', }, + subject => { order => 6, label => 'Topics', }, ); # We also have some special cases, e.g. itypes that need to show the @@ -409,7 +410,7 @@ sub _convert_facets { itype => { map { $_->itemtype => $_->description } @itypes }, location => { map { $_->authorised_value => ( $opac ? ( $_->lib_opac || $_->lib ) : $_->lib ) } @locations }, ); - my @res; + my @facets; $exp_facet //= ''; while ( ( $type, $data ) = each %$es ) { next if !exists( $type_to_label{$type} ); @@ -421,8 +422,9 @@ sub _convert_facets { expand => $type, expandable => ( $type ne $exp_facet ) && ( @{ $data->{terms} } > $limit ), - "type_label_$type_to_label{$type}" => 1, + "type_label_$type_to_label{$type}{label}" => 1, type_link_value => $type, + order => $type_to_label{$type}{order}, }; $limit = @{ $data->{terms} } if ( $limit > @{ $data->{terms} } ); foreach my $term ( @{ $data->{terms} }[ 0 .. $limit - 1 ] ) { @@ -443,9 +445,11 @@ sub _convert_facets { type_link_value => $type, }; } - push @res, $facet if exists $facet->{facets}; + push @facets, $facet if exists $facet->{facets}; } - return \@res; + + @facets = sort { $a->{order} cmp $b->{order} } @facets; + return \@facets; } --- a/catalogue/search.pl +++ a/catalogue/search.pl @@ -484,12 +484,6 @@ eval { ); }; -# This sorts the facets into alphabetical order -if ($facets) { - foreach my $f (@$facets) { - $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ]; - } -} if ($@ || $error) { $template->param(query_error => $error.$@); output_html_with_http_headers $cgi, $cookie, $template->output; --- a/opac/opac-search.pl +++ a/opac/opac-search.pl @@ -589,14 +589,6 @@ if ($tag) { }; } -# This sorts the facets into alphabetical order -if ($facets && @$facets) { - foreach my $f (@$facets) { - $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ]; - } - @$facets = sort {$a->{expand} cmp $b->{expand}} @$facets; -} - # use Data::Dumper; print STDERR "-" x 25, "\n", Dumper($results_hashref); if ($@ || $error) { $template->param(query_error => $error.$@); --