Best way to use PostgreSQL full text search ranking

后端 未结 3 1417
旧时难觅i
旧时难觅i 2021-02-01 23:33

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 q

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 00:28

    select *
    from (
        SELECT
            pictures.id,
            ts_rank_cd(to_tsvector('english', pictures.title), 
            to_tsquery('small dog')) AS score
        FROM pictures
    ) s
    WHERE score > 0
    ORDER BY score DESC
    

提交回复
热议问题