Plucene/Search/Similarity.pm

filter: Statementstmt 100% 25 / 25 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 95.6% 44 / 46 CC 3 SCAR 4.4
CC
3
Cov
97%
norm
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« Plucene/Store/InputStream.pm ↑ Summary Plucene/Index/SegmentTermPositions.pm »
1 package Plucene::Search::Similarity;
2  
3 =head1 NAME
4  
5 Plucene::Search::Similarity - the score of a query
6  
7 =head1 DESCRIPTION
8  
9 The score of a query for a given document.
10  
11 =head1 METHODS
12  
13 =cut
14  
15 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 18 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶use POSIX qw(ceil);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =head2 norm
22  
23 my $norm = $sim->norm($num_term);
24  
25 =cut
26  
27 370 ▶sub norm {
Subroutine norm: called CC=3 SCAR=11.0
Pod documented
28 370 my ($self, $num_terms) = @_;
29 370 ▶ return 0 if not defined $num_terms or $num_terms == 0;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $num_terms or $num_terms == 0 1 369 370
Condition66%2/3
not defined $num_terms or $num_terms == 0
l!l&&r!l&&!r
10369
MC/DC50%1/2
not defined $num_terms or $num_terms == 0
not defined $num_terms $num_terms == 0
Truth table66%2/3
not(A) or B
A= not defined $num_termsB= $num_terms == 0
ABresult
1X1
011
000
30 369 return ceil(255 / sqrt($num_terms));
31 }
32  
33 =head2 byte_norm
34  
35 my $byte_norm = $sim->byte_norm($byte);
36  
37 =cut
38  
39 488 ▶sub byte_norm {
Subroutine byte_norm: called CC=1 SCAR=0.0
Pod documented
40 488 my ($self, $byte) = @_;
41 488 ord($byte) / 255;
42 }
43  
44 =head2 tf
45  
46 Computes a score factor based on a term or phrase's frequency in a document.
47  
48 =cut
49  
50 7240 ▶sub tf { my $self = shift; return sqrt(shift); }
Subroutine tf: called CC=1 SCAR=0.0
Pod documented
51  
52 =head2 idf
53  
54 Computes a score factor for a phrase.
55  
56 =cut
57  
58 222 ▶sub idf {
Subroutine idf: called CC=1 SCAR=0.0
Pod documented
59 222 my ($self, $tf, $docs) = @_;
60 222 my ($x, $y) = ($docs->doc_freq($tf), $docs->max_doc);
61 222 return 1 + log($y / (1 + $x));
62 }
63  
64 =head2 coord
65  
66 Computes a score factor based on the fraction of all query terms that
67 a document contains.
68  
69 =cut
70  
71 94 ▶sub coord { my ($self, $a, $b) = @_; $a / $b } # Duh.
Subroutine coord: called CC=1 SCAR=0.0
Pod documented
72  
73 18 1;
« Plucene/Store/InputStream.pm ↑ Summary Plucene/Index/SegmentTermPositions.pm »