line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Solr::Response; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
80651
|
use Moo; |
|
10
|
|
|
|
|
9328
|
|
|
10
|
|
|
|
|
70
|
|
4
|
|
|
|
|
|
|
|
5
|
10
|
|
|
10
|
|
4430
|
use Types::Standard qw(Object HashRef Maybe InstanceOf ArrayRef); |
|
10
|
|
|
|
|
60842
|
|
|
10
|
|
|
|
|
87
|
|
6
|
10
|
|
|
10
|
|
12388
|
use WebService::Solr::Document; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
275
|
|
7
|
10
|
|
|
10
|
|
4132
|
use Data::Page; |
|
10
|
|
|
|
|
46537
|
|
|
10
|
|
|
|
|
53
|
|
8
|
10
|
|
|
10
|
|
3962
|
use Data::Pageset; |
|
10
|
|
|
|
|
9395
|
|
|
10
|
|
|
|
|
103
|
|
9
|
10
|
|
|
10
|
|
6120
|
use JSON::XS (); |
|
10
|
|
|
|
|
41816
|
|
|
10
|
|
|
|
|
6722
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'raw_response' => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => Object, |
14
|
|
|
|
|
|
|
handles => { |
15
|
|
|
|
|
|
|
status_code => 'code', |
16
|
|
|
|
|
|
|
status_message => 'message', |
17
|
|
|
|
|
|
|
is_success => 'is_success', |
18
|
|
|
|
|
|
|
is_error => 'is_error' |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'content' => ( is => 'lazy', isa => HashRef ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'docs' => |
25
|
|
|
|
|
|
|
( is => 'lazy', isa => ArrayRef ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
around docs => sub { |
28
|
|
|
|
|
|
|
my ($orig, $self, @args) = @_; |
29
|
|
|
|
|
|
|
my $ret = $self->$orig(@args); |
30
|
|
|
|
|
|
|
return wantarray ? @$ret : $ret; |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'pager' => ( is => 'lazy', isa => Maybe[InstanceOf['Data::Page']] ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has '_pageset_slide' => |
36
|
|
|
|
|
|
|
( is => 'rw', isa => Maybe[InstanceOf['Data::Pageset']], predicate => 1 ); |
37
|
|
|
|
|
|
|
has '_pageset_fixed' => |
38
|
|
|
|
|
|
|
( is => 'rw', isa => Maybe[InstanceOf['Data::Pageset']], predicate => 1 ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub BUILDARGS { |
41
|
21
|
|
|
21
|
1
|
41410
|
my ( $self, $res ) = @_; |
42
|
21
|
|
|
|
|
317
|
return { raw_response => $res }; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _build_content { |
46
|
19
|
|
|
19
|
|
7042
|
my $self = shift; |
47
|
19
|
|
|
|
|
128
|
my $content = $self->raw_response->content; |
48
|
19
|
100
|
|
|
|
1177
|
return {} unless $content; |
49
|
2
|
|
|
|
|
3
|
my $rv = eval { JSON::XS::decode_json( $content ) }; |
|
2
|
|
|
|
|
23
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
### JSON::XS throw an exception, but kills most of the content |
52
|
|
|
|
|
|
|
### in the diagnostic, making it hard to track down the problem |
53
|
2
|
50
|
|
|
|
5
|
die "Could not parse JSON response: $@ $content" if $@; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
28
|
return $rv; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _build_docs { |
59
|
1
|
|
|
1
|
|
10
|
my $self = shift; |
60
|
1
|
|
|
|
|
14
|
my $struct = $self->content; |
61
|
|
|
|
|
|
|
|
62
|
1
|
50
|
|
|
|
9
|
return unless exists $struct->{ response }->{ docs }; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
11
|
return [ map { WebService::Solr::Document->new( %$_ ) } |
65
|
1
|
|
|
|
|
2
|
@{ $struct->{ response }->{ docs } } ]; |
|
1
|
|
|
|
|
3
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _build_pager { |
69
|
2
|
|
|
2
|
|
812
|
my $self = shift; |
70
|
2
|
|
|
|
|
31
|
my $struct = $self->content; |
71
|
|
|
|
|
|
|
|
72
|
2
|
50
|
|
|
|
26
|
return unless exists $struct->{ response }->{ numFound }; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
5
|
my $rows = $struct->{ responseHeader }->{ params }->{ rows }; |
75
|
2
|
50
|
|
|
|
4
|
$rows = 10 unless defined $rows; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# do not generate a pager for queries explicitly requesting no rows |
78
|
2
|
100
|
|
|
|
17
|
return if $rows == 0; |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
8
|
my $pager = Data::Page->new; |
81
|
1
|
|
|
|
|
63
|
$pager->total_entries( $struct->{ response }->{ numFound } ); |
82
|
1
|
|
|
|
|
10
|
$pager->entries_per_page( $rows ); |
83
|
1
|
|
|
|
|
46
|
$pager->current_page( $struct->{ response }->{ start } / $rows + 1 ); |
84
|
1
|
|
|
|
|
27
|
return $pager; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub pageset { |
88
|
5
|
|
|
5
|
1
|
3657
|
my $self = shift; |
89
|
5
|
|
|
|
|
11
|
my %args = @_; |
90
|
|
|
|
|
|
|
|
91
|
5
|
|
100
|
|
|
17
|
my $mode = $args{ 'mode' } || 'fixed'; |
92
|
5
|
|
|
|
|
9
|
my $meth = "_pageset_" . $mode; |
93
|
5
|
|
|
|
|
7
|
my $pred = "_has" . $meth; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
### use a cached version if possible |
96
|
5
|
100
|
|
|
|
57
|
return $self->$meth if $self->$pred; |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
5
|
my $pager = $self->_build_pageset( @_ ); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
### store the result |
101
|
2
|
|
|
|
|
46
|
return $self->$meth( $pager ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _build_pageset { |
105
|
2
|
|
|
2
|
|
10
|
my $self = shift; |
106
|
2
|
|
|
|
|
39
|
my $struct = $self->content; |
107
|
|
|
|
|
|
|
|
108
|
2
|
50
|
|
|
|
16
|
return unless exists $struct->{ response }->{ numFound }; |
109
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
5
|
my $rows = $struct->{ responseHeader }->{ params }->{ rows }; |
111
|
2
|
50
|
|
|
|
4
|
$rows = 10 unless defined $rows; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# do not generate a pager for queries explicitly requesting no rows |
114
|
2
|
100
|
|
|
|
5
|
return if $rows == 0; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $pager = Data::Pageset->new( |
117
|
|
|
|
|
|
|
{ total_entries => $struct->{ response }->{ numFound }, |
118
|
|
|
|
|
|
|
entries_per_page => $rows, |
119
|
1
|
|
|
|
|
12
|
current_page => $struct->{ response }->{ start } / $rows + 1, |
120
|
|
|
|
|
|
|
pages_per_set => 10, |
121
|
|
|
|
|
|
|
mode => 'fixed', # default, or 'slide' |
122
|
|
|
|
|
|
|
@_, |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
|
126
|
1
|
|
|
|
|
271
|
return $pager; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub facet_counts { |
130
|
0
|
|
|
0
|
1
|
0
|
return shift->content->{ facet_counts }; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub spellcheck { |
134
|
0
|
|
|
0
|
1
|
0
|
return shift->content->{ spellcheck }; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub solr_status { |
138
|
17
|
|
|
17
|
1
|
257
|
return shift->content->{ responseHeader }->{ status }; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub ok { |
142
|
17
|
|
|
17
|
1
|
49
|
my $status = shift->solr_status; |
143
|
17
|
|
33
|
|
|
755
|
return defined $status && $status == 0; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
10
|
|
|
10
|
|
157
|
no Moo; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
180
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |