From efddf49a6fb7c4ae6cfbd9c2b81c6225d6adcee6 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Tue, 30 Apr 2024 21:23:37 +0200 Subject: [PATCH] index module name length as separate field --- lib/MetaCPAN/Document/File.pm | 12 ++++++++++++ lib/MetaCPAN/Script/Mapping/CPAN/File.pm | 3 +++ lib/MetaCPAN/Script/Release.pm | 1 + t/document/file.t | 5 +++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/MetaCPAN/Document/File.pm b/lib/MetaCPAN/Document/File.pm index 9cbcee0bf..62d35ca0a 100644 --- a/lib/MetaCPAN/Document/File.pm +++ b/lib/MetaCPAN/Document/File.pm @@ -378,6 +378,18 @@ sub _build_documentation { return undef; } +has documentation_length => ( + is => 'ro', + isa => Maybe [Int], + lazy => 1, + builder => '_build_documentation_length', +); + +sub _build_documentation_length { + my ($self) = @_; + return length( $self->documentation ); +} + =head2 suggest Autocomplete info for documentation. diff --git a/lib/MetaCPAN/Script/Mapping/CPAN/File.pm b/lib/MetaCPAN/Script/Mapping/CPAN/File.pm index b8a82391f..fbd99d9ba 100644 --- a/lib/MetaCPAN/Script/Mapping/CPAN/File.pm +++ b/lib/MetaCPAN/Script/Mapping/CPAN/File.pm @@ -116,6 +116,9 @@ sub mapping { }, "ignore_above" : 2048 }, + "documentation_length" : { + "type" : "integer" + }, "download_url" : { "type" : "string", "index" : "not_analyzed", diff --git a/lib/MetaCPAN/Script/Release.pm b/lib/MetaCPAN/Script/Release.pm index 5b6344d4f..ebacbc99d 100644 --- a/lib/MetaCPAN/Script/Release.pm +++ b/lib/MetaCPAN/Script/Release.pm @@ -347,6 +347,7 @@ sub import_archive { $file->clear_module if ( $file->is_pod_file ); $file->documentation; + $file->documentation_length; $file->suggest; log_trace {"reindexing file $file->{path}"}; diff --git a/t/document/file.t b/t/document/file.t index b06712811..dc79fb5b9 100644 --- a/t/document/file.t +++ b/t/document/file.t @@ -96,8 +96,9 @@ END my $file = new_file_doc( content => \$content ); - is( $file->abstract, 'mymodule1 abstract' ); - is( $file->documentation, 'MyModule' ); + is( $file->abstract, 'mymodule1 abstract' ); + is( $file->documentation, 'MyModule' ); + is( $file->documentation_length, 8 ); is_deeply( $file->pod_lines, [ [ 3, 12 ], [ 18, 6 ] ] ); is( $file->sloc, 3 ); is( $file->slop, 11 );