?
This document uses PHP Chinese website manual Release
Table 9-36, Table 9-37和 Table 9-38 概述了提供全文檢索函數(shù)和操作符。 詳見Chapter 12 PostgreSQL文本檢索功能的說明。
Table 9-36. 文本檢索操作符
操作符 | 描述 | 示例 | 結果 |
---|---|---|---|
@@ | tsvector匹配tsquery? | to_tsvector('fat cats ate rats') @@ to_tsquery('cat & rat') | t |
@@@ | deprecated synonym for@@ | to_tsvector('fat cats ate rats') @@@ to_tsquery('cat & rat') | t |
|| | 連接tsvectors | 'a:1 b:2'::tsvector || 'c:1 d:2 b:3'::tsvector | 'a':1 'b':2,5 'c':3 'd':4 |
&& | 和tsquerys 一起來與 | 'fat | rat'::tsquery && 'cat'::tsquery | ( 'fat' | 'rat' ) & 'cat' |
|| | 和tsquerys一起來或 | 'fat | rat'::tsquery || 'cat'::tsquery | ( 'fat' | 'rat' ) | 'cat' |
!! | tsquery非 | !! 'cat'::tsquery | !'cat' |
@> | tsquery包含另一個 ? | 'cat'::tsquery @> 'cat & rat'::tsquery | f |
<@ | tsquery包含于 ? | 'cat'::tsquery <@ 'cat & rat'::tsquery | t |
Note: tsquery的操作符只考慮兩個的查詢的情況,忽略組合的操作符。
除了顯示在表中的操作符,還定義了普通的B-tree比較操作符(=,<, 等)。它們對于文本檢索不是很有用,但是允許使用。 例如,建在這些類型列上的唯一索引。
Table 9-37. 文本檢索函數(shù)
函數(shù) | 返回類型 | 描述 | 示例 | 結果 |
---|---|---|---|---|
to_tsvector([configregconfig,]documenttext) |
tsvector | 減少文檔中的文本到tsvector | to_tsvector('english', 'The Fat Rats') | 'fat':2 'rat':3 |
length(tsvector) |
integer | tsvector的單詞數(shù) | length('fat:2,4 cat:3 rat:5A'::tsvector) | 3 |
setweight(tsvector,"char") |
tsvector | 給tsvector的每個元素賦予權值 | setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A') | 'cat':3A 'fat':2A,4A 'rat':5A |
strip(tsvector) |
tsvector | 刪除tsvector中的位置和權值 | strip('fat:2,4 cat:3 rat:5A'::tsvector) | 'cat' 'fat' 'rat' |
to_tsquery([configregconfig,]querytext) |
tsquery | 標準化單詞并轉換為tsquery | to_tsquery('english', 'The & Fat & Rats') | 'fat' & 'rat' |
plainto_tsquery([configregconfig,]querytext) |
tsquery | 產生tsquery忽略標點 | plainto_tsquery('english', 'The Fat Rats') | 'fat' & 'rat' |
numnode(tsquery) |
integer | tsquery中的單詞加上操作符的數(shù)量 | numnode('(fat & rat) | cat'::tsquery) | 5 |
querytree(querytsquery) |
text | 獲取tsquery可索引的部分 | querytree('foo & ! bar'::tsquery) | 'foo' |
ts_rank([weightsfloat4[],]vectortsvector,querytsquery[,normalizationinteger]) |
float4 | 文檔查詢排名 | ts_rank(textsearch, query) | 0.818 |
ts_rank_cd([weightsfloat4[],]vectortsvector,querytsquery[,normalizationinteger]) |
float4 | 排序文件查詢使用覆蓋密度 | ts_rank_cd('{0.1, 0.2, 0.4, 1.0}', textsearch, query) | 2.01317 |
ts_headline([configregconfig,]documenttext,querytsquery[,optionstext]) |
text | 顯示一個查詢的匹配項 | ts_headline('x y z', 'z'::tsquery) | x y <b>z</b> |
ts_rewrite(querytsquery,targettsquery,substitutetsquery) |
tsquery | 替換帶有查詢的替代目標 | ts_rewrite('a & b'::tsquery, 'a'::tsquery, 'foo|bar'::tsquery) | 'b' & ( 'foo' | 'bar' ) |
ts_rewrite(querytsquery,selecttext) |
tsquery | 從一條SELECT命令的替代目標做替換 | SELECT ts_rewrite('a & b'::tsquery, 'SELECT t,s FROM aliases') | 'b' & ( 'foo' | 'bar' ) |
get_current_ts_config() |
regconfig | 獲取文本檢索的默認配置 | get_current_ts_config() | english |
tsvector_update_trigger() |
trigger | 自動更新tsvector列的觸發(fā)器函數(shù) | CREATE TRIGGER ... tsvector_update_trigger(tsvcol, 'pg_catalog.swedish', title, body) | |
tsvector_update_trigger_column() |
trigger | 自動更新tsvector列的觸發(fā)器函數(shù) | CREATE TRIGGER ... tsvector_update_trigger_column(tsvcol, configcol, title, body) |
Note: 所有的文本檢索函數(shù),接受一個選項regconfig參數(shù)。當這個參數(shù)忽略,使用由default_text_search_config指定的配置。
Table 9-38單獨列出的函數(shù),因為他們通常不用在每天文本檢索操作。 它們有助于開發(fā)調試新文本檢索配置。
Table 9-38. 文本檢索調試函數(shù)
函數(shù) | 返回類型 | 描述 | 示例 | 結果 |
---|---|---|---|---|
ts_debug([configregconfig,]documenttext, OUTaliastext, OUTdescriptiontext, OUTtokentext, OUTdictionariesregdictionary[], OUTdictionaryregdictionary, OUTlexemestext[]) |
setof record | 測試一個配置 | ts_debug('english', 'The Brightest supernovaes') | (asciiword,"Word, all ASCII",The,{english_stem},english_stem,{}) ... |
ts_lexize(dictregdictionary,tokentext) |
text[] | 測試一個數(shù)據(jù)字典 | ts_lexize('english_stem', 'stars') | {star} |
ts_parse(parser_nametext,documenttext, OUTtokidinteger, OUTtokentext) |
setof record | 測試一個解析 | ts_parse('default', 'foo - bar') | (1,foo) ... |
ts_parse(parser_oidoid,documenttext, OUTtokidinteger, OUTtokentext) |
setof record | 測試一個解析 | ts_parse(3722, 'foo - bar') | (1,foo) ... |
ts_token_type(parser_nametext, OUTtokidinteger, OUTaliastext, OUTdescriptiontext) |
setof record | 由解析器獲取分詞類型的定義 | ts_token_type('default') | (1,asciiword,"Word, all ASCII") ... |
ts_token_type(parser_oidoid, OUTtokidinteger, OUTaliastext, OUTdescriptiontext) |
setof record | get token types defined by parser | ts_token_type(3722) | (1,asciiword,"Word, all ASCII") ... |
ts_stat(sqlquerytext,[weightstext,]OUTwordtext, OUTndocinteger, OUTnentryinteger) |
setof record | 獲取tsvector列的統(tǒng)計數(shù)據(jù) | ts_stat('SELECT vector from apod') | (foo,10,15) ... |