Skip to content

Commit

Permalink
Merge pull request #717 from metacpan/mickey/controller_autocomplete_…
Browse files Browse the repository at this point in the history
…refactor

Controller/Autocomplete - move data handling to Document module
  • Loading branch information
oalders committed Jul 10, 2017
2 parents 8df0a22 + 2a9d2f8 commit 2f74d54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 11 additions & 1 deletion lib/MetaCPAN/Document/File/Set.pm
Expand Up @@ -431,7 +431,7 @@ sub autocomplete {
my $query = join( q{ }, @terms );
return $self unless $query;

return $self->search_type('dfs_query_then_fetch')->query(
my $data = $self->search_type('dfs_query_then_fetch')->query(
{
filtered => {
query => {
Expand Down Expand Up @@ -462,6 +462,16 @@ sub autocomplete {
}
}
)->sort( [ '_score', 'documentation' ] );

$data = $data->fields( [qw(documentation release author distribution)] )
unless $self->fields;

$data = $data->source(0)->raw->all;

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

return $data;
}

# this method will replace 'sub autocomplete' after the
Expand Down
10 changes: 1 addition & 9 deletions lib/MetaCPAN/Server/Controller/Search/Autocomplete.pm
Expand Up @@ -14,15 +14,7 @@ has '+type' => ( default => 'file' );

sub get : Local : Path('') : Args(0) {
my ( $self, $c ) = @_;
my $model = $self->model($c);
$model = $model->fields( [qw(documentation release author distribution)] )
unless $model->fields;
my $data
= $model->autocomplete( $c->req->param("q") )->source(0)->raw->all;

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

my $data = $self->model($c)->autocomplete( $c->req->param("q") );
$c->stash($data);
}

Expand Down

0 comments on commit 2f74d54

Please sign in to comment.