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

【AntDB数据库 SQL语法专栏】——常用函数(9)文本搜索函数

北陌 2024-04-30
89

文本搜索函数

函数返回类型描述例子结果
array_to_tsvector(text[])tsvector把词位数组转换成tsvectorarray_to_tsvector(’{fat,cat,rat}’::text[])‘cat’ ‘fat’ ‘rat’
get_current_ts_config()regconfig获得默认文本搜索配置get_current_ts_config()english
length(tsvector)integertsvector中的词位数length(‘fat:2,4 cat:3 rat:5A’::tsvector)3
numnode(tsquery)integertsquery中词位外加操作符的数目numnode(’(fat & rat) | cat’::tsquery)5
plainto_tsquery([ config regconfig , ] query text)tsquery产生tsquery但忽略标点符号plainto_tsquery(‘english’, ‘The Fat Rats’)‘fat’ & ‘rat’
phraseto_tsquery([ config regconfig , ] query text)tsquery产生忽略标点搜索短语的tsqueryphraseto_tsquery(‘english’, ‘The Fat Rats’)‘fat’ <-> ‘rat’
websearch_to_tsquery([ config regconfig , ] query text)tsquery从一个Web搜索风格的查询产生tsquerywebsearch_to_tsquery(‘english’, ‘“fat rat” or rat’)‘fat’ <-> ‘rat’ | ‘rat’
querytree(query tsquery)text获得一个tsquery的可索引部分querytree(‘foo & ! bar’::tsquery)‘foo’
setweight(vector tsvector, weight “char”)tsvector为vector的每一个元素分配权重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为lexemes中列出的vector的元素分配权重setweight(‘fat:2,4 cat:3 rat:5B’::tsvector, ‘A’, ‘{cat,rat}’)‘cat’:3A ‘fat’:2,4 ‘rat’:5A
strip(tsvector)tsvector从tsvector中移除位置和权重strip(‘fat:2,4 cat:3 rat:5A’::tsvector)‘cat’ ‘fat’ ‘rat’
to_tsquery([ config regconfig , ] query text)tsquery规范化词并转换成tsqueryto_tsquery(‘english’, ‘The & Fat & Rats’)‘fat’ & ‘rat’
to_tsvector([ config regconfig , ] document text)tsvector缩减文档文本成tsvectorto_tsvector(‘english’, ‘The Fat Rats’)‘fat’:2 ‘rat’:3
to_tsvector([ config regconfig , ] document json(b))tsvector把该文档中的每个字符串值缩减成一个tsvector,然后将它们按在文档中的顺序串接起来形成一个tsvectorto_tsvector(‘english’, ‘{“a”: “The Fat Rats”}’::json)‘fat’:2 ‘rat’:3
json(b)_to_tsvector([ config regconfig, ] document json(b), filter json(b))tsvector把filter指定的文档中的每个值缩减为一个tsvector,然后把它们按照文档中的顺序串接起来形成一个tsvector。filter是一个jsonb数组,它列举哪些种类的元素需要被包括在结果tsvector中。json_to_tsvector(‘english’, ‘{“a”: “The Fat Rats”, “b”: 123}’::json, ‘[“string”, “numeric”]’)‘123’:5 ‘fat’:2 ‘rat’:3
ts_delete(vector tsvector, lexeme text)tsvector从vector中移除给定的lexemets_delete(‘fat:2,4 cat:3 rat:5A’::tsvector, ‘fat’)‘cat’:3 ‘rat’:5A
ts_delete(vector tsvector, lexemes text[])tsvector从vector中移除lexemes中词位的任何出现ts_delete(‘fat:2,4 cat:3 rat:5A’::tsvector, ARRAY[‘fat’,‘rat’])‘cat’:3
ts_filter(vector tsvector, weights “char”[])tsvector从vector中只选择带有给定权重的元素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 z
ts_headline([ config regconfig, ] document json(b), query tsquery [, options text ])text显示一个查询匹配ts_headline(’{“a”:“x y z”}’::json, ‘z’::tsquery){“a”:“x y z”}
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, target tsquery, substitute tsquery)tsquery在查询内用substitute替换targetts_rewrite(‘a & b’::tsquery, ‘a’::tsquery, ‘foo|bar’::tsquery)‘b’ & ( ‘foo’ | ‘bar’ )
ts_rewrite(query tsquery, select text)tsquery使用来自一个SELECT的目标和替换者进行替换SELECT ts_rewrite(‘a & b’::tsquery, ‘SELECT t,s FROM aliases’)‘b’ & ( ‘foo’ | ‘bar’ )
tsquery_phrase(query1 tsquery, query2 tsquery)tsquery制造搜索后面跟着query2的query1的查询(和<->操作符相同)tsquery_phrase(to_tsquery(‘fat’), to_tsquery(‘cat’))‘fat’ <-> ‘cat’
tsquery_phrase(query1 tsquery, query2 tsquery, distance integer)tsquery制造查询来搜索在query1后面最大距离distance上跟着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列更新的触发器函数CREATE TRIGGER … tsvector_update_trigger(tsvcol, ‘pg_catalog.swedish’, title, body)
tsvector_update_trigger_column()trigger用于自动tsvector列更新的触发器函数CREATE TRIGGER … tsvector_update_trigger_column(tsvcol, configcol, title, body)
unnest(tsvector, OUT lexeme text, OUT positions smallint[], OUT weights text)setof record把一个 tsvector 扩展成一组行unnest(‘fat:2,4 cat:3 rat:5A’::tsvector)(cat,{3},{D}) …


关于AntDB数据库

电信级核心交易数据库AntDB 数据库始于 2008年,在运营商的核心系统上,为全国 24个省份的 10亿多用户提供在线服务;具备高性能、弹性扩展、高可靠等产品特性,每秒可处理十多万笔核心交易,并保障系统平稳运行超 10年零故障。 AntDB 广泛应用于通信、金融、交通、能源、物联网等多个行业,在 200多个项目上成功落地。

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

评论