Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #1918 from metacpan/mickey/use_author_search_ep
Browse files Browse the repository at this point in the history
Use new /author/search API endpoint
  • Loading branch information
oalders committed Jun 14, 2017
2 parents 784b451 + f7c8c64 commit 3fd6a8a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Search.pm
Expand Up @@ -50,7 +50,7 @@ sub index : Path : Args(0) {
else {
my $author = $c->model('API::Author')->search($query)->get;
if ( $author->{total} == 1
&& $query eq $author->{results}->[0]->{pauseid} )
&& $query eq $author->{authors}->[0]->{pauseid} )
{
$c->res->redirect( '/author/' . uc($query) );
$c->detach;
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Search/AutoComplete.pm
Expand Up @@ -19,7 +19,7 @@ sub index : Path : Args(0) {
value => "$_->{pauseid} - $_->{name}",
data => { id => $_->{pauseid}, type => 'author' }
},
@{ $author_data->get->{results} }
@{ $author_data->get->{authors} }
),
(
map +{ value => $_, data => { module => $_, type => 'module' } },
Expand Down
42 changes: 2 additions & 40 deletions lib/MetaCPAN/Web/Model/API/Author.pm
Expand Up @@ -48,46 +48,8 @@ sub get {

sub search {
my ( $self, $query, $from ) = @_;

my $search = {
query => {
bool => {
should => [
{
match => {
'name.analyzed' =>
{ query => $query, operator => 'and' }
}
},
{
match => {
'asciiname.analyzed' =>
{ query => $query, operator => 'and' }
}
},
{ match => { 'pauseid' => uc($query) } },
{ match => { 'profile.id' => lc($query) } },
]
}
},
size => 10,
from => $from || 0,
};

return $self->request( '/author/_search', $search )->transform(
done => sub {
my $results = shift
|| { hits => { total => 0, hits => [] } };
return {
results => [
map { +{ %{ $_->{_source} }, id => $_->{_id} } }
@{ $results->{hits}{hits} }
],
total => $results->{hits}{total} || 0,
took => $results->{took}
};
},
);
return $self->request( '/author/search', undef,
{ q => $query, from => $from } );
}

sub by_user {
Expand Down

0 comments on commit 3fd6a8a

Please sign in to comment.