Skip to content

Commit f7f1e7a

Browse files
authored
Merge pull request #66 from metacpan/mickey/mapping_logic
Move mapping adding logic to the module
2 parents 33c1b14 + c546e6b commit f7f1e7a

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

bin/mapping.pl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use strict;
22
use warnings;
33

4-
use Cpanel::JSON::XS qw< decode_json >;
54
use Getopt::Long;
65
use MetaCPAN::Mapper;
7-
use MetaCPAN::Ingest qw< home >;
86

97
my ( $index, $cmd );
108
GetOptions(
@@ -23,10 +21,6 @@
2321
if $mapper->index_exists($index);
2422

2523
if ( $cmd eq 'create' ) {
26-
my $home = home();
27-
my $map_file = $home->child('conf/es/' . $index . '/mapping.json');
28-
my $mapping = decode_json $map_file->slurp();
29-
3024
$mapper->index_create($index);
31-
$mapper->index_put_mapping($index, $type, $mapping);
25+
$mapper->index_add_mapping($index, $type);
3226
}

lib/MetaCPAN/Mapper.pm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use strict;
44
use warnings;
55
use v5.36;
66

7+
use Cpanel::JSON::XS qw< decode_json >;
78
use Path::Tiny qw< path >;
89
use MetaCPAN::Logger qw< :log :dlog >;
910
use Search::Elasticsearch;
@@ -44,9 +45,12 @@ sub index_put_mapping ($self, $index, $type, $mapping) {
4445
);
4546
}
4647

47-
sub get_mapping ($self, $index) {
48-
# my $home = home();
49-
# my $file = $dir->child('');
48+
sub index_add_mapping ($self, $index, $type) {
49+
my $home = home();
50+
my $map_file = $home->child('conf/es/' . $index . '/mapping.json');
51+
my $mapping = decode_json $map_file->slurp();
52+
53+
$self->index_put_mapping($index, $type, $mapping);
5054
}
5155

5256
1;

0 commit comments

Comments
 (0)