Apache-Solr
view release on metacpan or search on metacpan
lib/Apache/Solr/Result.pm view on Meta::CPAN
# This code is part of Perl distribution Apache-Solr version 1.12.
# The POD got stripped from this file by OODoc version 3.06.
# For contributors see file ChangeLog.
# This software is copyright (c) 2012-2026 by Mark Overmeer.
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
package Apache::Solr::Result;{
our $VERSION = '1.12';
}
use warnings;
no warnings 'recursion'; # linked list of pages can get deep
use strict;
use Log::Report qw/solr/;
use Time::HiRes qw/time/;
use Scalar::Util qw/weaken/;
use Apache::Solr::Document ();
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Quotekeys = 0;
#--------------------
use overload
'""' => 'endpoint',
bool => 'success';
#--------------------
sub new(@) { my $c = shift; (bless {}, $c)->init({@_}) }
sub init($)
{ my ($self, $args) = @_;
my $p = $args->{params} || [];
($p, my $params) = ref $p eq 'HASH' ? ( +[%$p], $p ) : ($p, +{@$p});
$self->{ASR_params} = $p;
$self->{ASR_endpoint} = $args->{endpoint} or panic;
$self->{ASR_start} = time;
$self->request($args->{request});
$self->response($args->{response});
$self->{ASR_pages} = [ $self ]; # first has non-weak page-table
weaken $self->{ASR_pages}[0]; # no reference loop!
if($self->{ASR_core} = $args->{core}) { weaken $self->{ASR_core} }
$self->{ASR_next} = $params->{start} || 0;
$self->{ASR_seq} = $args->{sequential} || 0;
$self->{ASR_fpz} = $args->{_fpz};
$self;
}
# replace the pageset with a shared set.
sub _pageset($)
{ $_[0]->{ASR_pages} = $_[1];
weaken $_[0]->{ASR_pages}; # otherwise memory leak
}
#--------------------
sub start() { $_[0]->{ASR_start} }
sub endpoint() { $_[0]->{ASR_endpoint} }
sub params() { @{ $_[0]->{ASR_params}} }
sub core() { $_[0]->{ASR_core} }
sub sequential() { $_[0]->{ASR_seq} }
sub request(;$)
{ my $self = shift;
@_ && $_[0] or return $self->{ASR_request};
$self->{ASR_req_out} = time;
$self->{ASR_request} = shift;
}
sub response(;$)
{ my $self = shift;
@_ && $_[0] or return $self->{ASR_response};
$self->{ASR_resp_in} = time;
$self->{ASR_response} = shift;
}
sub decoded(;$)
{ my $self = shift;
@_ or return $self->{ASR_decoded};
$self->{ASR_dec_done} = time;
$self->{ASR_decoded} = shift;
}
sub elapse()
{ my $self = shift;
my $done = $self->{ASR_dec_done} or return;
$done = $self->{ASR_start};
}
sub success() { my $s = shift; $s->{ASR_success} ||= $s->solrStatus==0 }
sub solrStatus()
{ my $dec = shift->decoded or return 500;
$dec->{responseHeader}{status};
}
sub solrQTime()
{ my $dec = shift->decoded or return;
my $qtime = $dec->{responseHeader}{QTime};
defined $qtime ? $qtime/1000 : undef;
}
sub solrError()
{ my $dec = shift->decoded or return;
my $err = $dec->{error} || {};
my $msg = $err->{msg} || '';
$msg =~ s/\s*$//s;
length $msg ? $msg : ();
}
( run in 0.962 second using v1.01-cache-2.11-cpan-9789f410c06 )