在PostgreSQL中对子字符串进行全文搜索

编程入门 行业动态 更新时间:2024-10-25 00:24:34
本文介绍了在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中对子字符串进行全文搜索

本文发布于:2023-10-26 21:56:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531461.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对子   字符串   全文   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!