Skip to content

Commit

Permalink
Merge pull request #12 from metacpan/haarg/source-not-fields
Browse files Browse the repository at this point in the history
use _source rather than fields
  • Loading branch information
haarg authored Sep 28, 2024
2 parents 70ebc4c + ba6ea94 commit b837b00
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/MetaCPAN/SCORedirect.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ sub is_dist {
},
sort => [ { date => 'desc' } ],
size => 1,
fields => [ qw(name author) ],
_source => [ qw(name author) ],
});

return !!@{ $res->{hits}{hits} };
Expand Down Expand Up @@ -129,7 +129,7 @@ sub find_dev {
},
sort => [ { date => 'desc' } ],
size => 1,
fields => [ qw(name author) ],
_source => [ qw(name author) ],
};
my $res = $self->ua->post($self->api_url.'release', {
content => $J->encode($query),
Expand All @@ -139,7 +139,7 @@ sub find_dev {

my $rel = $J->decode($res->{content});
Dlog_debug { "found dev release $_" } $rel;
my $release = $rel->{hits}{hits}[0]{fields} or die [ 404 ];
my $release = $rel->{hits}{hits}[0]{_source} or die [ 404 ];

return ($release->{name}, $release->{author});
}
Expand Down Expand Up @@ -197,7 +197,7 @@ sub dist_lookup {
},
sort => [ { date => 'desc' } ],
size => 1,
fields => [ qw(status author) ],
_source => [ qw(status author) ],
};
my $json = $J->encode($query);
my $res = $self->ua->post($self->api_url.'release', {
Expand All @@ -206,7 +206,7 @@ sub dist_lookup {
die [ $res->{status} ]
unless $res->{status} == 200;

my $rel = $J->decode($res->{content})->{hits}{hits}[0]{fields};
my $rel = $J->decode($res->{content})->{hits}{hits}[0]{_source};
Dlog_debug { "found release from $release: $_" } $rel;
$author ||= $rel->{author};
}
Expand Down Expand Up @@ -273,21 +273,19 @@ sub mod_lookup {
{ 'stat.mtime' => { order => 'desc' } }
],
size => 100,
fields => [qw(
path
release
_source => [qw(
author
documentation
)],
_source => [qw(
module.name
path
release
)],
};

my $res = $self->api_call('file/_search?search_type=dfs_query_then_fetch', $query);
Dlog_debug { "found candidates: $_" } $res;

my @candidates = map +{ %{$_->{fields}}, %{$_->{_source}||{}} }, @{$res->{hits}{hits}||[]};
my @candidates = map $_->{_source}, @{$res->{hits}{hits}||[]};
my ($file) = grep {;
(!$_->{documentation} || $_->{documentation} eq $module )
&& grep { $_->{name} eq $module } @{ $_->{module} || [] }
Expand Down

0 comments on commit b837b00

Please sign in to comment.