Best way to use PostgreSQL full text search ranking
Following on from this answer I want to know what the best way to use PostgreSQL's built-in full text search is if I want to sort by rank, and limit to only matching queries. Let's assume a very simple table. CREATE TABLE pictures ( id SERIAL PRIMARY KEY, title varchar(300), ... ) or whatever. Now I want to search the title field. First I create an index: CREATE INDEX pictures_title ON pictures USING gin(to_tsvector('english', title)); Now I want to search for 'small dog' . This works: SELECT pictures.id, ts_rank_cd( to_tsvector('english', pictures.title), 'small dog' ) AS score FROM pictures