Skip to content

Commit

Permalink
/search/autocomplete: Collapse single-valued arrays in fields
Browse files Browse the repository at this point in the history
To be consistent with API v0 and other v1 endpoints.  No need to leak
more crazy from Elasticsearch than necessary.
  • Loading branch information
tsibley committed Nov 20, 2016
1 parent 5b40e60 commit cd85f4a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/MetaCPAN/Server/Controller/Search/Autocomplete.pm
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;

use Moose;
use MetaCPAN::Util qw( single_valued_arrayref_to_scalar );

BEGIN { extends 'MetaCPAN::Server::Controller' }

Expand All @@ -16,8 +17,12 @@ sub get : Local : Path('') : Args(0) {
my $model = $self->model($c);
$model = $model->fields( [qw(documentation release author distribution)] )
unless $model->fields;
my $data = $model->autocomplete( $c->req->param("q") )->raw;
$c->stash( $data->all );
my $data = $model->autocomplete( $c->req->param("q") )->raw->all;

single_valued_arrayref_to_scalar( $_->{fields} )
for @{ $data->{hits}{hits} };

$c->stash($data);
}

1;

0 comments on commit cd85f4a

Please sign in to comment.