Match a phrase ending in a prefix with full text search

后端 未结 4 1014
北恋
北恋 2020-12-31 14:36

I\'m looking for a way to emulate something like SELECT * FROM table WHERE attr LIKE \'%text%\' using a tsvector in PostgreSQL.

I\'ve created a tsvector

4条回答
  •  抹茶落季
    2020-12-31 14:58

    SELECT title
    FROM table
    WHERE title_tsv @@ to_tsquery('zend') and
    title_tsv @@ to_tsquery('fram:*')  
    

    is equivalent to:

    SELECT title
    FROM table
    WHERE title_tsv @@ to_tsquery('zend & fram:*')
    

    but of course that finds "Zend has no framework" as well.

    You could of course express a regular expression match against title after the tsquery match, but you would have to use explain analyze to make sure that was being executed after the tsquery instead of before.

提交回复
热议问题