line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::Solr::Searcher; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
291
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'Catmandu::Iterable'; |
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 total => (is => 'ro'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub generator { |
15
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
16
|
0
|
|
|
|
|
|
my $store = $self->bag->store; |
17
|
0
|
|
|
|
|
|
my $name = $self->bag->name; |
18
|
0
|
|
|
|
|
|
my $limit = $self->limit; |
19
|
0
|
|
|
|
|
|
my $query = $self->query; |
20
|
0
|
|
|
|
|
|
my $fq = qq/_bag:"$name"/; |
21
|
|
|
|
|
|
|
sub { |
22
|
0
|
|
|
0
|
|
|
state $start = $self->start; |
23
|
0
|
|
|
|
|
|
state $total = $self->total; |
24
|
0
|
|
|
|
|
|
state $hits; |
25
|
0
|
0
|
|
|
|
|
if (defined $total) { |
26
|
0
|
0
|
|
|
|
|
return unless $total; |
27
|
|
|
|
|
|
|
} |
28
|
0
|
0
|
0
|
|
|
|
unless ($hits && @$hits) { |
29
|
0
|
0
|
0
|
|
|
|
if ($total && $limit > $total) { |
30
|
0
|
|
|
|
|
|
$limit = $total; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
|
$hits = $store->solr->search($query, {start => $start, rows => $limit, fq => $fq})->content->{response}{docs}; |
33
|
0
|
|
|
|
|
|
$start += $limit; |
34
|
|
|
|
|
|
|
} |
35
|
0
|
0
|
|
|
|
|
if ($total) { |
36
|
0
|
|
|
|
|
|
$total--; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
0
|
|
|
|
my $hit = shift(@$hits) || return; |
39
|
0
|
|
|
|
|
|
delete $hit->{_bag}; |
40
|
0
|
|
|
|
|
|
$hit; |
41
|
0
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub slice { # TODO constrain total? |
45
|
0
|
|
|
0
|
0
|
|
my ($self, $start, $total) = @_; |
46
|
0
|
|
0
|
|
|
|
$start //= 0; |
47
|
0
|
|
|
|
|
|
$self->new( |
48
|
|
|
|
|
|
|
bag => $self->bag, |
49
|
|
|
|
|
|
|
query => $self->query, |
50
|
|
|
|
|
|
|
start => $self->start + $start, |
51
|
|
|
|
|
|
|
limit => $self->limit, |
52
|
|
|
|
|
|
|
total => $total, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub count { |
57
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
58
|
0
|
|
|
|
|
|
my $name = $self->bag->name; |
59
|
0
|
|
|
|
|
|
my $res = $self->bag->store->solr->search($self->query, {rows => 0, fq => qq/_bag:"$name"/}); |
60
|
0
|
|
|
|
|
|
$res->content->{response}{numFound}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |