Revert "Bug 12478: Display facet terms ordered by number of occurrences"
authorRobin Sheat <robin@catalyst.net.nz>
Tue, 13 Oct 2015 04:21:36 +0000 (17:21 +1300)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Tue, 26 Apr 2016 20:20:12 +0000 (20:20 +0000)
This reverts commit cd4905c2969b067476881016d0b03271f0bcc7c8.

This commit caused an error in C4::Search::GetFacets when running in
zebra mode.

Conflicts:
Koha/SearchEngine/Elasticsearch/Search.pm

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
C4/Search.pm
Koha/SearchEngine/Elasticsearch/Search.pm
catalogue/search.pl
opac/opac-search.pl

index 7dd7c2c..1e51427 100644 (file)
@@ -641,14 +641,6 @@ sub GetFacets {
         $facets = _get_facets_from_records( $rs );
     }
 
-    # 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;
-    }
-
     return $facets;
 }
 
index 0950139..3c3bf3b 100644 (file)
@@ -391,14 +391,13 @@ 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   => { 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', },
+        author   => 'Authors',
+        location => 'Location',
+        itype    => 'ItemTypes',
+        se       => 'Series',
+        subject  => 'Topics',
+        'su-geo' => 'Places',
     );
 
     # We also have some special cases, e.g. itypes that need to show the
@@ -410,7 +409,7 @@ sub _convert_facets {
         itype    => { map { $_->itemtype         => $_->description } @itypes },
         location => { map { $_->authorised_value => ( $opac ? ( $_->lib_opac || $_->lib ) : $_->lib ) } @locations },
     );
-    my @facets;
+    my @res;
     $exp_facet //= '';
     while ( ( $type, $data ) = each %$es ) {
         next if !exists( $type_to_label{$type} );
@@ -422,9 +421,8 @@ sub _convert_facets {
             expand     => $type,
             expandable => ( $type ne $exp_facet )
               && ( @{ $data->{terms} } > $limit ),
-            "type_label_$type_to_label{$type}{label}" => 1,
+            "type_label_$type_to_label{$type}" => 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 ] ) {
@@ -445,11 +443,9 @@ sub _convert_facets {
                 type_link_value => $type,
             };
         }
-        push @facets, $facet if exists $facet->{facets};
+        push @res, $facet if exists $facet->{facets};
     }
-
-    @facets = sort { $a->{order} cmp $b->{order} } @facets;
-    return \@facets;
+    return \@res;
 }
 
 
index 653ce4c..06e2b1f 100755 (executable)
@@ -531,6 +531,12 @@ 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;
index f68fb9f..221ecea 100755 (executable)
@@ -620,6 +620,14 @@ 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.$@);