Skip to content

Commit

Permalink
sort favs for collapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
ranguard committed May 13, 2017
1 parent 39f09b1 commit cd4b416
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/MetaCPAN/Model/Search.pm
Expand Up @@ -387,24 +387,24 @@ sub _build_search_favorites_query {
sub search_favorites {
my ( $self, $distributions ) = @_;

my $favorites = {};
my %favorites = ();

# If there are no distributions this will build a query with an empty
# filter and ES will return a parser error... so just skip it.
return $favorites unless @{$distributions};
return \%favorites unless @{$distributions};

my $es_query = $self->_build_search_favorites_query($distributions);
my $es_results = $self->run_query( favorite => $es_query );

if ( $es_results->{hits}->{total} ) {

# only proceed when we have results
$favorites
%favorites
= map { $_->{key} => $_->{doc_count} }
@{ $es_results->{aggregations}->{favorites}->{buckets} };
}

return $favorites;
return \%favorites;
}

sub _extract_results {
Expand Down Expand Up @@ -452,8 +452,8 @@ sub _add_descriptions_and_faves_to_collapsed_results {
my $descriptions = $self->search_descriptions( \@ids );

map {
$_->[0]->{description} = $descriptions->{results}->{ $_->{id} };
$_->[0]->{favorites} = $favorites->{ $_->{distribution} };
$_->[0]->{description} = $descriptions->{results}->{ $_->[0]->{id} };
$_->[0]->{favorites} = $favorites->{ $_->[0]->{distribution} };
} @{$results};

return $results;
Expand Down

0 comments on commit cd4b416

Please sign in to comment.