| 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 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 11 | ▶ | use constant SCORE_CACHE_SIZE => 32; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 11 | ▶ | use Plucene::Search::Similarity; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 11 | ▶ | use base qw(Plucene::Search::Scorer Class::Accessor::Fast); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 11 | __PACKAGE__->mk_accessors( | |||||||||
| 38 | qw(term_docs norms weight doc docs freqs | ||||||||||
| 39 | pointer pointer_max score_cache) | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | 211 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 43 | 211 | my $self = shift->SUPER::new(@_); | |||||||||
| 44 | 211 | ▶ | $self->weight(1) unless $self->weight(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 211 | $self->_compute_score_cache; | |||||||||
| 46 | 211 | $self->_refill_buffers; | |||||||||
| 47 | 211 | return $self; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 211 | ▶ | sub _compute_score_cache { | ||||||||
|
Subroutine
_compute_score_cache: called CC=2 SCAR=6.9
| |||||||||||
| 51 | 211 | my $self = shift; | |||||||||
| 52 | 211 | for (0 .. SCORE_CACHE_SIZE - 1) { | |||||||||
| 53 | 6752 | $self->{score_cache}[$_] = | |||||||||
| 54 | Plucene::Search::Similarity->tf($_) * $self->weight; | ||||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 450 | ▶ | sub _refill_buffers { | ||||||||
|
Subroutine
_refill_buffers: called CC=2 SCAR=6.9
| |||||||||||
| 59 | 450 | my $self = shift; | |||||||||
| 60 | 450 | $self->pointer(0); | |||||||||
| 61 | 450 | my ($docs, $freqs) = $self->{term_docs}->read; | |||||||||
| 62 | 450 | $self->docs($docs); | |||||||||
| 63 | 450 | $self->freqs($freqs); | |||||||||
| 64 | 450 | $self->pointer_max(scalar @$docs); | |||||||||
| 65 | 450 | ▶ | if ($self->{pointer_max} > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 239 | $self->doc($docs->[0]); | |||||||||
| 67 | } else { | ||||||||||
| 68 | 211 | $self->doc(~0); | |||||||||
| 69 | } # Sentinel | ||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | =head2 score | ||||||||||
| 73 | |||||||||||
| 74 | $term_scorer->score($hc, $end); | ||||||||||
| 75 | |||||||||||
| 76 | =cut | ||||||||||
| 77 | |||||||||||
| 78 | 211 | ▶ | sub score { | ||||||||
|
Subroutine
score: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 79 | 211 | my ($self, $hc, $end) = @_; | |||||||||
| 80 | 211 | my $d = $self->doc; | |||||||||
| 81 | 211 | ▶ | while ($d < $end) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 454 | my $f = $self->{freqs}->[ $self->{pointer} ]; | |||||||||
| 83 | 454 | $self->_score_it($f, $d, $hc); | |||||||||
| 84 | |||||||||||
| 85 | 454 | ▶ | if (++$self->{pointer} == $self->{pointer_max}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 239 | $self->_refill_buffers; | |||||||||
| 87 | 239 | ▶ | return if $self->doc == ~0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | } | ||||||||||
| 89 | 251 | $d = $self->{docs}[ $self->{pointer} ]; | |||||||||
| 90 | } | ||||||||||
| 91 | 8 | $self->doc($d); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 11 | 1; | |||||||||