我试图在文本搜索的基础上使用 to_tsquery()从数据库中检索数据。我能够获得完整单词搜索的结果,但无法获得子字符串的结果。
I am trying to retrieve the data from the a database using to_tsquery() on the basis of text search. I am able to get the results for complete word search but not for the substring.
示例:
SELECT * FROM snp_gene_context WHERE protein_name @@ to_tsquery('english','KIN') AND gene_dist='0';我能够获取包含单词 KIN11的行,但无法获取包含'激酶'。
I am able to get the rows containing the word 'KIN11' but I am unable to get rows containing 'Kinase'.
推荐答案全文搜索不适用于子字符串-仅适用于单词。
Full text search doesn't work on substrings — only words.
对于索引子字符串搜索,您需要使用 pg_trgm 扩展名。有关于更快<$ c $的好文章在 select * from depesz中使用 pg_trgm 进行c> like / ilike 搜索/ i>博客。不过,这是一个折衷方案–写得慢得多。
For indexed substring searches you'd need to use pg_trgm extension. There's a good article about faster like/ilike searches using pg_trgm on select * from depesz blog. There's a trade-of though — much slower writes.
更多推荐
在PostgreSQL中对子字符串进行全文搜索
发布评论