line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plucene::Search::TermScorer; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Plucene::Search::TermScorer - score terms |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# isa Plucene::Search::Scorer |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$term_scorer->score($hc, $end); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This is a Plucene::Search::Scorer subclass for scoring terms. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHODS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
11
|
|
|
11
|
|
63
|
use strict; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
397
|
|
22
|
11
|
|
|
11
|
|
60
|
use warnings; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
306
|
|
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
11
|
|
57
|
use constant SCORE_CACHE_SIZE => 32; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
714
|
|
25
|
|
|
|
|
|
|
|
26
|
11
|
|
|
11
|
|
61
|
use Plucene::Search::Similarity; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
280
|
|
27
|
|
|
|
|
|
|
|
28
|
11
|
|
|
11
|
|
57
|
use base qw(Plucene::Search::Scorer Class::Accessor::Fast); |
|
11
|
|
|
|
|
1012
|
|
|
11
|
|
|
|
|
11051
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 term_docs / norms / weight / doc / docs / freqs / pointer / |
31
|
|
|
|
|
|
|
pointer_max / score_cache |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Get / set these attributes |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
38
|
|
|
|
|
|
|
qw(term_docs norms weight doc docs freqs |
39
|
|
|
|
|
|
|
pointer pointer_max score_cache) |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
189
|
|
|
189
|
1
|
1312
|
my $self = shift->SUPER::new(@_); |
44
|
189
|
100
|
|
|
|
3296
|
$self->weight(1) unless $self->weight(); |
45
|
189
|
|
|
|
|
1898
|
$self->_compute_score_cache; |
46
|
189
|
|
|
|
|
1752
|
$self->_refill_buffers; |
47
|
189
|
|
|
|
|
2083
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _compute_score_cache { |
51
|
189
|
|
|
189
|
|
472
|
my $self = shift; |
52
|
189
|
|
|
|
|
638
|
for (0 .. SCORE_CACHE_SIZE - 1) { |
53
|
6048
|
|
|
|
|
37319
|
$self->{score_cache}[$_] = |
54
|
|
|
|
|
|
|
Plucene::Search::Similarity->tf($_) * $self->weight; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _refill_buffers { |
59
|
393
|
|
|
393
|
|
741
|
my $self = shift; |
60
|
393
|
|
|
|
|
1373
|
$self->pointer(0); |
61
|
393
|
|
|
|
|
3408
|
my ($docs, $freqs) = $self->{term_docs}->read; |
62
|
393
|
|
|
|
|
1629
|
$self->docs($docs); |
63
|
393
|
|
|
|
|
3814
|
$self->freqs($freqs); |
64
|
393
|
|
|
|
|
3866
|
$self->pointer_max(scalar @$docs); |
65
|
393
|
100
|
|
|
|
3188
|
if ($self->{pointer_max} > 0) { |
66
|
204
|
|
|
|
|
906
|
$self->doc($docs->[0]); |
67
|
|
|
|
|
|
|
} else { |
68
|
189
|
|
|
|
|
875
|
$self->doc(~0); |
69
|
|
|
|
|
|
|
} # Sentinel |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 score |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$term_scorer->score($hc, $end); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub score { |
79
|
189
|
|
|
189
|
1
|
739
|
my ($self, $hc, $end) = @_; |
80
|
189
|
|
|
|
|
687
|
my $d = $self->doc; |
81
|
189
|
|
|
|
|
1366
|
while ($d < $end) { |
82
|
347
|
|
|
|
|
867
|
my $f = $self->{freqs}->[ $self->{pointer} ]; |
83
|
347
|
|
|
|
|
1562
|
$self->_score_it($f, $d, $hc); |
84
|
|
|
|
|
|
|
|
85
|
347
|
100
|
|
|
|
6623
|
if (++$self->{pointer} == $self->{pointer_max}) { |
86
|
204
|
|
|
|
|
717
|
$self->_refill_buffers; |
87
|
204
|
100
|
|
|
|
1642
|
return if $self->doc == ~0; |
88
|
|
|
|
|
|
|
} |
89
|
163
|
|
|
|
|
702
|
$d = $self->{docs}[ $self->{pointer} ]; |
90
|
|
|
|
|
|
|
} |
91
|
5
|
|
|
|
|
25
|
$self->doc($d); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |