Документ взят из кэша поисковой машины. Адрес оригинального документа : http://vo.astronet.ru/wiki/ranking?rev=1277151756
Дата изменения: Unknown
Дата индексирования: Sun Apr 10 20:09:21 2016
Кодировка:

Поисковые слова: meteors
ranking [SAI Virtual Observatory - Wiki]

This is an old revision of the document!


Ranking search results

CREATE OR REPLACE FUNCTION my_rank (tsvector, tsquery) RETURNS float AS $$
my ($string, $query) = @_;
 
# Parse tsvector. Use only words, not positional information
my @vector = map /'(\w+)'/, split / /, $string;
 
# Parse tsquery, assuming it to be ORed only
$query =~ s/[()|'']/ /g;
$query =~ s/^\s+(.*?)\s+$/$1/;
my @query = split /\s+/, $query;
 
# Number of query terms in the vector
my $qlength = scalar(@query);
# Number of matched terms
my $qfound = scalar(scalar(map {my $q=$_; grep {/$q/} @vector} @query));
 
# The more matched terms - the better
my $rank_more = $qfound/$qlength;
# The less matched terms - the better
my $rank_less = ($qlength - $qfound + 1)/$qlength;
# Middle way - prefer both single and all matches
#my $rank_mid = 1 - $qfound*($qlength - $qfound + 1)/$qlength**2;
my $rank_mid = ($rank_more > $rank_less ? $rank_more : $rank_less);
 
RETURN $rank_mid;
$$ LANGUAGE plperl;
SELECT title, my_rank(fts, q) rank FROM apod, to_tsquery('english','sombrero|supernovae|milky|way|meteor') q WHERE fts @@ q ORDER BY rank DESC LIMIT 100;
ranking.1277151756.txt.gz · Last modified: 2010/06/22 00:22 by karpov
Back to top
SAI VO | Astronet | SAI MSU | Legal Information
RFBR