Skip to content

Commit 56aaecd

Browse files
committed
add /search/history/{module,file,documentation}/... endpoint
1 parent 24d568e commit 56aaecd

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/MetaCPAN/Document/File.pm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,4 +857,48 @@ sub prefix {
857857
);
858858
}
859859

860+
=head2 history
861+
862+
Find the history of a given module/documentation.
863+
864+
=cut
865+
866+
sub history {
867+
my ($self, $type, $module, @path) = @_;
868+
my $search = $type eq "module"
869+
? $self->filter({
870+
nested => {
871+
path => "module",
872+
query => {
873+
constant_score => {
874+
filter => { and => [
875+
{ term =>
876+
{ "module.authorized" => \1 }
877+
},
878+
{ term => { "module.indexed" => \1 }
879+
},
880+
{ term => { "module.name" => $module }
881+
},
882+
] }
883+
}
884+
}
885+
}
886+
})
887+
: $type eq "file"
888+
? $self->filter({
889+
and => [
890+
{ term => { "file.path" => join("/", @path) } },
891+
{ term => { "file.distribution" => $module } },
892+
]
893+
})
894+
: $self->filter({
895+
and => [
896+
{ term => { "file.documentation" => $module } },
897+
{ term => { "file.indexed" => \1 } },
898+
{ term => { "file.authorized" => \1 } },
899+
]
900+
});
901+
return $search->sort([{ "file.date" => "desc"}]);
902+
}
903+
860904
__PACKAGE__->meta->make_immutable;

t/release/moose.t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,14 @@ $signature = $idx->type('file')->filter(
6363
)->first;
6464
ok(!$signature, 'SIGNATURE is not documentation');
6565

66+
{
67+
my $files = $idx->type("file");
68+
my $module = $files->history(module => "Moose")->raw->all;
69+
my $file = $files->history(file => "Moose", "lib/Moose.pm")->raw->all;
70+
is_deeply($module->{hits}, $file->{hits}, "history of Moose and lib/Moose.pm match");
71+
is($module->{hits}->{total}, 2, "two hits");
72+
my $pod = $files->history(documentation => "Moose::FAQ")->raw->all;
73+
is($pod->{hits}->{total}, 1, "one hit");
74+
}
75+
6676
done_testing;

0 commit comments

Comments
 (0)