Skip to content

Commit

Permalink
Added /release/interesting_files/PAUSEID/RELEASE
Browse files Browse the repository at this point in the history
This endpoint will be used to replace the query being sent
from WEB.
  • Loading branch information
mickeyn committed Jun 21, 2017
1 parent abbab23 commit 7c58308
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
107 changes: 107 additions & 0 deletions lib/MetaCPAN/Document/File/Set.pm
Expand Up @@ -572,5 +572,112 @@ sub dir {
return { dir => $dir };
}

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

my $body = {
query => {
bool => {
must => [
{ term => { release => $release } },
{ term => { author => $author } },
{ term => { directory => \0 } },
{ not => { prefix => { 'path' => 'xt/' } } },
{ not => { prefix => { 'path' => 't/' } } },
{
bool => {
should => [
{
bool => {
must => [
{ term => { level => 0 } },
{
terms => {
name => [
qw(
AUTHORS
Build.PL
CHANGELOG
CHANGES
CONTRIBUTING
CONTRIBUTING.md
COPYRIGHT
CREDITS
ChangeLog
Changelog
Changes
Copying
FAQ
INSTALL
INSTALL.md
LICENCE
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
NEWS
README
README.markdown
README.md
README.mdown
README.mkdn
THANKS
TODO
ToDo
Todo
cpanfile
dist.ini
minil.toml
)
]
}
}
]
}
},
map {
{ prefix => { 'name' => $_ } },
{ prefix => { 'path' => $_ } },

# With "prefix" we don't need the plural "s".
} qw(
ex eg
example Example
sample
)
]
}
}
]
}
},

# NOTE: We could inject author/release/distribution into each result
# in the controller if asking ES for less data would be better.
fields => [
qw(
name documentation path pod_lines
author release distribution status
)
],
size => 250,
};

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

my $files = [ map { $_->{fields} } @{ $data->{hits}{hits} } ];
single_valued_arrayref_to_scalar($files);

return { files => $files };
}

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

sub interesting_files : Path('interesting_files') : Args(2) {
my ( $self, $c, $author, $release ) = @_;
my $data
= $c->model('CPAN::File')->interesting_files( $author, $release );
return unless $data;
$c->stash($data);
}

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit 7c58308

Please sign in to comment.