View | Details | Raw Unified | Return to bug 12478
Collapse All | Expand All

(-)a/C4/Search.pm (+8 lines)
Lines 643-648 sub GetFacets { Link Here
643
        $facets = _get_facets_from_records( $rs );
643
        $facets = _get_facets_from_records( $rs );
644
    }
644
    }
645
645
646
    # This sorts the facets into alphabetical order
647
    if ($facets && @$facets) {
648
        foreach my $f (@$facets) {
649
            $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ];
650
        }
651
        @$facets = sort {$a->{expand} cmp $b->{expand}} @$facets;
652
    }
653
646
    return $facets;
654
    return $facets;
647
}
655
}
648
656
(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (-11 / +15 lines)
Lines 390-402 sub _convert_facets { Link Here
390
390
391
    # These should correspond to the ES field names, as opposed to the CCL
391
    # These should correspond to the ES field names, as opposed to the CCL
392
    # things that zebra uses.
392
    # things that zebra uses.
393
    # TODO let the library define the order using the interface.
393
    my %type_to_label = (
394
    my %type_to_label = (
394
        author   => 'Authors',
395
        author   => { order => 1, label => 'Authors', },
395
        location => 'Location',
396
        itype    => { order => 2, label => 'ItemTypes', },
396
        itype    => 'ItemTypes',
397
        location => { order => 3, label => 'Location', },
397
        se       => 'Series',
398
        'su-geo' => { order => 4, label => 'Places', },
398
        subject  => 'Topics',
399
        se       => { order => 5, label => 'Series', },
399
        'su-geo' => 'Places',
400
        subject  => { order => 6, label => 'Topics', },
400
    );
401
    );
401
402
402
    # We also have some special cases, e.g. itypes that need to show the
403
    # We also have some special cases, e.g. itypes that need to show the
Lines 408-427 sub _convert_facets { Link Here
408
        itype    => { map { $_->itemtype         => $_->description } @itypes },
409
        itype    => { map { $_->itemtype         => $_->description } @itypes },
409
        location => { map { $_->authorised_value => ( $opac ? ( $_->lib_opac || $_->lib ) : $_->lib ) } @locations },
410
        location => { map { $_->authorised_value => ( $opac ? ( $_->lib_opac || $_->lib ) : $_->lib ) } @locations },
410
    );
411
    );
411
    my @res;
412
    my @facets;
412
    $exp_facet //= '';
413
    $exp_facet //= '';
413
    while ( ( $type, $data ) = each %$es ) {
414
    while ( ( $type, $data ) = each %$es ) {
414
        next if !exists( $type_to_label{$type} );
415
        next if !exists( $type_to_label{$type} );
415
416
416
        # We restrict to the most popular $limit results
417
        # We restrict to the most popular $limit !results
417
        my $limit = ( $type eq $exp_facet ) ? 10 : 5;
418
        my $limit = ( $type eq $exp_facet ) ? 10 : 5;
418
        my $facet = {
419
        my $facet = {
419
            type_id    => $type . '_id',
420
            type_id    => $type . '_id',
420
            expand     => $type,
421
            expand     => $type,
421
            expandable => ( $type ne $exp_facet )
422
            expandable => ( $type ne $exp_facet )
422
              && ( @{ $data->{terms} } > $limit ),
423
              && ( @{ $data->{terms} } > $limit ),
423
            "type_label_$type_to_label{$type}" => 1,
424
            "type_label_$type_to_label{$type}{label}" => 1,
424
            type_link_value                    => $type,
425
            type_link_value                    => $type,
426
            order      => $type_to_label{$type}{order},
425
        };
427
        };
426
        $limit = @{ $data->{terms} } if ( $limit > @{ $data->{terms} } );
428
        $limit = @{ $data->{terms} } if ( $limit > @{ $data->{terms} } );
427
        foreach my $term ( @{ $data->{terms} }[ 0 .. $limit - 1 ] ) {
429
        foreach my $term ( @{ $data->{terms} }[ 0 .. $limit - 1 ] ) {
Lines 442-450 sub _convert_facets { Link Here
442
                type_link_value => $type,
444
                type_link_value => $type,
443
            };
445
            };
444
        }
446
        }
445
        push @res, $facet if exists $facet->{facets};
447
        push @facets, $facet if exists $facet->{facets};
446
    }
448
    }
447
    return \@res;
449
450
    @facets = sort { $a->{order} cmp $b->{order} } @facets;
451
    return \@facets;
448
}
452
}
449
453
450
454
(-)a/catalogue/search.pl (-6 lines)
Lines 484-495 eval { Link Here
484
    );
484
    );
485
};
485
};
486
486
487
# This sorts the facets into alphabetical order
488
if ($facets) {
489
    foreach my $f (@$facets) {
490
        $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ];
491
    }
492
}
493
if ($@ || $error) {
487
if ($@ || $error) {
494
    $template->param(query_error => $error.$@);
488
    $template->param(query_error => $error.$@);
495
    output_html_with_http_headers $cgi, $cookie, $template->output;
489
    output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/opac/opac-search.pl (-9 lines)
Lines 589-602 if ($tag) { Link Here
589
    };
589
    };
590
}
590
}
591
591
592
# This sorts the facets into alphabetical order
593
if ($facets && @$facets) {
594
    foreach my $f (@$facets) {
595
        $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ];
596
    }
597
    @$facets = sort {$a->{expand} cmp $b->{expand}} @$facets;
598
}
599
600
# use Data::Dumper; print STDERR "-" x 25, "\n", Dumper($results_hashref);
592
# use Data::Dumper; print STDERR "-" x 25, "\n", Dumper($results_hashref);
601
if ($@ || $error) {
593
if ($@ || $error) {
602
    $template->param(query_error => $error.$@);
594
    $template->param(query_error => $error.$@);
603
- 

Return to bug 12478