| 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
MC/DC0%0/1
$args->{'boost'} || 1.0
$args->{'boost'}
Truth table0%0/2
A
A= $args->{'boost'}
| |||||||||||||||
| 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
| |||||||||||||||
| 42 | 0 | ▶ | { my @v = map +{name => $k, content => $_}, ref $v eq 'ARRAY' ? @$v : $v; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 59 | 0 | ▶ | my $f = $self->field(shift) or return; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 0 | ▶ | @_ ? $f->{boost} = shift : $f->{boost}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 76 | 0 | my $name = shift; | |||||||||||||
| 77 | 0 | my $fh = $self->{ASD_fields_h}{$name}; # grouped by name | |||||||||||||
| 78 | 0 | ▶ | $fh ? @$fh : (); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 114 | : shift | ||||||||||||||
| 115 | ), | ||||||||||||||
| 116 | }; | ||||||||||||||
| 117 | 0 | my %args = @_; | |||||||||||||
| 118 | 0 | ▶ | $field->{boost} = $args{boost} || 1.0; | ||||||||||||
|
Condition0%0/2
$args{'boost'} || 1.0
MC/DC0%0/1
$args{'boost'} || 1.0
$args{'boost'}
Truth table0%0/2
A
A= $args{'boost'}
| |||||||||||||||
| 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
| |||||||||||||||
| 131 | 0 | ▶ | { for(my $i=0; $i < @$h; $i+=2) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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; | |||||||||||||