繁体   English   中英

PostgreSQL中带有tsquery的奇怪行为,前缀为lexemes

[英]Strange behavior with tsquery in PostgreSQL with prefix-lexemes

当我使用'a:*'(也是'i:*','s:*','t:*')

SELECT id FROM mv_fulltextsearch1 WHERE to_tsvector(text) @@ to_tsquery('a:*') LIMIT 50;

永远占用并打印以下PostgreSQL输出很多

NOTICE:  text-search query contains only stop words or doesn't contain lexemes, ignored

但是当我使用'b:*'时(与':*'前面的任何其他单个字母相同)

SELECT id FROM mv_fulltextsearch1 WHERE to_tsvector(text) @@ to_tsquery('b:*') LIMIT 50;

一切都好

a,i,s和t是某种特殊字符吗? 我怎样才能逃脱它们/修复这种奇怪的行为?

使用to_tsvector('simple', text)to_tsquery('simple', 'a:*')

原因是“英语”regconfig删除了停用词 ,“a”被认为是停用词

但是,'simple'regconfig不会删除停用词

https://www.postgresql.org/docs/current/static/textsearch-controls.html#textsearch-parsing-queries

此外,*可以附加到词位以指定前缀匹配:

https://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES

当基本tsquery输入以面值取得标记时,to_tsquery使用指定或默认配置将每个标记规范化为一个lexeme,并根据配置丢弃任何停用单词的标记。

这让我得出一个结论,你的to_tsquery抛出一个作为停止的单词,保持NO TEXT来查询...(参见上面文档中the rat and cat的例子)

(((请不要问什么停用词为t)))

例如,如果你(没有to_tsquery ,因此停止不被丢弃的话)

with c(t) as (values('a an also at bond'),('but by illegal'),('I in it aligator'))
select t,to_tsvector(t) @@ ('a:*')::tsquery from c;

         t         | ?column?
-------------------+----------
 a an also at bond | t
 but by illegal    | f
 I in it aligator  | t
(3 rows)

它会工作......

关于停用词的参考:

-bash-4.2$ grep "^t$" /usr/share/pgsql93/tsearch_data/english.stop
t

t是一个...但我的英语知识温和缺乏理解为什么

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM