Plucene::Search::Similarity - the score of a query


Plucene documentation Contained in the Plucene distribution.

Index


Code Index:

NAME

Top

Plucene::Search::Similarity - the score of a query

DESCRIPTION

Top

The score of a query for a given document.

METHODS

Top

norm

	my $norm = $sim->norm($num_term);

byte_norm

	my $byte_norm = $sim->byte_norm($byte);

tf

Computes a score factor based on a term or phrase's frequency in a document.

idf

Computes a score factor for a phrase.

coord

Computes a score factor based on the fraction of all query terms that a document contains.


Plucene documentation Contained in the Plucene distribution.
package Plucene::Search::Similarity;

use strict;
use warnings;

use Carp qw(confess);
use POSIX qw(ceil);

sub norm {
	my ($self, $num_terms) = @_;
	return 0 if not defined $num_terms or $num_terms == 0;
	return ceil(255 / sqrt($num_terms));
}

sub byte_norm {
	my ($self, $byte) = @_;
	ord($byte) / 255;
}

sub tf { my $self = shift; return sqrt(shift); }

sub idf {
	my ($self, $tf, $docs) = @_;
	my ($x, $y) = ($docs->doc_freq($tf), $docs->max_doc);
	return 1 + log($y / (1 + $x));
}

sub coord { my ($self, $a, $b) = @_; $a / $b }    # Duh.

1;