postgresql postgres 全文搜索,如运算符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4588717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:28:25  来源:igfitidea点击:

postgres full text search like operator

postgresql

提问by user373201

what is the query to use to search for text that matches the like operator.

用于搜索与 like 运算符匹配的文本的查询是什么。

I am asking about full text search query, which is of the form

我问的是全文搜索查询,它的形式

 SELECT * FROM eventlogging WHERE description_tsv @@ plainto_tsquery('mess');   

I want results with "message" as well but right not it does not return anything

我也想要带有“消息”的结果,但不是它不返回任何内容

回答by a_horse_with_no_name

If I read the description in the manualcorrectly, you'll need to use to_tsquery()instead of plainto_tsquery together with a wildcard to allow prefix matching:

如果我正确阅读了手册中描述,则需要使用to_tsquery()而不是 plainto_tsquery 和通配符来允许前缀匹配:

SELECT * 
FROM eventlogging 
WHERE description_tsv @@ to_tsquery('mess:*');

回答by Michael Irigoyen

You can use LIKEfor exact case matches or ILIKEfor case insensitive. Use the %as your wildcard.

您可以LIKE用于完全大小写匹配或ILIKE不区分大小写。将%用作您的通配符。

This will match anything with 'SomeThing' in it (case sensitive).

这将匹配其中包含“SomeThing”的任何内容(区分大小写)。

SELECT * FROM table WHERE name LIKE '%SomeThing%'

This will match anything ending with "ing" (case insensitive).

这将匹配以“ing”(不区分大小写)结尾的任何内容。

SELECT * FROM table WHERE name ILIKE '%ing'