暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

华为openGauss 解析查询

华为高斯 2020-06-01
998

openGauss提供了函数to_tsquery和plainto_tsquery将查询转换为tsquery数据类型,to_tsquery提供比plainto_tsquery更多的功能,但对其输入要求更严格。

to_tsquery([ config regconfig, ] querytext text) returns tsquery

to_tsquery从querytext中创建一个tsquery,querytext必须由布尔运算符& (AND),| (OR)和! (NOT)分割的单个token组成。这些运算符可以用圆括弧分组。换句话说,to_tsquery输入必须遵循tsquery输入的通用规则,具体请参见文本搜索类型。不同的是基本tsquery以token表面值作为输入,而to_tsquery使用指定或默认分词器将每个token标准化成词素,并依据分词器丢弃属于停用词的token。例如:

``` postgres=# SELECT to_tsquery('english', 'The & Fat & Rats'); to_tsquery


'fat' & 'rat' (1 row) ```

像在基本tsquery中的输入一样,weight(s)可以附加到每个词素来限制它只匹配那些有相同weight(s)的tsvector词素。比如:

``` postgres=# SELECT to_tsquery('english', 'Fat | Rats:AB'); to_tsquery


'fat' | 'rat':AB (1 row) ```

同时,*也可以附加到词素来指定前缀匹配:

``` postgres=# SELECT to_tsquery('supern:A & star:AB'); to_tsquery


'supern':A & 'star':AB (1 row) ```

这样的词素将匹配tsquery中指定字符串和权重的项。

plainto_tsquery([ config regconfig, ] querytext text) returns tsquery

plainto_tsquery将未格式化的文本querytext变换为tsquery。类似于to_tsvector,文本被解析并且标准化,然后在存在的词之间插入&(AND)布尔算子。

比如:

``` postgres=# SELECT plainto_tsquery('english', 'The Fat Rats'); plainto_tsquery


'fat' & 'rat' (1 row) ```

请注意,plainto_tsquery无法识别布尔运算符、权重标签,或在其输入中的前缀匹配标签:

``` postgres=# SELECT plainto_tsquery('english', 'The Fat & Rats:C'); plainto_tsquery


'fat' & 'rat' & 'c' (1 row) ```

在这里,所有输入的标点符号作为空格符号丢弃。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

文集目录
暂无数据