Plucene/Search/PhraseScorer.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 100% 14 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 2 / 2 totaltotal 97.5% 79 / 81 CC 9 SCAR 9.7
CC
9
Cov
99%
score
5.0
_pq_to_list
3.0
_phrase_freq
2.0
CRAP 2.6
« Plucene/Index/Term.pm ↑ Summary Plucene/Index/TermInfosReader.pm »
1 package Plucene::Search::PhraseScorer;
2  
3 =head1 NAME
4  
5 Plucene::Search::PhraseScorer - a phrase scorer
6  
7 =head1 SYNOPSIS
8  
9 # isa Plucene::Search::Scorer
10  
11 $scorer->score($results, $end);
12
13 =head1 DESCRIPTION
14  
15 This is the phrase scorer.
16  
17 =head1 METHODS
18  
19 =cut
20  
21 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 ▶use Tie::Array::Sorted;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 4 ▶use Plucene::Search::PhrasePositions;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 4 ▶use base qw(Plucene::Search::Scorer Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 0 ▶sub _phrase_freq { die "Abstract method" }
Subroutine _phrase_freq: not called CC=1 SCAR=6.9
31  
32 4 __PACKAGE__->mk_accessors(qw/ norms weight pq first last /);
33  
34 7 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
35 7 my $self = shift->SUPER::new(@_);
36 7 my @pq;
37 132 ▶ tie @pq, "Tie::Array::Sorted", sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
38 132 ▶ $_[0]->doc <=> $_[1]->doc
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->doc <=> $_[1]->doc or $_[0]->position <=> $_[1]->position 1 131 132
39 || $_[0]->position <=> $_[1]->position;
40 7 };
41  
42 7 for my $i (0 .. $#{ $self->{tps} }) {
43 push @pq,
44 Plucene::Search::PhrasePositions->new({
45 15 tp => $self->{tps}->[$i],
46 offset => $i
47 });
48 }
49  
50 7 $self->{pq} = \@pq;
51  
52 7 $self->_pq_to_list();
53 7 return $self;
54 }
55  
56 # Thread the array elements together into a linked list
57 80 ▶sub _pq_to_list {
Subroutine _pq_to_list: called CC=3 SCAR=11.0
58 80 my $self = shift;
59 80 $self->{first} = $self->{last} = undef;
60 80 ▶ while (@{ $self->{pq} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"pq"};}) 168 80 248
61 168 my $pp = shift @{ $self->{pq} };
62  
63 # If there's an entry already, put this after it
64 168 ▶ if ($self->{last}) { $self->last->next_in_list($pp); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'last'}) { } 88 80 168
65  
66 # Else, this is the first one
67 80 else { $self->first($pp); }
68  
69 # But it's definitely the last one
70 168 $self->last($pp);
71  
72 # And there's nothing after it, yet.
73 168 $pp->next_in_list(undef);
74 }
75 }
76  
77 =head2 score
78  
79 $scorer->score($results, $end);
80
81 =cut
82  
83 7 ▶sub score {
Subroutine score: called CC=5 SCAR=16.1
Pod documented
84 7 my ($self, $results, $end) = @_;
85 7 ▶ while ($self->last->doc < $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->last->doc < $end) 85 5 90
86 85 ▶ while ($self->first->doc < $self->last->doc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->first->doc < $self->last->doc) 89 83 172
87 89 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->first->doc < $self->last->doc and do { do { $self->first->next } } 7 89 96
88 96 $self->first->next;
89 } while $self->first->doc < $self->last->doc;
90 89 $self->_first_to_last;
91 89 ▶ return if $self->last->doc >= $end;
Branch: 1 branch
BranchTrueFalseTotal
if $self->last->doc >= $end 2 87 89
92 }
93 83 my $freq = $self->_phrase_freq;
94 83 $self->_score_it($freq, $self->first->doc, $results);
95 83 $self->last->next;
96 }
97 }
98  
99 277 ▶sub _first_to_last {
Subroutine _first_to_last: called CC=1 SCAR=0.0
100 277 my $self = shift;
101 277 $self->last->next_in_list($self->first);
102 277 $self->last($self->first);
103 277 $self->first($self->first->next_in_list);
104 277 $self->last->next_in_list(undef);
105 }
106  
107 4 1;
« Plucene/Index/Term.pm ↑ Summary Plucene/Index/TermInfosReader.pm »