Skip to content

Commit

Permalink
Added new /release/modules/PAUSEID/RELNAME endpoint
Browse files Browse the repository at this point in the history
This endpoint will replace the query sent from WEB.
  • Loading branch information
mickeyn committed Jun 23, 2017
1 parent 54e5bc3 commit c114465
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
93 changes: 93 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -960,5 +960,98 @@ sub recent {
};
}

sub modules {
my ( $self, $author, $release ) = @_;

my $body = {
query => {
bool => {
must => [
{ term => { release => $release } },
{ term => { author => $author } },
{ term => { directory => 0 } },
{
bool => {
should => [
{
bool => {
must => [
{
exists => {
field => 'module.name'
}
},
{
term =>
{ 'module.indexed' => 1 }
}
]
}
},
{
bool => {
must => [
{
range => {
slop => { gt => 0 }
}
},
{
exists => {
field => 'pod.analyzed'
}
},
{
term => { 'indexed' => 1 }
},
]
}
}
]
}
}
]
}
},
size => 999,

# Sort by documentation name; if there isn't one, sort by path.
sort => [ 'documentation', 'path' ],

_source => [ "module", "abstract" ],

fields => [
qw(
author
authorized
distribution
documentation
indexed
path
pod_lines
release
status
)
],
};

my $ret = $self->es->search(
index => $self->index->name,
type => 'file',
body => $body,
);
return unless $ret->{hits}{total};

my @files = map { single_valued_arrayref_to_scalar($_) }
map +{ %{ $_->{fields} }, %{ $_->{_source} } },
@{ $ret->{hits}{hits} };

return {
files => \@files,
total => $ret->{hits}{total},
took => $ret->{took}
};
}

__PACKAGE__->meta->make_immutable;
1;
7 changes: 7 additions & 0 deletions lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -67,6 +67,13 @@ sub files : Path('files') : Args(1) {
$c->stash($data);
}

sub modules : Path('modules') : Args(2) {
my ( $self, $c, $author, $name ) = @_;
my $data = $self->model($c)->raw->modules( $author, $name );
return unless $data;
$c->stash($data);
}

sub recent : Path('recent') : Args(0) {
my ( $self, $c ) = @_;
my @params = @{ $c->req->params }{qw( page page_size type )};
Expand Down

0 comments on commit c114465

Please sign in to comment.