line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::Solr::Searcher; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
174
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
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}) |
33
|
|
|
|
|
|
|
->content->{response}{docs}; |
34
|
0
|
|
|
|
|
|
$start += $limit; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
0
|
|
|
|
|
if ($total) { |
37
|
0
|
|
|
|
|
|
$total--; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
0
|
|
|
|
my $hit = shift(@$hits) || return; |
40
|
0
|
|
|
|
|
|
delete $hit->{_bag}; |
41
|
0
|
|
|
|
|
|
$hit; |
42
|
0
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub slice { # TODO constrain total? |
46
|
0
|
|
|
0
|
0
|
|
my ($self, $start, $total) = @_; |
47
|
0
|
|
0
|
|
|
|
$start //= 0; |
48
|
0
|
|
|
|
|
|
$self->new( |
49
|
|
|
|
|
|
|
bag => $self->bag, |
50
|
|
|
|
|
|
|
query => $self->query, |
51
|
|
|
|
|
|
|
start => $self->start + $start, |
52
|
|
|
|
|
|
|
limit => $self->limit, |
53
|
|
|
|
|
|
|
total => $total, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub count { |
58
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
59
|
0
|
|
|
|
|
|
my $name = $self->bag->name; |
60
|
0
|
|
|
|
|
|
my $res = $self->bag->store->solr->search( |
61
|
|
|
|
|
|
|
$self->query, |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
rows => 0, |
64
|
|
|
|
|
|
|
fq => qq/_bag:"$name"/, |
65
|
|
|
|
|
|
|
facet => "false", |
66
|
|
|
|
|
|
|
spellcheck => "false", |
67
|
|
|
|
|
|
|
defType => "lucene", |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
); |
70
|
0
|
|
|
|
|
|
$res->content->{response}{numFound}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |