Skip to content

Commit

Permalink
convert deprecated use of and/or/not in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed May 23, 2017
1 parent 0145221 commit 1da3dec
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
19 changes: 11 additions & 8 deletions lib/MetaCPAN/Web/Controller/Activity.pm
Expand Up @@ -43,14 +43,17 @@ sub index : Path : Args(0) {
aggregations => {
histo => {
filter => {
and => [
{
range => {
date => { from => $start->epoch . '000' }
}
},
@$q
]
bool => {
must => [
{
range => {
date =>
{ from => $start->epoch . '000' }
}
},
@$q
]
}
},
aggregations => {
entries => {
Expand Down
17 changes: 11 additions & 6 deletions lib/MetaCPAN/Web/Controller/Mirrors.pm
Expand Up @@ -14,7 +14,7 @@ sub index : Path : Args(0) {

my $location;
my @protocols;
if ( my $q = $c->req->parameters->{q} ) {
if ( my $q = $c->req->parameters->{'q'} ) {
my @parts = split( /\s+/, $q );
foreach my $part (@parts) {
push( @protocols, $part )
Expand All @@ -25,16 +25,21 @@ sub index : Path : Args(0) {
}
}

my @or;
push( @or, { not => { filter => { missing => { field => $_ } } } } )
for (@protocols);
my @filters
= map +{ filter => { missing => { field => $_ } } },
@protocols;

my $data = $c->model('API')->request(
'/mirror/_search',
{
size => 999,
query => { match_all => {} },
@or ? ( filter => { and => \@or } ) : (),
query => (
@filters
? {
bool => { must_not => { bool => should => \@filters } }
}
: { match_all => {} }
),
$location
? (
sort => {
Expand Down
4 changes: 1 addition & 3 deletions lib/MetaCPAN/Web/Model/API/Author.pm
Expand Up @@ -98,9 +98,7 @@ sub by_user {
my $query = return $self->request(
'/author/_search',
{
query => { match_all => {} },
filter =>
{ or => [ map { { term => { user => $_ } } } @{$users} ] },
query => { terms => { user => $users } },
fields => [qw(user pauseid)],
size => 100
}
Expand Down
4 changes: 1 addition & 3 deletions lib/MetaCPAN/Web/Model/API/Favorite.pm
Expand Up @@ -182,9 +182,7 @@ sub plusser_by_id {
return $self->request(
'/author/_search',
{
query => { match_all => {} },
filter =>
{ or => [ map { { term => { user => $_ } } } @{$users} ] },
query => { terms => { user => $users } },
_source => { includes => [qw(pauseid gravatar_url)] },
size => 1000,
sort => ['pauseid']
Expand Down
14 changes: 6 additions & 8 deletions lib/MetaCPAN/Web/Model/API/Lab.pm
Expand Up @@ -75,20 +75,18 @@ sub _handle_module {
sub fetch_latest_distros {
my ( $self, $size, $pauseid ) = @_;

# status can have all kinds of values, cpan is an attempt to find the ones that are on cpan but
# are not authorized. Maybe it also includes ones that were superseeded by releases of other people
my @filter = ( { not => { term => { status => 'backpan' } } } );
if ($pauseid) {
push @filter, { term => { author => $pauseid } };
}

my $cv = $self->cv;
my $r = $self->request(
'/release/_search',
{
query => {
bool => {
must => \@filter,
must => [
{ terms => { status => [qw< cpan latest >] } },
(
$pauseid ? { term => { author => $pauseid } } : ()
),
],
}
},
sort => [
Expand Down
15 changes: 7 additions & 8 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Expand Up @@ -52,13 +52,12 @@ sub _new_distributions_query {
return {
constant_score => {
filter => {
and => [
{ term => { first => 1 } },
{
not =>
{ filter => { term => { status => 'backpan' } } }
},
]
bool => {
must => [
{ term => { first => 1 } },
{ terms => { status => [qw< cpan latest >] } },
]
}
}
}
};
Expand Down Expand Up @@ -116,7 +115,7 @@ sub recent {
$query = {
constant_score => {
filter => {
not => { filter => { term => { status => 'backpan' } } }
terms => { status => [qw< cpan latest >] }
}
}
};
Expand Down

0 comments on commit 1da3dec

Please sign in to comment.