更新时间:2024-01-31 GMT+08:00
分享

文本检索函数

get_current_ts_config()

描述:获取文本检索的默认配置。

返回类型:regconfig

示例:

1
2
3
4
5
SELECT get_current_ts_config();
 get_current_ts_config 
-----------------------
 english
(1 row)

length(tsvector)

描述:tsvector类型词汇的单词数。

返回类型:integer

示例:

1
2
3
4
5
SELECT length('fat:2,4 cat:3 rat:5A'::tsvector);
 length 
--------
      3
(1 row)

numnode(tsquery)

描述:tsquery类型的单词加上操作符的数量。

返回类型:integer

示例:

1
2
3
4
5
SELECT numnode('(fat & rat) | cat'::tsquery);
 numnode 
---------
       5
(1 row)

plainto_tsquery([ config regconfig , ] query text)

描述:产生tsquery类型的词汇,并忽略标点。

返回类型:tsquery

示例:

1
2
3
4
5
SELECT plainto_tsquery('english', 'The Fat Rats');
 plainto_tsquery 
-----------------
 'fat' & 'rat'
(1 row)

querytree(query tsquery)

描述:获取tsquery类型的词汇可加索引的部分。

返回类型:text

示例:

1
2
3
4
5
SELECT querytree('foo & ! bar'::tsquery);
 querytree 
-----------
 'foo'
(1 row)

setweight(tsvector, "char")

描述:给tsvector类型的每个元素分配权值。

返回类型:tsvector

示例:

1
2
3
4
5
SELECT setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A');
           setweight           
-------------------------------
 'cat':3A 'fat':2A,4A 'rat':5A
(1 row)

strip(tsvector)

描述:删除tsvector类型单词中的position和权值。

返回类型:tsvector

示例:

1
2
3
4
5
SELECT strip('fat:2,4 cat:3 rat:5A'::tsvector);
       strip       
-------------------
 'cat' 'fat' 'rat'
(1 row)

to_tsquery([ config regconfig , ] query text)

描述:标准化单词,并转换为tsquery类型。

返回类型:tsquery

示例:

1
2
3
4
5
SELECT to_tsquery('english', 'The & Fat & Rats');
  to_tsquery   
---------------
 'fat' & 'rat'
(1 row)

to_tsvector([ config regconfig , ] document text)

描述:去除文件信息,并转换为tsvector类型。

返回类型:tsvector

示例:

1
2
3
4
5
SELECT to_tsvector('english', 'The Fat Rats');
   to_tsvector   
-----------------
 'fat':2 'rat':3
(1 row)

ts_headline([ config regconfig, ] document text, query tsquery [, options text ])

描述:高亮显示查询的匹配项。

返回类型:text

示例:

1
2
3
4
5
SELECT ts_headline('x y z', 'z'::tsquery);
 ts_headline  
--------------
 x y <b>z</b>
(1 row)

ts_rank([ weights float4[], ] vector tsvector, query tsquery [, normalization integer ])

描述:文档查询排名。

返回类型:float4

示例:

1
2
3
4
5
SELECT ts_rank('hello world'::tsvector, 'world'::tsquery);
 ts_rank  
----------
 .0607927
(1 row)

ts_rank_cd([ weights float4[], ] vector tsvector, query tsquery [, normalization integer ])

描述:排序文件查询使用覆盖密度。

返回类型:float4

示例:

1
2
3
4
5
SELECT ts_rank_cd('hello world'::tsvector, 'world'::tsquery);
 ts_rank_cd 
------------
          0
(1 row)

ts_rewrite(query tsquery, target tsquery, substitute tsquery)

描述:替换目标tsquery类型的单词。

返回类型:tsquery

示例:

1
2
3
4
5
SELECT ts_rewrite('a & b'::tsquery, 'a'::tsquery, 'foo|bar'::tsquery);
       ts_rewrite        
-------------------------
 'b' & ( 'foo' | 'bar' )
(1 row)

ts_rewrite(query tsquery, select text)

描述:使用SELECT命令的结果替代目标中tsquery类型的单词。

返回类型:tsquery

示例:

1
2
3
4
5
SELECT ts_rewrite('world'::tsquery, 'select ''world''::tsquery, ''hello''::tsquery');
 ts_rewrite 
------------
 'hello'
(1 row)
分享:

    相关文档

    相关产品