line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::File::MediaHaven::Searcher; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
55694
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
136549
|
|
|
4
|
|
|
|
|
27
|
|
6
|
4
|
|
|
4
|
|
887
|
use Moo; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has bag => (is => 'ro', required => 1); |
9
|
|
|
|
|
|
|
has query => (is => 'ro', required => 1); |
10
|
|
|
|
|
|
|
has start => (is => 'ro', required => 1); |
11
|
|
|
|
|
|
|
has limit => (is => 'ro', required => 1); |
12
|
|
|
|
|
|
|
has sort => (is => 'ro', required => 0); |
13
|
|
|
|
|
|
|
has total => (is => 'ro'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub generator { |
16
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $mh = $self->bag->store->mh; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $query = $self->query; |
21
|
0
|
|
0
|
|
|
|
my $index = $self->start // 0; |
22
|
0
|
|
|
|
|
|
my $limit = $self->limit; |
23
|
0
|
|
|
|
|
|
my $sort = $self->sort; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $res = $mh->search($query, start => $index, num => $limit, sort => $sort); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub { |
28
|
0
|
|
|
0
|
|
|
state $results = $res->{mediaDataList}; |
29
|
0
|
|
|
|
|
|
state $num_of_results = $res->{totalNrOfResults}; |
30
|
0
|
|
|
|
|
|
state $total = $self->total; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if (defined $total) { |
33
|
0
|
0
|
|
|
|
|
return unless $total; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
0
|
|
|
|
if (defined($total) && defined($limit) && $limit > $total) { |
|
|
|
0
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$limit = $total; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if (@$results > 0) { |
|
|
0
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $hit = shift @$results; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$index++; |
44
|
0
|
0
|
|
|
|
|
$total-- if defined($total); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $self->hit2rec($hit); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ($index < $num_of_results) { |
49
|
0
|
|
|
|
|
|
my $res = $mh->search($query, start => $index, num => $limit, sort => $sort); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$results = $res->{mediaDataList}; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
$total-- if defined($total); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$index++; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $hit = shift @$results; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $self->hit2rec($hit); |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return undef; |
62
|
0
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub hit2rec { |
66
|
0
|
|
|
0
|
0
|
|
my ($self,$hit) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ($self->bag->store->id_fixer) { |
69
|
0
|
|
|
|
|
|
return $self->bag->store->id_fixer->fix($hit); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
|
my $id = $hit->{externalId}; |
73
|
0
|
|
|
|
|
|
return +{_id => $id}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub slice { |
78
|
0
|
|
|
0
|
0
|
|
my ($self, $start, $total) = @_; |
79
|
0
|
|
0
|
|
|
|
$start //= 0; |
80
|
0
|
|
|
|
|
|
$self->new( |
81
|
|
|
|
|
|
|
bag => $self->bag, |
82
|
|
|
|
|
|
|
query => $self->query, |
83
|
|
|
|
|
|
|
start => $self->start + $start, |
84
|
|
|
|
|
|
|
limit => $self->limit, |
85
|
|
|
|
|
|
|
sort => $self->sort, |
86
|
|
|
|
|
|
|
total => $total, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub count { |
91
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $mh = $self->bag->store->mh; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $query = $self->query; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $res = $mh->search($query); |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$res->{totalNrOfResults}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |