diff --git a/lib/MetaCPAN/Document/File/Set.pm b/lib/MetaCPAN/Document/File/Set.pm index 14c63ad90..b289d84eb 100644 --- a/lib/MetaCPAN/Document/File/Set.pm +++ b/lib/MetaCPAN/Document/File/Set.pm @@ -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. diff --git a/lib/MetaCPAN/Query/File.pm b/lib/MetaCPAN/Query/File.pm index e9cb7af78..b6ad3aa6f 100644 --- a/lib/MetaCPAN/Query/File.pm +++ b/lib/MetaCPAN/Query/File.pm @@ -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; diff --git a/lib/MetaCPAN/Server/Controller/Pod.pm b/lib/MetaCPAN/Server/Controller/Pod.pm index b903a211f..b001f6a4c 100644 --- a/lib/MetaCPAN/Server/Controller/Pod.pm +++ b/lib/MetaCPAN/Server/Controller/Pod.pm @@ -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; @@ -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;