百科 / 函数百科 / 文本搜索函数和操作符
FUNCTION文本搜索函数和操作符
ts_debug
根据指定的或默认的文本检索配置从 document 中提取和正规化词元,并返回关于每个词元是如何处理的信息。详情参见第 12.8.1 节。
Extracts and normalizes tokens from the document according to the specified or default text search configuration, and returns information about how each token was processed.
文本搜索函数和操作符 引入 8.3 现存至 20 devel 1 条签名 0 次签名变更
- 分组
- 文本搜索函数和操作符
- 签名数
- 1 条
- 引入版本
- 8.3
- 状态
- 现存
- 签名变更
- 未变过
- 本版来源
- 英文原文
版本轨迹
相对 PostgreSQL 17 无变化。
说明
document 中提取和正规化词元,并返回关于每个词元是如何处理的信息。详情参见第 12.8.1 节。ts_debug ( [config regconfig, ] document text ) → setof record ( alias text, description text, token text, dictionaries regdictionary[], dictionary regdictionary, lexemes text[] )根据指定的或默认的文本检索配置从
document 中提取和正规化词元,并返回关于每个词元是如何处理的信息。详情参见第 12.8.1 节。签名
PostgreSQL 18.7 里 ts_debug 的 1 条签名,按上游手册顺序排列。参数名用斜体,类型用弱化色, 之后是返回类型。中文说明来自同版本手册与审阅译文,悬停可查看每条说明的来源。
-
ts_debug( [configregconfig, ]documenttext) →setof record(aliastext,descriptiontext,tokentext,dictionariesregdictionary[],dictionaryregdictionary,lexemestext[])根据指定的或默认的文本检索配置从document中提取和正规化词元,并返回关于每个词元是如何处理的信息。详情参见第 12.8.1 节。ts_debug('english', 'The Brightest supernovaes')(asciiword,"Word, all ASCII",The,{english_stem},english_stem,{}) ...
演化历史
相邻两个大版本之间的差异,新的在前。版本号链到该版的签名。
-
PostgreSQL 13 ← 12 手册重排
这一跳手册重排了函数表的写法,签名文本整体改写,只记函数的增删,不逐条比较签名。
-
PostgreSQL 8.3 ← 8.2 新增此函数
PostgreSQL 8.3 起可用
签名矩阵
每条签名在给出了签名的 20 个版本里的存在情况;方格指向该版的签名。只在正文里提到此函数、没有给出签名的版本不列进来,上面的版本轨迹里仍然有它们。签名文本在 PostgreSQL 13 前后写法不同,跨越那一跳的同一条签名会显示成两行。
存在 不存在
| 签名 | 8.3 | 8.4 | 9.0 | 9.1 | 9.2 | 9.3 | 9.4 | 9.5 | 9.6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ts_debug ( [ config regconfig, ] document text, OUT alias text, OUT description text, OUT token text, OUT dictionaries regdictionary[], OUT dictionary regdictionary, OUT lexemes text[] ) → setof record |
存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 |
ts_debug ( [ config regconfig, ] document text ) → setof record ( alias text, description text, token text, dictionaries regdictionary[], dictionary regdictionary, lexemes text[] ) |
不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 |
同组函数
| 函数 | 签名 | 主签名 | 版本变动 | 最近变更 |
|---|---|---|---|---|
array_to_tsvector |
1 | array_to_tsvector ( text[] ) → tsvector |
— | |
| 将文本字符串数组转换为 tsvector。给定的字符串被直接用作词位,不经过进一步处理。数组元素不得为空字符串或 NULL。 | 现存 | |||
get_current_ts_config |
1 | get_current_ts_config ( ) → regconfig |
— | |
| 返回当前默认文本检索配置的 OID(由 default_text_search_config 设置)。 | 现存 | |||
json_to_tsvector |
1 | json_to_tsvector ( [ config regconfig, ] document json, filter jsonb ) → tsvector |
— | |
| 选择 filter 请求的 JSON 文档中的每个项,并将每个项转换为 tsvector,根据指定的或默认配置对单词进行正规化。然后将结果按文档顺序连接起来以产生输出。位置信息就像在每对选定的项目之间存在一个停用词一样生成。(注意,当输入为 jsonb 时,JSON 对象字段的“文档顺序”取决于实现。)filter 必须是一个 jsonb 数组,其中包含 0 个或多个关键字:"string"(包括所有字符串值),"numeric"(包括所有数值),"boolean"(包括所有布尔值),"key"(包括所有键),或 "all"(包括以上所有内容)。作为一种特殊情况,该 filter 也可以是这些关键字之一的简单 JSON 值。 | 现存 | |||
jsonb_to_tsvector |
1 | jsonb_to_tsvector ( [ config regconfig, ] document jsonb, filter jsonb ) → tsvector |
— | |
| 选择 filter 请求的 JSON 文档中的每个项,并将每个项转换为 tsvector,根据指定的或默认配置对单词进行正规化。然后将结果按文档顺序连接起来以产生输出。位置信息就像在每对选定的项目之间存在一个停用词一样生成。(注意,当输入为 jsonb 时,JSON 对象字段的“文档顺序”取决于实现。)filter 必须是一个 jsonb 数组,其中包含 0 个或多个关键字:"string"(包括所有字符串值),"numeric"(包括所有数值),"boolean"(包括所有布尔值),"key"(包括所有键),或 "all"(包括以上所有内容)。作为一种特殊情况,该 filter 也可以是这些关键字之一的简单 JSON 值。 | 现存 | |||
numnode |
1 | numnode ( tsquery ) → integer |
— | |
| 返回 tsquery 中词位和操作符的数目。 | 现存 | |||
phraseto_tsquery |
1 | phraseto_tsquery ( [ config regconfig, ] query text ) → tsquery |
— | |
| 将文本转换为 tsquery,根据指定的或默认配置对单词进行正规化。字符串中的任何标点符号都会被忽略(它不决定查询操作符)。结果查询匹配包含文本中所有非停用词的短语。 | 现存 | |||
plainto_tsquery |
1 | plainto_tsquery ( [ config regconfig, ] query text ) → tsquery |
— | |
| 将文本转换为 tsquery,根据指定的或默认配置对单词进行正规化。字符串中的任何标点符号都会被忽略(它们不决定查询操作符)。生成的查询匹配包含文本中所有非停用词的文档。 | 现存 | |||
querytree |
1 | querytree ( tsquery ) → text |
— | |
| 生成 tsquery 中可索引部分的表示。结果为空或仅为 T 表示该查询不可索引。 | 现存 | |||
setweight |
2 | setweight ( vector tsvector, weight "char" ) → tsvector |
9.61 次 | |
| 将指定的 weight 赋给 vector 的每个元素。 | 现存 | |||
strip |
1 | strip ( tsvector ) → tsvector |
— | |
| 从 tsvector 中移除位置和权重。 | 现存 | |||
to_tsquery |
1 | to_tsquery ( [ config regconfig, ] query text ) → tsquery |
— | |
| 将文本转换为 tsquery,根据指定的或默认配置对单词进行正规化。单词必须由有效的 tsquery 操作符组合。 | 现存 | |||
to_tsvector |
3 | to_tsvector ( [ config regconfig, ] document text ) → tsvector |
101 次 | |
| 将文本转换为 tsvector,根据指定的或默认配置对单词进行正规化。结果中包含位置信息。 | 现存 | |||
ts_debug |
1 | ts_debug ( [ config regconfig, ] document text ) → setof record ( alias text, description text, token text, dictionaries regdictionary[], dictionary regdictionary, lexemes text[] ) |
— | |
| 根据指定的或默认的文本检索配置从 document 中提取和正规化词元,并返回关于每个词元是如何处理的信息。详情参见第 12.8.1 节。 | 现存 | |||
ts_delete |
2 | ts_delete ( vector tsvector, lexeme text ) → tsvector |
— | |
| 从 vector 中删除给定的 lexeme 的所有出现。lexeme 字符串被视为原样的词位,不经过进一步处理。 | 现存 | |||
ts_filter |
1 | ts_filter ( vector tsvector, weights "char"[] ) → tsvector |
— | |
| 只从 vector 中选择具有给定 weights 的元素。 | 现存 | |||
ts_headline |
3 | ts_headline ( [ config regconfig, ] document text, query tsquery [, options text ] ) → text |
101 次 | |
| 以缩略形式显示 query 在 document 中的匹配项;后者必须是原始文本,不能是 tsvector。在匹配查询之前,文档中的单词将根据指定的或默认配置进行正规化。第 12.3.4 节中讨论了该函数的使用,还描述了可用的 options。 | 现存 | |||
ts_lexize |
1 | ts_lexize ( dict regdictionary, token text ) → text[] |
— | |
| 如果词典识别输入词元,则返回由替换词位组成的数组;如果词典识别该词元,但它是停用词,则返回空数组;如果词典无法识别该词元,则返回 NULL。详情参见第 12.8.3 节。 | 现存 | |||
ts_parse |
2 | ts_parse ( parser_name text, document text ) → setof record ( tokid integer, token text ) |
— | |
| 使用指定名称的解析器从 document 中提取词元。详情参见第 12.8.2 节。 | 现存 | |||
ts_rank |
1 | ts_rank ( [ weights real[], ] vector tsvector, query tsquery [, normalization integer ] ) → real |
— | |
| 计算一个分数,显示 vector 与 query 的匹配程度。详情请参见第 12.3.3 节。 | 现存 | |||
ts_rank_cd |
1 | ts_rank_cd ( [ weights real[], ] vector tsvector, query tsquery [, normalization integer ] ) → real |
— | |
| 使用覆盖密度算法计算一个分数,显示 vector 与 query 的匹配程度。详情参见第 12.3.3 节。 | 现存 | |||
ts_rewrite |
2 | ts_rewrite ( query tsquery, target tsquery, substitute tsquery ) → tsquery |
— | |
| 在 query 中使用 substitute 替换出现的 target。详情参见第 12.4.2.1 节。 | 现存 | |||
ts_stat |
1 | ts_stat ( sqlquery text [, weights text ] ) → setof record ( word text, ndoc integer, nentry integer ) |
— | |
| 执行 sqlquery,该查询必须返回单个 tsvector 列,并返回数据中每个不同词位的统计信息。详情参见第 12.4.4 节。 | 现存 | |||
ts_token_type |
2 | ts_token_type ( parser_name text ) → setof record ( tokid integer, alias text, description text ) |
— | |
| 返回一个表,该表描述指定名称的解析器可以识别的每种类型的词元。详情参见第 12.8.2 节。 | 现存 | |||
tsquery_phrase |
2 | tsquery_phrase ( query1 tsquery, query2 tsquery ) → tsquery |
— | |
| 构造一个短语查询,在连续的词位上搜索 query1 和 query2 的匹配项(与<-> 操作符相同)。 | 现存 | |||
tsvector_to_array |
1 | tsvector_to_array ( tsvector ) → text[] |
— | |
| 将 tsvector 转换为词位的数组。 | 现存 | |||
unnest |
4 | unnest ( tsvector ) → setof record ( lexeme text, positions smallint[], weights text ) |
143 次 | |
| 将 tsvector 展开为一组行,每行对应一个词位。 | 现存 | |||
websearch_to_tsquery |
1 | websearch_to_tsquery ( [ config regconfig, ] query text ) → tsquery |
— | |
| 将文本转换为 tsquery,根据指定的或默认配置对单词进行正规化。带引号的单词序列被转换为短语测试。“or”一词产生 OR 操作符,短横线产生 NOT 操作符;其他标点符号会被忽略。这类似于一些常见网络搜索工具的行为。 | 现存 | |||