Skip to content

Commit

Permalink
Merge pull request #1804 from metacpan/tsibley/module-search-duplication
Browse files Browse the repository at this point in the history
Fix the module search
  • Loading branch information
ranguard committed Nov 19, 2016
2 parents 6ab87ab + efc55a2 commit e25a01a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/MetaCPAN/Web/Model/API/Module.pm
Expand Up @@ -130,8 +130,7 @@ sub search_collapsed {
&& $data->{hits}->{total}
&& $data->{hits}->{total} > $hits + ( $run - 2 ) * $RESULTS_PER_RUN );

@distributions
= map { $_->[0] } splice( @distributions, $from, $page_size );
@distributions = splice( @distributions, $from, $page_size );

# Everything else will fail (slowly and quietly) without distributions.
if ( !@distributions ) {
Expand Down Expand Up @@ -248,7 +247,7 @@ sub _search {
return $self->search(
$query,
{
size => $run * $RESULTS_PER_RUN,
size => $RESULTS_PER_RUN,
from => ( $run - 1 ) * $RESULTS_PER_RUN,
fields => [qw(distribution)],
$run == 1
Expand Down Expand Up @@ -415,6 +414,12 @@ sub search {
}
);

# Ensure our requested fields are unique so that Elasticsearch doesn't
# return us the same value multiple times in an unexpected arrayref. For
# example, distribution is listed both above and in ->_search, which calls
# this function (->search) and gets merged with the query above.
$search->{fields} = [ uniq @{ $search->{fields} || [] } ];

return $self->request( '/file/_search', $search );
}

Expand Down

0 comments on commit e25a01a

Please sign in to comment.