There is a bug in ts_rank_cd. It does not correctly give rank when the query lexeme is the first one in the tsvector.
Example: select ts_rank_cd(to_tsvector('english', 'abc sdd'), plainto_tsquery('english', 'abc')); ts_rank_cd ------------ 0 select ts_rank_cd(to_tsvector('english', 'bcg abc sdd'), plainto_tsquery('english', 'abc')); ts_rank_cd ------------ 0.1 The problem is that the Cover finding algorithm ignores the lexeme at the 0th position, I have attached a patch which fixes it. After the patch the result is fine. select ts_rank_cd(to_tsvector('english', 'abc sdd'), plainto_tsquery( 'english', 'abc')); ts_rank_cd ------------ 0.1
--- postgresql-9.0.0/src/backend/utils/adt/tsrank.c 2010-01-02 22:27:55.000000000 +0530 +++ postgres-9.0.0-tsrankbugfix/src/backend/utils/adt/tsrank.c 2010-12-21 18:39:57.000000000 +0530 @@ -551,7 +551,7 @@ memset(qr->operandexist, 0, sizeof(bool) * qr->query->size); ext->p = 0x7fffffff; - ext->q = 0; + ext->q = -1; ptr = doc + ext->pos; /* find upper bound of cover from current position, move up */
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers