Solr/Document.pm

filter: Statementstmt 17.8% 13 / 73 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 18.7% 3 / 16 Podpod 91.6% 11 / 12 totaltotal 19.4% 27 / 139 CC 21 SCAR 25.8
CC
21
Cov
12%
addField
30.0
boost
20.0
addFields
20.0
CRAP 13.2
« Solr/Result.pm ↑ Summary Solr/Tables.pm »
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::Document;{
13 6 our $VERSION = '1.12';
14 }
15  
16  
17 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 6 ▶use Log::Report qw/solr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 #--------------------
23  
24 0 ▶sub new(@) { my $c = shift; (bless {}, $c)->init({@_}) }
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
25  
26 sub init($)
27 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
28  
29 0 ▶ $self->{ASD_boost} = $args->{boost} || 1.0;
Condition0%0/2
$args->{'boost'} || 1.0
l!l
00
MC/DC0%0/1
$args->{'boost'} || 1.0
$args->{'boost'}
Truth table0%0/2
A
A= $args->{'boost'}
Aresult
11
00
30 0 $self->{ASD_fields} = []; # ordered
31 0 $self->{ASD_fields_h} = {}; # grouped by name
32 0 $self->addFields($args->{fields});
33 0 $self;
34 }
35  
36  
37 sub fromResult($$)
38 0 ▶{ my ($class, $data, $rank) = @_;
Subroutine fromResult: not called CC=3 SCAR=24.8
Pod documented
39 0 my (@f, %fh);
40  
41 0 ▶ while(my($k, $v) = each %$data)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$data) 0 0 0
42 0 ▶ { my @v = map +{name => $k, content => $_}, ref $v eq 'ARRAY' ? @$v : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
43 0 push @f, @v;
44 0 $fh{$k} = \@v;
45 }
46  
47 0 my $self = $class->new;
48 0 $self->{ASD_rank} = $rank;
49 0 $self->{ASD_fields} = \@f;
50 0 $self->{ASD_fields_h} = \%fh;
51 0 $self;
52 }
53  
54 #--------------------
55  
56 sub boost(;$)
57 0 ▶{ my $self = shift;
Subroutine boost: not called CC=4 SCAR=30.0
Pod documented
58 0 ▶ @_ or return $self->{ASD_boost};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"ASD_boost"} 0 0 0
59 0 ▶ my $f = $self->field(shift) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $f = $self->field(shift()) or return 0 0 0
60 0 ▶ @_ ? $f->{boost} = shift : $f->{boost};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
61 }
62  
63 0 ▶sub fieldNames() { my %c; $c{$_->{name}}++ for shift->fields; sort keys %c }
Subroutine fieldNames: not called CC=2 SCAR=17.9
Pod documented
64  
65  
66 0 ▶sub uniqueId() { $_[0]->content($Apache::Solr::uniqueKey) }
Subroutine uniqueId: not called CC=1 SCAR=6.9
Pod documented
67  
68  
69 0 ▶sub rank() { $_[0]->{ASD_rank} }
Subroutine rank: not called CC=1 SCAR=6.9
Pod documented
70  
71  
72 sub fields(;$)
73 0 ▶{ my $self = shift;
Subroutine fields: not called CC=3 SCAR=24.8
Pod documented
74 0 my $f = $self->{ASD_fields};
75 0 ▶ @_ or return @$f;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return @$f 0 0 0
76 0 my $name = shift;
77 0 my $fh = $self->{ASD_fields_h}{$name}; # grouped by name
78 0 ▶ $fh ? @$fh : ();
Branch: 1 branch
BranchTrueFalseTotal
$fh ? : 0 0 0
79 }
80  
81  
82 sub field($)
83 0 ▶{ my $fh = $_[0]->{ASD_fields_h}{$_[1]};
Subroutine field: not called CC=2 SCAR=17.9
Pod documented
84 0 ▶ $fh ? $fh->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$fh ? : 0 0 0
85 }
86  
87  
88 sub content($)
89 0 ▶{ my $f = $_[0]->field($_[1]);
Subroutine content: not called CC=2 SCAR=17.9
Pod documented
90 0 ▶ $f ? $f->{content} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$f ? : 0 0 0
91 }
92  
93 6 our $AUTOLOAD;
94 sub AUTOLOAD
95 0 ▶{ my $self = shift;
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
96 0 (my $fn = $AUTOLOAD) =~ s/.*\:\://;
97  
98 0 ▶ $fn =~ /^_(.*)/ ? $self->content($1)
Branch: 2 branches
BranchTrueFalseTotal
$fn =~ /^_(.*)/ ? : 0 0 0
$fn eq 'DESTROY' ? : 0 0 0
99 : $fn eq 'DESTROY' ? undef
100 : panic "Unknown method $AUTOLOAD (hint: fields start with '_')";
101 }
102  
103  
104 sub addField($$%)
105 0 ▶{ my $self = shift;
Subroutine addField: not called CC=5 SCAR=34.0
Pod documented
106 0 my $name = shift;
107 0 ▶ defined $_[0] or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] or return 0 0 0
108  
109 my $field = { # important to minimalize copying of content
110 name => $name,
111 content => (
112 !ref $_[0] ? shift
113 0 ▶ : ref $_[0] eq 'SCALAR' ? ${shift()}
Branch: 2 branches
BranchTrueFalseTotal
!ref($_[0]) ? : 0 0 0
ref $_[0] eq 'SCALAR' ? : 0 0 0
114 : shift
115 ),
116 };
117 0 my %args = @_;
118 0 ▶ $field->{boost} = $args{boost} || 1.0;
Condition0%0/2
$args{'boost'} || 1.0
l!l
00
MC/DC0%0/1
$args{'boost'} || 1.0
$args{'boost'}
Truth table0%0/2
A
A= $args{'boost'}
Aresult
11
00
119 0 $field->{update} = $args{update};
120  
121 0 push @{$self->{ASD_fields}}, $field;
122 0 push @{$self->{ASD_fields_h}{$name}}, $field;
123 0 $field;
124 }
125  
126  
127 sub addFields($%)
128 0 ▶{ my ($self, $h, @args) = @_;
Subroutine addFields: not called CC=4 SCAR=30.0
Pod documented
129 # pass content by ref to avoid a copy of potentially huge field.
130 0 ▶ if(ref $h eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $h eq 'ARRAY') { } 0 0 0
131 0 ▶ { for(my $i=0; $i < @$h; $i+=2)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$h) 0 0 0
132 0 { $self->addField($h->[$i] => \$h->[$i+1], @args);
133 }
134 }
135 else
136 0 { $self->addField($_ => \$h->{$_}, @args) for sort keys %$h;
137 }
138 0 $self;
139 }
140  
141 6 1;
« Solr/Result.pm ↑ Summary Solr/Tables.pm »