Skip to content

Commit

Permalink
move documented_modules to query
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Dec 28, 2024
1 parent 495fa1c commit 8fb204d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 56 deletions.
45 changes: 0 additions & 45 deletions lib/MetaCPAN/Document/File/Set.pm
Original file line number Diff line number Diff line change
Expand Up @@ -107,51 +107,6 @@ sub find_pod {
}
}

sub documented_modules {
my ( $self, $release ) = @_;
return $self->query( {
bool => {
must => [
{ term => { release => $release->{name} } },
{ term => { author => $release->{author} } },
{ exists => { field => "documentation" } },
{
bool => {
should => [
{
bool => {
must => [
{
exists =>
{ field => 'module.name' }
},
{
term =>
{ 'module.indexed' => true }
},
],
}
},
{
bool => {
must => [
{
exists =>
{ field => 'pod.analyzed' }
},
{ term => { indexed => true } },
],
}
},
],
}
},
],
},
} )->size(999)
->source( [qw(name module path documentation distribution)] )->all;
}

=head2 history
Find the history of a given module/documentation.
Expand Down
57 changes: 57 additions & 0 deletions lib/MetaCPAN/Query/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,62 @@ sub autocomplete_suggester {
};
}

sub documented_modules {
my ( $self, $author, $release ) = @_;
my $query = {
bool => {
must => [
{ term => { author => $author } },
{ term => { release => $release } },
{ exists => { field => "documentation" } },
{
bool => {
should => [
{
bool => {
must => [
{
exists =>
{ field => 'module.name' }
},
{
term =>
{ 'module.indexed' => true }
},
],
}
},
{
bool => {
must => [
{
exists =>
{ field => 'pod.analyzed' }
},
{ term => { indexed => true } },
],
}
},
],
}
},
],
},
};
my $res = $self->es->search(
es_doc_path('file'),
body => {
query => $query,
size => 999,
_source => [qw(name module path documentation distribution)],
},
);

return {
took => $res->{took},
files => [ map $_->{_source}, $res->{hits}{hits} ],
};
}

__PACKAGE__->meta->make_immutable;
1;
22 changes: 11 additions & 11 deletions lib/MetaCPAN/Server/Controller/Pod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ sub get : Path('') : Args(1) {

sub find_dist_links {
my ( $self, $c, $author, $release, $permalinks ) = @_;
my @modules = $c->model('ESModel')->doc('file')
->documented_modules( { name => $release, author => $author } );
my $modules
= $c->model('ESQuery')->file->documented_modules( $author, $release );
my $files = $modules->{files};

my $links = {};

for my $file (@modules) {
next
unless $file->has_documentation;
my $name = $file->documentation;
for my $file (@$files) {
my $name = $file->{documentation}
or next;
my ($module)
= grep { $_->name eq $name } @{ $file->module };
if ( $module && $module->authorized && $module->indexed ) {
= grep { $_->{name} eq $name } @{ $file->{module} };
if ( $module && $module->{authorized} && $module->{indexed} ) {
if ($permalinks) {
$links->{$name} = join '/',
'release', $author, $release, $file->path;
'release', $author, $release, $file->{path};
}
else {
$links->{$name} = $name;
Expand All @@ -67,11 +67,11 @@ sub find_dist_links {
if exists $links->{$name};
if ($permalinks) {
$links->{$name} = join '/',
'release', $author, $release, $file->path;
'release', $author, $release, $file->{path};
}
else {
$links->{$name} = join '/',
'distribution', $file->distribution, $file->path;
'distribution', $file->{distribution}, $file->{path};
}
}
return $links;
Expand Down

0 comments on commit 8fb204d

Please sign in to comment.