/usr/share/perl5/Plucene/Search/Similarity.pm is in libplucene-perl 1.25-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | package Plucene::Search::Similarity;
=head1 NAME
Plucene::Search::Similarity - the score of a query
=head1 DESCRIPTION
The score of a query for a given document.
=head1 METHODS
=cut
use strict;
use warnings;
use Carp qw(confess);
use POSIX qw(ceil);
=head2 norm
my $norm = $sim->norm($num_term);
=cut
sub norm {
my ($self, $num_terms) = @_;
return 0 if not defined $num_terms or $num_terms == 0;
return ceil(255 / sqrt($num_terms));
}
=head2 byte_norm
my $byte_norm = $sim->byte_norm($byte);
=cut
sub byte_norm {
my ($self, $byte) = @_;
ord($byte) / 255;
}
=head2 tf
Computes a score factor based on a term or phrase's frequency in a document.
=cut
sub tf { my $self = shift; return sqrt(shift); }
=head2 idf
Computes a score factor for a phrase.
=cut
sub idf {
my ($self, $tf, $docs) = @_;
my ($x, $y) = ($docs->doc_freq($tf), $docs->max_doc);
return 1 + log($y / (1 + $x));
}
=head2 coord
Computes a score factor based on the fraction of all query terms that
a document contains.
=cut
sub coord { my ($self, $a, $b) = @_; $a / $b } # Duh.
1;
|