Permalink
Browse files

Merge branch 'master' into mickey/use_author_by_ids

  • Loading branch information...
2 parents db7da2e + cbb4938 commit 3d64c0d5fcad6d24ff11d6b2ea55712dcf07a009 @mickeyn mickeyn committed Jul 4, 2017
Showing with 18 additions and 51 deletions.
  1. +4 −51 lib/MetaCPAN/Web/Controller/Mirrors.pm
  2. +14 −0 lib/MetaCPAN/Web/Model/API/Mirror.pm
@@ -12,61 +12,14 @@ sub index : Path : Args(0) {
$c->browser_max_age('1d');
$c->cdn_max_age('1d');
- my $location;
- my @protocols;
- if ( my $q = $c->req->parameters->{'q'} ) {
- my @parts = split( /\s+/, $q );
- foreach my $part (@parts) {
- push( @protocols, $part )
- if ( grep { $_ eq $part } qw(http ftp rsync) );
- }
- if ( $q =~ /loc\:([^\s]+)/ ) {
- $location = [ split( /,/, $1 ) ];
- }
- }
-
- my @filters
- = map +{ filter => { missing => { field => $_ } } },
- @protocols;
+ my $query = $c->req->parameters->{'q'};
+ my $data = $c->model('API::Mirror')->search($query)->get;
- my $data = $c->model('API')->request(
- '/mirror/_search',
- {
- size => 999,
- query => (
- @filters
- ? {
- bool => { must_not => { bool => should => \@filters } }
- }
- : { match_all => {} }
- ),
- $location
- ? (
- sort => {
- _geo_distance => {
- location => [ $location->[1], $location->[0] ],
- order => 'asc',
- unit => 'km'
- }
- }
- )
- : ( sort => [ 'continent', 'country' ] )
- }
- )->get;
- my $latest = [
- map {
- {
- %{ $_->{_source} }, distance => $location
- ? $_->{sort}->[0]
- : undef
- }
- } @{ $data->{hits}->{hits} }
- ];
$c->stash(
{
- mirrors => $latest,
+ mirrors => $data->{mirrors},
took => $data->{took},
- total => $data->{hits}->{total},
+ total => $data->{total},
template => 'mirrors.html',
}
);
@@ -0,0 +1,14 @@
+package MetaCPAN::Web::Model::API::Mirror;
+use Moose;
+use namespace::autoclean;
+
+extends 'MetaCPAN::Web::Model::API';
+
+sub search {
+ my ( $self, $query ) = @_;
+ $self->request( "/mirror/search", undef, { q => $query } );
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;

0 comments on commit 3d64c0d

Please sign in to comment.