Skip to content

Commit cc99e50

Browse files
committed
move documented_modules to query
1 parent 0d31ee2 commit cc99e50

File tree

3 files changed

+68
-56
lines changed

3 files changed

+68
-56
lines changed

lib/MetaCPAN/Document/File/Set.pm

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -107,51 +107,6 @@ sub find_pod {
107107
}
108108
}
109109

110-
sub documented_modules {
111-
my ( $self, $release ) = @_;
112-
return $self->query( {
113-
bool => {
114-
must => [
115-
{ term => { release => $release->{name} } },
116-
{ term => { author => $release->{author} } },
117-
{ exists => { field => "documentation" } },
118-
{
119-
bool => {
120-
should => [
121-
{
122-
bool => {
123-
must => [
124-
{
125-
exists =>
126-
{ field => 'module.name' }
127-
},
128-
{
129-
term =>
130-
{ 'module.indexed' => true }
131-
},
132-
],
133-
}
134-
},
135-
{
136-
bool => {
137-
must => [
138-
{
139-
exists =>
140-
{ field => 'pod.analyzed' }
141-
},
142-
{ term => { indexed => true } },
143-
],
144-
}
145-
},
146-
],
147-
}
148-
},
149-
],
150-
},
151-
} )->size(999)
152-
->source( [qw(name module path documentation distribution)] )->all;
153-
}
154-
155110
=head2 history
156111
157112
Find the history of a given module/documentation.

lib/MetaCPAN/Query/File.pm

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,62 @@ sub autocomplete_suggester {
502502
};
503503
}
504504

505+
sub documented_modules {
506+
my ( $self, $author, $release ) = @_;
507+
my $query = {
508+
bool => {
509+
must => [
510+
{ term => { author => $author } },
511+
{ term => { release => $release } },
512+
{ exists => { field => "documentation" } },
513+
{
514+
bool => {
515+
should => [
516+
{
517+
bool => {
518+
must => [
519+
{
520+
exists =>
521+
{ field => 'module.name' }
522+
},
523+
{
524+
term =>
525+
{ 'module.indexed' => true }
526+
},
527+
],
528+
}
529+
},
530+
{
531+
bool => {
532+
must => [
533+
{
534+
exists =>
535+
{ field => 'pod.analyzed' }
536+
},
537+
{ term => { indexed => true } },
538+
],
539+
}
540+
},
541+
],
542+
}
543+
},
544+
],
545+
},
546+
};
547+
my $res = $self->es->search(
548+
es_doc_path('file'),
549+
body => {
550+
query => $query,
551+
size => 999,
552+
_source => [qw(name module path documentation distribution)],
553+
},
554+
);
555+
556+
return {
557+
took => $res->{took},
558+
files => [ map $_->{_source}, $res->{hits}{hits} ],
559+
};
560+
}
561+
505562
__PACKAGE__->meta->make_immutable;
506563
1;

lib/MetaCPAN/Server/Controller/Pod.pm

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ sub get : Path('') : Args(1) {
4343

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

4950
my $links = {};
5051

51-
for my $file (@modules) {
52-
next
53-
unless $file->has_documentation;
54-
my $name = $file->documentation;
52+
for my $file (@$files) {
53+
my $name = $file->{documentation}
54+
or next;
5555
my ($module)
56-
= grep { $_->name eq $name } @{ $file->module };
57-
if ( $module && $module->authorized && $module->indexed ) {
56+
= grep { $_->{name} eq $name } @{ $file->{module} };
57+
if ( $module && $module->{authorized} && $module->{indexed} ) {
5858
if ($permalinks) {
5959
$links->{$name} = join '/',
60-
'release', $author, $release, $file->path;
60+
'release', $author, $release, $file->{path};
6161
}
6262
else {
6363
$links->{$name} = $name;
@@ -67,11 +67,11 @@ sub find_dist_links {
6767
if exists $links->{$name};
6868
if ($permalinks) {
6969
$links->{$name} = join '/',
70-
'release', $author, $release, $file->path;
70+
'release', $author, $release, $file->{path};
7171
}
7272
else {
7373
$links->{$name} = join '/',
74-
'distribution', $file->distribution, $file->path;
74+
'distribution', $file->{distribution}, $file->{path};
7575
}
7676
}
7777
return $links;

0 commit comments

Comments
 (0)