Skip to content

Commit

Permalink
Merge branch 'master' into mickey/use_mirrors_search_endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Jul 4, 2017
2 parents 80995fa + 592bfb7 commit 1399dc6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
9 changes: 2 additions & 7 deletions lib/MetaCPAN/Web/Controller/Feed.pm
Expand Up @@ -14,9 +14,6 @@ use Path::Tiny qw/path/;
use Text::Markdown qw/markdown/;
use XML::Feed ();

use Importer 'MetaCPAN::Web::Elasticsearch::Adapter' =>
qw/ single_valued_arrayref_to_scalar /;

sub feed_index : PathPart('feed') : Chained('/') : CaptureArgs(0) {
my ( $self, $c ) = @_;
}
Expand Down Expand Up @@ -137,13 +134,11 @@ sub distribution : Local : Args(1) {
$c->add_dist_key($distribution);

my $data = $c->model('API::Release')->versions($distribution)->get;

$c->stash->{feed} = $self->build_feed(
host => $c->config->{web_host},
title => "Recent CPAN uploads of $distribution - MetaCPAN",
entries => [
map { single_valued_arrayref_to_scalar($_) }
map { $_->{fields} } @{ $data->{hits}->{hits} }
]
entries => $data->{releases},
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Release.pm
Expand Up @@ -131,7 +131,7 @@ sub view : Private {
release => $out,
total => $modules->{total},
took => List::Util::max(
$modules->{took}, $files->{took}, $reqs->{versions}->{took}
$modules->{took}, $files->{took}, $reqs->{versions}{took}
),
root => \@root_files,
examples => \@examples,
Expand Down
3 changes: 3 additions & 0 deletions lib/MetaCPAN/Web/Controller/Search.pm
Expand Up @@ -30,6 +30,9 @@ sub index : Path : Args(0) {
$query =~ s{\.pm\b}{};
}

$query =~ s/^\s+//;
$query =~ s/\s+$//;

my $model = $c->model('API::Module');
my $from = ( $req->page - 1 ) * $page_size;
if (
Expand Down
11 changes: 1 addition & 10 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Expand Up @@ -115,16 +115,7 @@ sub interesting_files {

sub versions {
my ( $self, $dist ) = @_;
$self->request(
'/release/_search',
{
query => { term => { distribution => $dist } },
size => 250,
sort => [ { date => 'desc' } ],
fields =>
[qw( name date author version status maturity authorized )],
}
);
$self->request("/release/versions/$dist");
}

sub topuploaders {
Expand Down
3 changes: 1 addition & 2 deletions lib/MetaCPAN/Web/Role/ReleaseInfo.pm
Expand Up @@ -67,8 +67,7 @@ sub stash_api_results {
author => $reqs->{author},
distribution => $reqs->{distribution},
rating => $reqs->{rating}->{ratings}->{ $data->{distribution} },
versions =>
[ map { $_->{fields} } @{ $reqs->{versions}->{hits}->{hits} } ],
versions => $reqs->{versions}{releases},
);

my %stash
Expand Down
19 changes: 19 additions & 0 deletions t/controller/search/precision.t
Expand Up @@ -18,6 +18,14 @@ my %tests = (
'dbix class resultset' => 'DBIx::Class::ResultSet',
);

my %authors = (
' LLAP ' => 'LLAP',
'PERLER ' => 'PERLER',
' NEILB' => 'NEILB',
'RWSTAUNER' => 'RWSTAUNER',
' OALDERS ' => 'OALDERS',
);

test_psgi app, sub {
my $cb = shift;
for my $k ( sort keys %tests ) {
Expand All @@ -29,6 +37,17 @@ test_psgi app, sub {
'//div[@class="module-result"][1]/big[1]//a[1]');
is( $module, $v, "$v is first result" );
}

for my $k ( sort keys %authors ) {
ok( my $res = $cb->( GET "/search?q=$k" ), qq{search for "$k"} );
my $v = $authors{$k};
my $tx = tx($res);
my $author
= $tx->find_value(
'//div[@class="author-results"]/ul[@class="authors clearfix"]/li[1]/a[1]'
);
like( $author, qr/\b$v\b/, "$v is first result" );
}
};

done_testing;
13 changes: 2 additions & 11 deletions t/model/release.t
Expand Up @@ -8,14 +8,6 @@ use MetaCPAN::Web;
use Importer 'MetaCPAN::Web::Elasticsearch::Adapter' =>
qw/ single_valued_arrayref_to_scalar /;

sub search_release {
my ( $method, @args ) = @_;

return
map { @{ $_->{hits}{hits} } }
MetaCPAN::Web->model('API::Release')->$method(@args)->get;
}

my ( $true, $false ) = @{ decode_json('[true, false]') };

# Explicitly test that we get a boolean.
Expand Down Expand Up @@ -60,15 +52,14 @@ subtest versions => sub {

# Something with not too many versions.
my @versions
= map { $_->{fields} }
search_release( versions => 'Mojolicious-Plugin-HamlRenderer' );
= @{ MetaCPAN::Web->model('API::Release')
->versions('Mojolicious-Plugin-HamlRenderer')->get->{releases} };

ok( scalar @versions, 'found release versions' );

my %statuses;
my @dates;
foreach my $version (@versions) {
single_valued_arrayref_to_scalar($version);

# Ensure we get a boolean so that conditions work as expected.
is_bool( $version->{authorized}, q['authorized' is a boolean] );
Expand Down

0 comments on commit 1399dc6

Please sign in to comment.