在PostgreSQL中对子字符串进行全文搜索 [英] Full text search on substring in PostgreSQL

查看:85
本文介绍了在PostgreSQL中对子字符串进行全文搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在文本搜索的基础上使用 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中对子字符串进行全文搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