Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
simplify multi-value term queries (using 'terms')
  • Loading branch information
mickeyn committed Apr 23, 2017
1 parent 954d5e4 commit cd7d998
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 38 deletions.
8 changes: 1 addition & 7 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -313,13 +313,7 @@ sub aggregate_status_by_author {

sub find_depending_on {
my ( $self, $modules ) = @_;
return $self->filter(
{
or => [
map { { term => { 'dependency.module' => $_ } } } @$modules
]
}
);
return $self->filter( { terms => { 'dependency.module' => $modules } } );
}

sub find {
Expand Down
34 changes: 10 additions & 24 deletions lib/MetaCPAN/Model/Search.pm
Expand Up @@ -32,9 +32,11 @@ my @ROGUE_DISTRIBUTIONS
= qw(kurila perl_debug perl_mlb perl-5.005_02+apache1.3.3+modperl pod2texi perlbench spodcxx Bundle-Everything);

sub _not_rogue {
my @rogue_dists
= map { { term => { 'distribution' => $_ } } } @ROGUE_DISTRIBUTIONS;
return { not => { filter => { or => \@rogue_dists } } };
return {
not => {
filter => { terms => { distribution => \@ROGUE_DISTRIBUTIONS } }
}
};
}

sub search_simple {
Expand Down Expand Up @@ -168,17 +170,8 @@ sub _search_collapsed {
size => 5000,
query => {
filtered => {
filter => {
and => [
{
or => [
map {
{ term => { 'distribution' => $_ } }
} @distributions
]
}
]
}
filter =>
{ terms => { 'distribution' => \@distributions } }
}
}
}
Expand Down Expand Up @@ -383,9 +376,7 @@ sub _build_search_descriptions_query {
query => {
filtered => {
query => { match_all => {} },
filter => {
or => [ map { { term => { id => $_ } } } @ids ]
}
filter => { terms => { id => \@ids } },
}
},
fields => [qw(description id)],
Expand Down Expand Up @@ -418,13 +409,8 @@ sub _build_search_favorites_query {
size => 0,
query => {
filtered => {
query => { match_all => {} },
filter => {
or => [
map { { term => { 'distribution' => $_ } } }
@distributions
]
}
query => { match_all => {} },
filter => { terms => { distribution => \@distributions } },
}
},
aggregations => {
Expand Down
8 changes: 1 addition & 7 deletions lib/MetaCPAN/Server/Controller/Changes.pm
Expand Up @@ -62,13 +62,7 @@ sub get : Chained('index') : PathPart('') : Args(2) {
and => [
{ term => { level => 0 } },
{ term => { directory => 0 } },
{
or => [
map {
{ term => { 'name' => $_ } }
} @candidates
]
}
{ terms => { name => \@candidates } },
]
}
],
Expand Down

0 comments on commit cd7d998

Please sign in to comment.