| 1 | # This code is part of Perl distribution Apache-Solr version 1.12. | ||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.06. | ||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2012-2026 by Mark Overmeer. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Apache::Solr::Result;{ | ||||||||||||||||||||||||||||
| 13 | 6 | our $VERSION = '1.12'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | no warnings 'recursion'; # linked list of pages can get deep | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 6 | ▶ | use Log::Report qw/solr/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 6 | ▶ | use Time::HiRes qw/time/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 6 | ▶ | use Apache::Solr::Document (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 6 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 6 | $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||
| 30 | 6 | $Data::Dumper::Quotekeys = 0; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | #-------------------- | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | use overload | ||||||||||||||||||||||||||||
| 35 | 6 | ▶ | '""' => 'endpoint', | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 6 | bool => 'success'; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #-------------------- | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub new(@) { my $c = shift; (bless {}, $c)->init({@_}) } | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub init($) | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $p = $args->{params} || []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'params'} || []
MC/DC0%0/1
$args->{'params'} || []
$args->{'params'}
Truth table0%0/2
A
A= $args->{'params'}
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | ($p, my $params) = ref $p eq 'HASH' ? ( +[%$p], $p ) : ($p, +{@$p}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | $self->{ASR_params} = $p; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $self->{ASR_endpoint} = $args->{endpoint} or panic; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | $self->{ASR_start} = time; | |||||||||||||||||||||||||||
| 51 | 0 | $self->request($args->{request}); | |||||||||||||||||||||||||||
| 52 | 0 | $self->response($args->{response}); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | $self->{ASR_pages} = [ $self ]; # first has non-weak page-table | |||||||||||||||||||||||||||
| 55 | 0 | weaken $self->{ASR_pages}[0]; # no reference loop! | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if($self->{ASR_core} = $args->{core}) { weaken $self->{ASR_core} } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $self->{ASR_next} = $params->{start} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$params->{'start'} || 0
MC/DC0%0/1
$params->{'start'} || 0
$params->{'start'}
Truth table0%0/2
A
A= $params->{'start'}
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $self->{ASR_seq} = $args->{sequential} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'sequential'} || 0
MC/DC0%0/1
$args->{'sequential'} || 0
$args->{'sequential'}
Truth table0%0/2
A
A= $args->{'sequential'}
| |||||||||||||||||||||||||||||
| 60 | 0 | $self->{ASR_fpz} = $args->{_fpz}; | |||||||||||||||||||||||||||
| 61 | 0 | $self; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # replace the pageset with a shared set. | ||||||||||||||||||||||||||||
| 65 | sub _pageset($) | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | { $_[0]->{ASR_pages} = $_[1]; | ||||||||||||||||||||||||||
|
Subroutine
_pageset: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 0 | weaken $_[0]->{ASR_pages}; # otherwise memory leak | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | #-------------------- | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub start() { $_[0]->{ASR_start} } | ||||||||||||||||||||||||||
|
Subroutine
start: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub endpoint() { $_[0]->{ASR_endpoint} } | ||||||||||||||||||||||||||
|
Subroutine
endpoint: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub params() { @{ $_[0]->{ASR_params}} } | ||||||||||||||||||||||||||
|
Subroutine
params: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub core() { $_[0]->{ASR_core} } | ||||||||||||||||||||||||||
|
Subroutine
core: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub sequential() { $_[0]->{ASR_seq} } | ||||||||||||||||||||||||||
|
Subroutine
sequential: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub request(;$) | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
request: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | @_ && $_[0] or return $self->{ASR_request}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and $_[0]
MC/DC0%0/2
@_ and $_[0]
@_
$_[0]
Truth table0%0/3
A and B
A= @_B= $_[0]
| |||||||||||||||||||||||||||||
| 81 | 0 | $self->{ASR_req_out} = time; | |||||||||||||||||||||||||||
| 82 | 0 | $self->{ASR_request} = shift; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub response(;$) | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
response: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | @_ && $_[0] or return $self->{ASR_response}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and $_[0]
MC/DC0%0/2
@_ and $_[0]
@_
$_[0]
Truth table0%0/3
A and B
A= @_B= $_[0]
| |||||||||||||||||||||||||||||
| 88 | 0 | $self->{ASR_resp_in} = time; | |||||||||||||||||||||||||||
| 89 | 0 | $self->{ASR_response} = shift; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub decoded(;$) | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
decoded: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | @_ or return $self->{ASR_decoded}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | $self->{ASR_dec_done} = time; | |||||||||||||||||||||||||||
| 96 | 0 | $self->{ASR_decoded} = shift; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub elapse() | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
elapse: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $done = $self->{ASR_dec_done} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $done = $self->{ASR_start}; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub success() { my $s = shift; $s->{ASR_success} ||= $s->solrStatus==0 } | ||||||||||||||||||||||||||
|
Subroutine
success: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
$s->{"ASR_success"} ||= $s->solrStatus == 0
MC/DC0%0/2
$s->{"ASR_success"} ||= $s->solrStatus == 0
$s->{"ASR_success"}
$s->solrStatus == 0
Truth table0%0/3
A ||= B
A= $s->{"ASR_success"}B= $s->solrStatus == 0
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | sub solrStatus() | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | { my $dec = shift->decoded or return 500; | ||||||||||||||||||||||||||
|
Subroutine
solrStatus: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | $dec->{responseHeader}{status}; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub solrQTime() | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | { my $dec = shift->decoded or return; | ||||||||||||||||||||||||||
|
Subroutine
solrQTime: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | my $qtime = $dec->{responseHeader}{QTime}; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | defined $qtime ? $qtime/1000 : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub solrError() | ||||||||||||||||||||||||||||
| 121 | 0 | ▶ | { my $dec = shift->decoded or return; | ||||||||||||||||||||||||||
|
Subroutine
solrError: not called CC=5 SCAR=34.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my $err = $dec->{error} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$dec->{'error'} || {}
MC/DC0%0/1
$dec->{'error'} || {}
$dec->{'error'}
Truth table0%0/2
A
A= $dec->{'error'}
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | my $msg = $err->{msg} || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$err->{'msg'} || ''
MC/DC0%0/1
$err->{'msg'} || ''
$err->{'msg'}
Truth table0%0/2
A
A= $err->{'msg'}
| |||||||||||||||||||||||||||||
| 124 | 0 | $msg =~ s/\s*$//s; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | length $msg ? $msg : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub httpError() | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | { my $resp = shift->response or return; | ||||||||||||||||||||||||||
|
Subroutine
httpError: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | $resp->status_line; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub serverError() | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | { my $resp = shift->response or return; | ||||||||||||||||||||||||||
|
Subroutine
serverError: not called CC=5 SCAR=34.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $resp->code != 200 or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | my $ct = $resp->content_type; | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | $ct eq 'text/html' or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my $body = $resp->decoded_content || $resp->content; | ||||||||||||||||||||||||||
|
Condition0%0/3
$resp->decoded_content || $resp->content
MC/DC0%0/2
$resp->decoded_content || $resp->content
$resp->decoded_content
$resp->content
Truth table0%0/3
A || B
A= $resp->decoded_contentB= $resp->content
| |||||||||||||||||||||||||||||
| 140 | 0 | $body =~ s!.*<body>!!; | |||||||||||||||||||||||||||
| 141 | 0 | $body =~ s!</body>.*!!; | |||||||||||||||||||||||||||
| 142 | 0 | $body =~ s!</h[0-6]>|</p>!\n!g; # cheap reformatter | |||||||||||||||||||||||||||
| 143 | 0 | $body =~ s!</b>\s*!: !g; | |||||||||||||||||||||||||||
| 144 | 0 | $body =~ s!<[^>]*>!!gs; | |||||||||||||||||||||||||||
| 145 | 0 | $body; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub errors() | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
errors: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | my @errors; | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | if(my $h = $self->httpError) { push @errors, "HTTP error:", " $h" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if(my $a = $self->serverError) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | { $a =~ s/^/ /gm; | |||||||||||||||||||||||||||
| 155 | 0 | push @errors, "Server error:", $a; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if(my $s = $self->solrError) { push @errors, "Solr error:", " $s" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | join "\n", @errors, ''; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | #-------------------- | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | sub _responseData() | ||||||||||||||||||||||||||||
| 164 | 0 | ▶ | { my $dec = shift->decoded; | ||||||||||||||||||||||||||
|
Subroutine
_responseData: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $dec->{result} // $dec->{response}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$dec->{"result"} // $dec->{"response"}
MC/DC0%0/2
$dec->{"result"} // $dec->{"response"}
$dec->{"result"}
$dec->{"response"}
Truth table0%0/3
A // B
A= $dec->{"result"}B= $dec->{"response"}
| |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | sub nrSelected() | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | { my $results = shift->_responseData | ||||||||||||||||||||||||||
|
Subroutine
nrSelected: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | or panic "there are no results (yet)"; | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | $results->{numFound}; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | sub _docs($) | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | { my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_docs: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $docs = $data->{doc} // $data->{docs} // []; | ||||||||||||||||||||||||||
|
Condition0%0/5
($data->{"doc"} // $data->{"docs"}) // []
$data->{"doc"} // $data->{"docs"}
MC/DC0%0/2
($data->{"doc"} // $data->{"docs"}) // []
$data->{"doc"}
$data->{"docs"}
Truth table0%0/3
A // B
A= $data->{"doc"}B= $data->{"docs"}
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # Decoding XML without schema may give unexpect results | ||||||||||||||||||||||||||||
| 181 | 0 | ▶ | $docs = [ $docs ] if ref $docs eq 'HASH'; # when only one result | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | $docs; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | sub selected($%) | ||||||||||||||||||||||||||||
| 186 | 0 | ▶ | { my ($self, $rank, %options) = @_; | ||||||||||||||||||||||||||
|
Subroutine
selected: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $data = $self->_responseData | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | or panic __x"There are no results in the answer"; | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # start for next | ||||||||||||||||||||||||||||
| 191 | 0 | $self->{ASR_next} = $rank +1; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # in this page? | ||||||||||||||||||||||||||||
| 194 | 0 | my $startnr = $data->{start}; | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | if($rank >= $startnr) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | { my $docs = $self->_docs($data); | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | if($rank - $startnr < @$docs) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 0 | { my $doc = $docs->[$rank - $startnr]; | |||||||||||||||||||||||||||
| 199 | 0 | return Apache::Solr::Document->fromResult($doc, $rank); | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | $rank < $data->{numFound} # outside answer range | ||||||||||||||||||||||||||||
| 204 | 0 | ▶ | or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | my $pagenr = $self->selectedPageNr($rank); | |||||||||||||||||||||||||||
| 207 | 0 | ▶ | my $page = $self->selectedPage($pagenr) || $self->selectedPageLoad($pagenr, $self->core); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->selectedPage($pagenr) || $self->selectedPageLoad($pagenr, $self->core)
MC/DC0%0/2
$self->selectedPage($pagenr) || $self->selectedPageLoad($pagenr, $self->core)
$self->selectedPage($pagenr)
$self->selectedPageLoad($pagenr, $self->core)
Truth table0%0/3
A || B
A= $self->selectedPage($pagenr)B= $self->selectedPageLoad($pagenr, $self->core)
| |||||||||||||||||||||||||||||
| 208 | 0 | $page->selected($rank); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub nextSelected(%) | ||||||||||||||||||||||||||||
| 213 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
nextSelected: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | 0 | $self->selected($self->{ASR_next}, @_); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | sub highlighted($) | ||||||||||||||||||||||||||||
| 219 | 0 | ▶ | { my ($self, $doc) = @_; | ||||||||||||||||||||||||||
|
Subroutine
highlighted: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 220 | 0 | my $rank = $doc->rank; | |||||||||||||||||||||||||||
| 221 | 0 | my $pagenr = $self->selectedPageNr($rank); | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | my $hl = $self->selectedPage($pagenr)->decoded->{highlighting} | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | or error __x"there is no highlighting information in the result."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | Apache::Solr::Document->fromResult($hl->{$doc->uniqueId}, $rank); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | #-------------------- | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | sub terms($;$) | ||||||||||||||||||||||||||||
| 232 | 0 | ▶ | { my ($self, $field) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
terms: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 233 | 0 | ▶ | return $self->{ASR_terms}{$field} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | my $r = $self->{ASR_terms}{$field} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | or error __x"no search for terms on field {field} requested.", field => $field; | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | $r; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | #-------------------- | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub _to_msec($) { sprintf "%.1f", $_[0] * 1000 } | ||||||||||||||||||||||||||
|
Subroutine
_to_msec: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | sub showTimings(;$) | ||||||||||||||||||||||||||||
| 246 | 0 | ▶ | { my ($self, $fh) = @_; | ||||||||||||||||||||||||||
|
Subroutine
showTimings: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $fh ||= select; | ||||||||||||||||||||||||||
|
Condition0%0/3
$fh ||= select
MC/DC0%0/2
$fh ||= select
$fh
select
Truth table0%0/3
A ||= B
A= $fhB= select
| |||||||||||||||||||||||||||||
| 248 | 0 | my $req = $self->request; | |||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $to = $req ? $req->uri : '(not set yet)'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 0 | my $start = localtime $self->{ASR_start}; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | $fh->print("endpoint: $to\nstart: $start\n"); | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if($req) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | { my $reqsize = length($req->as_string); | |||||||||||||||||||||||||||
| 256 | 0 | my $reqcons = _to_msec($self->{ASR_req_out} - $self->{ASR_start}); | |||||||||||||||||||||||||||
| 257 | 0 | $fh->print("request: constructed $reqsize bytes in $reqcons ms\n"); | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if(my $resp = $self->response) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | 0 | { my $respsize = length($resp->as_string); | |||||||||||||||||||||||||||
| 262 | 0 | my $respcons = _to_msec($self->{ASR_resp_in} - $self->{ASR_req_out}); | |||||||||||||||||||||||||||
| 263 | 0 | $fh->print("response: received $respsize bytes after $respcons ms\n"); | |||||||||||||||||||||||||||
| 264 | 0 | my $ct = $resp->content_type; | |||||||||||||||||||||||||||
| 265 | 0 | my $status = $resp->status_line; | |||||||||||||||||||||||||||
| 266 | 0 | $fh->print(" $ct, $status\n"); | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if(my $dec = $self->decoded) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 0 | { my $decoder = _to_msec($self->{ASR_dec_done} - $self->{ASR_resp_in}); | |||||||||||||||||||||||||||
| 271 | 0 | $fh->print("decoding: completed in $decoder ms\n"); | |||||||||||||||||||||||||||
| 272 | 0 | ▶ | if(defined(my $qt = $self->solrQTime)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | { $fh->print(" solr processing took "._to_msec($qt)." ms\n"); | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if(my $error = $self->solrError) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 0 | { $fh->print(" solr reported error: '$error'\n"); | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | 0 | my $total = _to_msec($self->{ASR_dec_done} - $self->{ASR_start}); | |||||||||||||||||||||||||||
| 279 | 0 | $fh->print("elapse: $total ms total\n"); | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub selectedPageNr($) { my $pz = shift->fullPageSize; $pz ? int(shift() / $pz) : 0 } | ||||||||||||||||||||||||||
|
Subroutine
selectedPageNr: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub selectPages() { @{ $_[0]->{ASR_pages}} } | ||||||||||||||||||||||||||
|
Subroutine
selectPages: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | sub selectedPage($) { my $pages = shift->{ASR_pages}; $pages->[shift()] } | ||||||||||||||||||||||||||
|
Subroutine
selectedPage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | # The reloads page 0, which may have been purged by sequential reading. Besided, | ||||||||||||||||||||||||||||
| 292 | # the name does not cover its content: it's not the size of the select page but | ||||||||||||||||||||||||||||
| 293 | # the first page. | ||||||||||||||||||||||||||||
| 294 | sub selectedPageSize() | ||||||||||||||||||||||||||||
| 295 | 0 | ▶ | { my $result = shift->selectedPage(0)->_responseData || {}; | ||||||||||||||||||||||||||
|
Subroutine
selectedPageSize: not called CC=5 SCAR=34.0
Pod
documented
Condition0%0/2
(shift())->selectedPage(0)->_responseData || {}
MC/DC0%0/1
(shift())->selectedPage(0)->_responseData || {}
(shift())->selectedPage(0)->_responseData
Truth table0%0/2
A
A= (shift())->selectedPage(0)->_responseData
| |||||||||||||||||||||||||||||
| 296 | 0 | ▶ | my $docs = $result->{doc} // $result->{docs}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$result->{"doc"} // $result->{"docs"}
MC/DC0%0/2
$result->{"doc"} // $result->{"docs"}
$result->{"doc"}
$result->{"docs"}
Truth table0%0/3
A // B
A= $result->{"doc"}B= $result->{"docs"}
| |||||||||||||||||||||||||||||
| 297 | 0 | ▶ | ref $docs eq 'HASH' ? 1 : ref $docs eq 'ARRAY' ? scalar @$docs : 50; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 0 | ▶ | sub fullPageSize() { my $self = shift; $self->{ASR_fpz} ||= $self->_calc_page_size } | ||||||||||||||||||||||||||
|
Subroutine
fullPageSize: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
$self->{"ASR_fpz"} ||= $self->_calc_page_size
MC/DC0%0/2
$self->{"ASR_fpz"} ||= $self->_calc_page_size
$self->{"ASR_fpz"}
$self->_calc_page_size
Truth table0%0/3
A ||= B
A= $self->{"ASR_fpz"}B= $self->_calc_page_size
| |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | sub _calc_page_size() | ||||||||||||||||||||||||||||
| 304 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_calc_page_size: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 305 | 0 | my $docs = $self->_docs($self->selectedPage(0)->_responseData); | |||||||||||||||||||||||||||
| 306 | #warn "CALC PZ=", scalar @$docs; | ||||||||||||||||||||||||||||
| 307 | 0 | scalar @$docs; | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | sub selectedPageLoad($;$) | ||||||||||||||||||||||||||||
| 312 | 0 | ▶ | { my ($self, $pagenr, $client) = @_; | ||||||||||||||||||||||||||
|
Subroutine
selectedPageLoad: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | $client | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | or error __x"cannot autoload page {nr}, no client provided.", nr => $pagenr; | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 0 | my $fpz = $self->fullPageSize; | |||||||||||||||||||||||||||
| 317 | 0 | my @params = $self->replaceParams( { start => $pagenr * $fpz, rows => $fpz }, $self->params); | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 0 | my $seq = $self->sequential; | |||||||||||||||||||||||||||
| 320 | 0 | my $page = $client->select({sequential => $seq, _fpz => $fpz}, @params); | |||||||||||||||||||||||||||
| 321 | 0 | my $pages = $self->{ASR_pages}; | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | # put new page in shared table of pages | ||||||||||||||||||||||||||||
| 324 | 0 | $pages->[$pagenr] = $page; | |||||||||||||||||||||||||||
| 325 | 0 | $page->_pageset($pages); | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # purge cached previous pages when in sequential mode | ||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if($seq && $pagenr != 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$seq and $pagenr != 0
MC/DC0%0/2
$seq and $pagenr != 0
$seq
$pagenr != 0
Truth table0%0/3
A and B
A= $seqB= $pagenr != 0
| |||||||||||||||||||||||||||||
| 329 | 0 | { $pages->[$_] = undef for 0..$pagenr-1; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 0 | $page; | |||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | sub replaceParams($@) | ||||||||||||||||||||||||||||
| 337 | 0 | ▶ | { my ($self, $new) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
replaceParams: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 338 | 0 | my @out; | |||||||||||||||||||||||||||
| 339 | 0 | ▶ | while(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 0 | { my ($k, $v) = (shift, shift); | |||||||||||||||||||||||||||
| 341 | 0 | ▶ | $v = delete $new->{$k} if $new->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 0 | push @out, $k => $v; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | 0 | (@out, %$new); | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 6 | 1; | |||||||||||||||||||||||||||