Skip to content

Commit

Permalink
Merge pull request #570 from metacpan/tsibley/autocomplete-collapse
Browse files Browse the repository at this point in the history
/search/autocomplete: Collapse single-valued arrays in fields
  • Loading branch information
mickeyn committed Nov 20, 2016
2 parents 1321275 + b94affe commit 286c183
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 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;
2 changes: 1 addition & 1 deletion t/server/controller/search/autocomplete.t
Expand Up @@ -14,7 +14,7 @@ test_psgi app, sub {
'GET' );
my $json = decode_json_ok($res);

my $got = [ map { @{ $_->{fields}{documentation} } }
my $got = [ map { $_->{fields}{documentation} }
@{ $json->{hits}{hits} } ];

is_deeply $got, [
Expand Down

0 comments on commit 286c183

Please sign in to comment.