line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Find out whether results exist for cases |
2
|
|
|
|
|
|
|
# PODNAME: App::Prove::Elasticsearch::Searcher::ByName |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package App::Prove::Elasticsearch::Searcher::ByName; |
5
|
|
|
|
|
|
|
$App::Prove::Elasticsearch::Searcher::ByName::VERSION = '0.001'; |
6
|
2
|
|
|
2
|
|
421
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
53
|
|
7
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
43
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
8
|
use Search::Elasticsearch(); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
27
|
|
10
|
2
|
|
|
2
|
|
8
|
use File::Basename(); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
28
|
|
11
|
2
|
|
|
2
|
|
9
|
use Cwd(); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
47
|
|
12
|
2
|
|
|
2
|
|
10
|
use List::Util 1.45 qw{uniq}; |
|
2
|
|
|
|
|
32
|
|
|
2
|
|
|
|
|
98
|
|
13
|
2
|
|
|
2
|
|
10
|
use App::Prove::Elasticsearch::Utils(); |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
1217
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
1
|
|
|
1
|
1
|
210
|
my ($class, $conf, $indexer) = @_; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
3
|
my $v = App::Prove::Elasticsearch::Utils::require_versioner($conf); |
19
|
1
|
|
|
|
|
4
|
my $p = App::Prove::Elasticsearch::Utils::require_platformer($conf); |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
9
|
return bless( |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
handle => Search::Elasticsearch->new( |
24
|
|
|
|
|
|
|
nodes => "$conf->{'server.host'}:$conf->{'server.port'}", |
25
|
|
|
|
|
|
|
request_timeout => 30 |
26
|
|
|
|
|
|
|
), |
27
|
|
|
|
|
|
|
index => $indexer->index, |
28
|
|
|
|
|
|
|
versioner => $v, |
29
|
|
|
|
|
|
|
platformer => $p, |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
$class |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub filter { |
37
|
4
|
|
|
4
|
1
|
4301
|
my ($self, @tests) = @_; |
38
|
|
|
|
|
|
|
|
39
|
4
|
50
|
|
|
|
10
|
return @tests unless $self->_has_results(); |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
15
|
my $platz = &{\&{$self->{platformer} . "::get_platforms"}}(); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
17
|
|
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
11
|
my @tests_filtered; |
44
|
4
|
|
|
|
|
9
|
foreach my $test (@tests) { |
45
|
4
|
|
|
|
|
7
|
$test = Cwd::abs_path($test); |
46
|
4
|
|
|
|
|
13
|
my $tname = File::Basename::basename($test); |
47
|
4
|
|
|
|
|
17
|
my $tversion = &{\&{$self->{versioner} . "::get_version"}}($test); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
13
|
|
48
|
|
|
|
|
|
|
my %q = ( |
49
|
|
|
|
|
|
|
index => $self->{index}, |
50
|
4
|
|
|
|
|
32
|
body => { |
51
|
|
|
|
|
|
|
query => { |
52
|
|
|
|
|
|
|
bool => { |
53
|
|
|
|
|
|
|
must => [ |
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
match => { |
56
|
|
|
|
|
|
|
name => $tname, |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
match => { |
61
|
|
|
|
|
|
|
version => $tversion, |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
], |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
size => 1 |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
4
|
|
|
|
|
9
|
foreach my $plat (@$platz) { |
72
|
|
|
|
|
|
|
push( |
73
|
2
|
|
|
|
|
3
|
@{$q{body}{query}{bool}{must}}, |
|
2
|
|
|
|
|
9
|
|
74
|
|
|
|
|
|
|
{match => {platform => $plat}} |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
14
|
my $docs = $self->{handle}->search(%q); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#OK, check if this document we got back *actually* matched |
81
|
4
|
50
|
|
|
|
34
|
if (!scalar(@{$docs->{hits}->{hits}})) { |
|
4
|
|
|
|
|
10
|
|
82
|
0
|
|
|
|
|
0
|
push(@tests_filtered, $test); |
83
|
0
|
|
|
|
|
0
|
next; |
84
|
|
|
|
|
|
|
} |
85
|
4
|
|
|
|
|
10
|
my $match = $docs->{hits}->{hits}->[0]->{_source}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my @plats_match = ( |
88
|
|
|
|
|
|
|
(ref($match->{platform}) eq 'ARRAY') |
89
|
0
|
|
|
|
|
0
|
? @{$match->{platform}} |
90
|
|
|
|
|
|
|
: ($match->{platform}) |
91
|
4
|
50
|
|
|
|
25
|
); |
92
|
|
|
|
|
|
|
|
93
|
4
|
|
|
|
|
9
|
my $name_correct = $match->{name} eq $tname; |
94
|
4
|
|
|
|
|
10
|
my $version_correct = $match->{version} eq $tversion; |
95
|
4
|
|
|
|
|
9
|
my $plats_size_ok = scalar(@plats_match) == scalar(@$platz); |
96
|
4
|
|
|
|
|
19
|
my $plats_are_same = |
97
|
|
|
|
|
|
|
scalar(@plats_match) == |
98
|
|
|
|
|
|
|
scalar(uniq((@plats_match, @$platz))) |
99
|
|
|
|
|
|
|
; #XXX THIS IS WRONG, WHAT IF WE HAVE NO PLATZ |
100
|
4
|
|
66
|
|
|
17
|
my $plats_correct = $plats_size_ok && $plats_are_same; |
101
|
|
|
|
|
|
|
|
102
|
4
|
100
|
100
|
|
|
19
|
if ($name_correct && $version_correct && $plats_correct) { |
|
|
|
100
|
|
|
|
|
103
|
1
|
|
|
|
|
27
|
print |
104
|
|
|
|
|
|
|
"# Not going to execute $test, it already has results in elasticsearch for this version and platform\n"; |
105
|
1
|
|
|
|
|
10
|
next; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
3
|
|
|
|
|
17
|
push(@tests_filtered, $test); |
109
|
|
|
|
|
|
|
} |
110
|
4
|
|
|
|
|
18
|
return @tests_filtered; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub get_test_replay { |
114
|
2
|
|
|
2
|
1
|
15313
|
my ($self, $tversion, $platz, @tests) = @_; |
115
|
|
|
|
|
|
|
|
116
|
2
|
50
|
|
|
|
11
|
return @tests unless $self->_has_results(); |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
17
|
my @tests_filtered; |
119
|
2
|
|
|
|
|
7
|
foreach my $test (@tests) { |
120
|
|
|
|
|
|
|
my %q = ( |
121
|
|
|
|
|
|
|
index => $self->{index}, |
122
|
4
|
|
|
|
|
40
|
body => { |
123
|
|
|
|
|
|
|
query => { |
124
|
|
|
|
|
|
|
query_string => { |
125
|
|
|
|
|
|
|
query => qq{name: "$test" AND version: "$tversion"}, |
126
|
|
|
|
|
|
|
}, |
127
|
|
|
|
|
|
|
}, |
128
|
|
|
|
|
|
|
size => 1 |
129
|
|
|
|
|
|
|
}, |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
|
132
|
4
|
|
|
|
|
14
|
foreach my $plat (@$platz) { |
133
|
2
|
|
|
|
|
11
|
$q{body}{query}{query_string}{query} .= qq{ AND platform: "$plat"}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
4
|
|
|
|
|
22
|
my $docs = $self->{handle}->search(%q); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
#OK, check if this document we got back *actually* matched |
139
|
4
|
100
|
|
|
|
30
|
if (!scalar(@{$docs->{hits}->{hits}})) { |
|
4
|
|
|
|
|
17
|
|
140
|
2
|
|
|
|
|
9
|
push( |
141
|
|
|
|
|
|
|
@tests_filtered, |
142
|
|
|
|
|
|
|
{name => $test, status => 'UNTESTED', body => ''} |
143
|
|
|
|
|
|
|
); |
144
|
2
|
|
|
|
|
12
|
next; |
145
|
|
|
|
|
|
|
} |
146
|
2
|
|
|
|
|
13
|
push(@tests_filtered, $docs->{hits}->{hits}->[0]->{_source}); |
147
|
|
|
|
|
|
|
} |
148
|
2
|
|
|
|
|
13
|
return @tests_filtered; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _has_results { |
152
|
2
|
|
|
2
|
|
843
|
my ($self) = @_; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $res = $self->{handle}->search( |
155
|
|
|
|
|
|
|
index => $self->{index}, |
156
|
2
|
|
|
|
|
19
|
body => { |
157
|
|
|
|
|
|
|
query => {match_all => {}}, |
158
|
|
|
|
|
|
|
sort => {id => {order => "desc"}}, |
159
|
|
|
|
|
|
|
size => 1 |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
|
163
|
2
|
|
|
|
|
18
|
my $hits = $res->{hits}->{hits}; |
164
|
2
|
100
|
|
|
|
15
|
return 0 unless scalar(@$hits); |
165
|
|
|
|
|
|
|
|
166
|
1
|
|
|
|
|
7
|
return $res->{hits}->{total}; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |