From f7c8c641ce6291ac4f1a92dbcc5b7c4c92ae002c Mon Sep 17 00:00:00 2001 From: Mickey Nasriachi Date: Wed, 14 Jun 2017 22:45:12 +0100 Subject: [PATCH] Use new /author/search API endpoint Replace query sending with endpoint usage. --- lib/MetaCPAN/Web/Controller/Search.pm | 2 +- .../Web/Controller/Search/AutoComplete.pm | 2 +- lib/MetaCPAN/Web/Model/API/Author.pm | 42 +------------------ 3 files changed, 4 insertions(+), 42 deletions(-) diff --git a/lib/MetaCPAN/Web/Controller/Search.pm b/lib/MetaCPAN/Web/Controller/Search.pm index 68aa3d3985..ddbbf96952 100644 --- a/lib/MetaCPAN/Web/Controller/Search.pm +++ b/lib/MetaCPAN/Web/Controller/Search.pm @@ -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; diff --git a/lib/MetaCPAN/Web/Controller/Search/AutoComplete.pm b/lib/MetaCPAN/Web/Controller/Search/AutoComplete.pm index c8a2f77d4e..e8fcaf2541 100644 --- a/lib/MetaCPAN/Web/Controller/Search/AutoComplete.pm +++ b/lib/MetaCPAN/Web/Controller/Search/AutoComplete.pm @@ -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' } }, diff --git a/lib/MetaCPAN/Web/Model/API/Author.pm b/lib/MetaCPAN/Web/Model/API/Author.pm index 31761d40f1..c0675ed283 100644 --- a/lib/MetaCPAN/Web/Model/API/Author.pm +++ b/lib/MetaCPAN/Web/Model/API/Author.pm @@ -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 {