Skip to content

Commit

Permalink
add an example for es_filter use
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Jan 19, 2015
1 parent 774f5db commit fecbcd4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/es_filter.pl
@@ -0,0 +1,29 @@
use strict;
use warnings;

use MetaCPAN::Client;

# use raw ES filter on a { match_all => {} } query

# find 'latest' status releases with at least 700 failing tests
# which consist at least 50% of their overall number of tests.

my $release = MetaCPAN::Client->new->all(
'releases',
{
es_filter => {
and => [
{ range => { 'tests.fail' => { gte => 700 } } },
{ term => { 'status' => 'latest' } }
]
},

fields => [qw/ name tests /],
}
);

while ( my $r = $release->next ) {
my $fail = $r->tests->{fail};
my $all = 0; $all += $_ for @{ $r->tests }{qw/pass fail na unknown/};
($fail / $all) >= 0.5 and printf "%4d/%4d: %s\n", $fail, $all, $r->name;
}

0 comments on commit fecbcd4

Please sign in to comment.