Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://vo.astronet.ru/wiki/ranking?rev=1277154476
Дата изменения: Unknown Дата индексирования: Sun Apr 10 20:09:32 2016 Кодировка: Поисковые слова: п п п п п п п п п п п п п |
This is an old revision of the document!
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(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;