Postgresql - Functions and Operators 函数和运算 - Text Search

text search类型的相关函数和运算

Operator

Return Type

Description

Example

Result

@@

boolean

tsvector 是否匹配 tsquery 

to_tsvector('fat cats ate rats') @@ to_tsquery('cat & rat')

t

@@@

boolean

tsvector 是否匹配 tsquery 

to_tsvector('fat cats ate rats') @@@ to_tsquery('cat & rat')

t

||

tsvector

连接 tsvectors

'a:1 b:2'::tsvector || 'c:1 d:2 b:3'::tsvector

'a':1 'b':2,5 'c':3 'd':4

&&

tsquery

将两个tsquery用AND连接在一起

'fat | rat'::tsquery && 'cat'::tsquery

( 'fat' | 'rat' ) & 'cat'

||

tsquery

将两个tsquery用OR连接在一起

'fat | rat'::tsquery || 'cat'::tsquery

( 'fat' | 'rat' ) | 'cat'

!!

tsquery

对一个 tsquery取非

!! 'cat'::tsquery

!'cat'

<->

tsquery

tsquery followed by tsquery

to_tsquery('fat') <-> to_tsquery('rat')

'fat' <-> 'rat'

@>

boolean

一个tsquery是否包含另一个

'cat'::tsquery @> 'cat & rat'::tsquery

f

<@

boolean

一个tsquery是否包含另一个

'cat'::tsquery <@ 'cat & rat'::tsquery

t

Function

Return Type

Description

Example

Result

array_to_tsvector(text[])

tsvector

将数组转换为tsvector

array_to_tsvector('{fat,cat,rat}'::text[])

'cat' 'fat' 'rat'

get_current_ts_config()

regconfig

获取默认的text search配置

get_current_ts_config()

english

length(tsvector)

integer

获取tsvector之后的数量

length('fat:2,4 cat:3 rat:5A'::tsvector)

3

numnode(tsquery)

integer

词位+运算符号的数量

numnode('(fat & rat) | cat'::tsquery)

5

plainto_tsquery([ configregconfig , ] query text)

tsquery

根据英语,生成tsquery,去掉标点及辅助词(a the than then等)并且去掉复数

plainto_tsquery('english', 'The Fat Rats')

'fat' & 'rat'

phraseto_tsquery([ configregconfig , ] query text)

tsquery

根据英语,生成tsquery,去掉标点及辅助词(a the than then等)并且去掉复数

phraseto_tsquery('english', 'The Fat Rats')

'fat' <-> 'rat'

querytree(query tsquery)

text

得到可加索引的部分

querytree('foo & ! bar'::tsquery)

'foo'

setweight(vector tsvector,weight "char")

tsvector

对向量的每个元素赋权

setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A')

'cat':3A 'fat':2A,4A 'rat':5A

setweight(vector tsvector,weight "char", lexemes text[])

tsvector

将权重分配给列在列表中的向量元素

setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A', '{cat,rat}')

'cat':3A 'fat':2,4 'rat':5A

strip(tsvector)

tsvector

删除位置和比重

strip('fat:2,4 cat:3 rat:5A'::tsvector)

'cat' 'fat' 'rat'

to_tsquery([ config regconfig ,] query text)

tsquery

普通的词转换为tsquery

to_tsquery('english', 'The & Fat & Rats')

'fat' & 'rat'

to_tsvector([ config regconfig ,] document text)

tsvector

将文档文本还原为tsvector

to_tsvector('english', 'The Fat Rats')

'fat':2 'rat':3

to_tsvector([ config regconfig ,] document json(b))

tsvector

将文档中的每个字符串值还原为tsvector, 然后在文档顺序中连接这些字符串以生成单个tsvector

to_tsvector('english', '{"a": "The Fat Rats"}'::json)

'fat':2 'rat':3

ts_delete(vector tsvector,lexeme text)

tsvector

从tsvector中删除给定的词位

ts_delete('fat:2,4 cat:3 rat:5A'::tsvector, 'fat')

'cat':3 'rat':5A

ts_delete(vector tsvector,lexemes text[])

tsvector

从tsvector中删除任意词条的出现

ts_delete('fat:2,4 cat:3 rat:5A'::tsvector, ARRAY['fat','rat'])

'cat':3

ts_filter(vector tsvector,weights "char"[])

