Skip to content

Commit

Permalink
Module search: Avoid requesting duplicate fields from ES
Browse files Browse the repository at this point in the history
Requesting a field more than once produces the value more than once
which causes the new ES to produce an array value for the field
containing duplicate values.  This busts our collapsed search which
ended up making ref addresses unique instead of distribution names.
With the root cause removed, the map which papered over the symptoms is
not longer needed.
  • Loading branch information
tsibley committed Nov 19, 2016
1 parent 7d41a31 commit efc55a2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 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 @@ -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 efc55a2

Please sign in to comment.