diff --git a/bin/mapping.pl b/bin/mapping.pl index 830442c..2579107 100644 --- a/bin/mapping.pl +++ b/bin/mapping.pl @@ -1,10 +1,8 @@ use strict; use warnings; -use Cpanel::JSON::XS qw< decode_json >; use Getopt::Long; use MetaCPAN::Mapper; -use MetaCPAN::Ingest qw< home >; my ( $index, $cmd ); GetOptions( @@ -23,10 +21,6 @@ if $mapper->index_exists($index); if ( $cmd eq 'create' ) { - my $home = home(); - my $map_file = $home->child('conf/es/' . $index . '/mapping.json'); - my $mapping = decode_json $map_file->slurp(); - $mapper->index_create($index); - $mapper->index_put_mapping($index, $type, $mapping); + $mapper->index_add_mapping($index, $type); } diff --git a/lib/MetaCPAN/Mapper.pm b/lib/MetaCPAN/Mapper.pm index 190404a..8d86600 100644 --- a/lib/MetaCPAN/Mapper.pm +++ b/lib/MetaCPAN/Mapper.pm @@ -4,6 +4,7 @@ use strict; use warnings; use v5.36; +use Cpanel::JSON::XS qw< decode_json >; use Path::Tiny qw< path >; use MetaCPAN::Logger qw< :log :dlog >; use Search::Elasticsearch; @@ -44,9 +45,12 @@ sub index_put_mapping ($self, $index, $type, $mapping) { ); } -sub get_mapping ($self, $index) { -# my $home = home(); -# my $file = $dir->child(''); +sub index_add_mapping ($self, $index, $type) { + my $home = home(); + my $map_file = $home->child('conf/es/' . $index . '/mapping.json'); + my $mapping = decode_json $map_file->slurp(); + + $self->index_put_mapping($index, $type, $mapping); } 1;