tsvector

仅从向量中选择具有矢量的元素

ts_filter('fat:2,4 cat:3b rat:5A'::tsvector, '{a,b}')

'cat':3B 'rat':5A

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

text

选择元素,对元素加粗

ts_headline('x y z', 'z'::tsquery)

x y <b>z</b>

ts_headline([ config regconfig,] document json(b), querytsquery [, options text ])

text

选择元素,对元素加粗

ts_headline('{"a":"x y z"}'::json, 'z'::tsquery)

{"a":"x y <b>z</b>"}

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

float4

查询排序文件

ts_rank(textsearch, query)

0.818

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

float4

使用覆盖密度查询的秩文档

ts_rank_cd('{0.1, 0.2, 0.4, 1.0}', textsearch, query)

2.01317

ts_rewrite(query tsquery, targettsquery, substitute tsquery)

tsquery

在查询中替换目标

ts_rewrite('a & b'::tsquery, 'a'::tsquery, 'foo|bar'::tsquery)

'b' & ( 'foo' | 'bar' )

ts_rewrite(query tsquery, selecttext)

tsquery

使用select查询命令替换目标和替代物

SELECT ts_rewrite('a & b'::tsquery, 'SELECT t,s FROM aliases')

'b' & ( 'foo' | 'bar' )

tsquery_phrase(query1 tsquery,query2 tsquery)

tsquery

使查询query1跟随query2 (same as <->operator)

tsquery_phrase(to_tsquery('fat'), to_tsquery('cat'))

'fat' <-> 'cat'

tsquery_phrase(query1 tsquery,query2 tsquery, distanceinteger)

tsquery

ts_query1 到ts_query2之间的距离

tsquery_phrase(to_tsquery('fat'), to_tsquery('cat'), 10)

'fat' <10> 'cat'

tsvector_to_array(tsvector)

text[]

将tsvector转换为词位的数组

tsvector_to_array('fat:2,4 cat:3 rat:5A'::tsvector)

{cat,fat,rat}

tsvector_update_trigger()

trigger

自动tsvector列更新的trigger

CREATE TRIGGER ... tsvector_update_trigger(tsvcol, 'pg_catalog.swedish', title, body)

 

tsvector_update_trigger_column()

trigger

自动tsvector列更新的trigger

CREATE TRIGGER ... tsvector_update_trigger_column(tsvcol, configcol, title, body)

 

unnest(tsvector, OUT lexemetext, OUT positions smallint[], OUT weights text)

setof record

将tsvectorz元素展开为一行行的内容

unnest('fat:2,4 cat:3 rat:5A'::tsvector)

(cat,{3},{D}) ...

Function

Return Type

Description

Example

Result

ts_debug([ config regconfig, ] documenttext, OUT alias text, OUT descriptiontext, OUT token text, OUT dictionariesregdictionary[], OUT dictionaryregdictionary, OUT lexemes text[])

setof record

测试配置

ts_debug('english', 'The Brightest supernovaes')

(asciiword,"Word, all ASCII",The,{english_stem},english_stem,{}) ...

ts_lexize(dict regdictionary, tokentext)

text[]

测试字典类型

ts_lexize('english_stem', 'stars')

{star}

ts_parse(parser_name text, documenttext, OUT tokid integer, OUT tokentext)

setof record

测试解析

ts_parse('default', 'foo - bar')

(1,foo) ...

ts_parse(parser_oid oid, document text, OUT tokid integer, OUT token text)

setof record

测试解析

ts_parse(3722, 'foo - bar')

(1,foo) ...

ts_token_type(parser_name text, OUTtokid integer, OUT alias text, OUTdescription text)

setof record

获取解析器定义的token类型

ts_token_type('default')

(1,asciiword,"Word, all ASCII") ...

ts_token_type(parser_oid oid, OUT tokidinteger, OUT alias text, OUTdescription text)

setof record

获取解析器定义的token类型

ts_token_type(3722)

(1,asciiword,"Word, all ASCII") ...

ts_stat(sqlquery text, [ weights text,] OUT word text, OUT ndoc integer, OUTnentry integer)

setof record

获取tsvector列的统计信息

ts_stat('SELECT vector from apod')

(foo,10,15) ...

猜你喜欢

转载自blog.csdn.net/chuckchen1222/article/details/81390319
今日推荐