| The PostgreSQL 9.0 Reference Manual - Volume 1A - SQL Language Reference
by The PostgreSQL Global Development Group Paperback (6"x9"), 454 pages ISBN 9781906966041 RRP £14.95 ($19.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |
7.13 Text Search Functions and Operators
Table 7-36, Table 7-37 and Table 7-38 summarize the functions and operators that are provided for full text searching. See section 10 Full Text Search for a detailed explanation of PostgreSQL's text search facility.
| Operator | Description
|
@@ | tsvector matches tsquery ?e.g. to_tsvector('fat cats ate rats') @@ to_tsquery('cat & rat') => t
|
@@@ | deprecated synonym for @@e.g. to_tsvector('fat cats ate rats') @@@ to_tsquery('cat & rat') => t
|
|| | concatenate tsvectorse.g. 'a:1 b:2'::tsvector || 'c:1 d:2 b:3'::tsvector => 'a':1 'b':2,5 'c':3 'd':4
|
&& | AND tsquerys togethere.g. 'fat | rat'::tsquery && 'cat'::tsquery => ( 'fat' | 'rat' ) & 'cat'
|
|| | OR tsquerys togethere.g. 'fat | rat'::tsquery || 'cat'::tsquery => ( 'fat' | 'rat' ) | 'cat'
|
!! | negate a tsquerye.g. !! 'cat'::tsquery => !'cat'
|
@> | tsquery contains another ?e.g. 'cat'::tsquery @> 'cat & rat'::tsquery => f
|
<@ | tsquery is contained in ?e.g. 'cat'::tsquery <@ 'cat & rat'::tsquery => t
|
Note: The
tsquerycontainment operators consider only the lexemes listed in the two queries, ignoring the combining operators.
In addition to the operators shown in the table, the ordinary B-tree
comparison operators (=, <, etc) are defined
for types tsvector and tsquery. These are not very
useful for text searching but allow, for example, unique indexes to be
built on columns of these types.
| Function | Return Type | Description
|
| tsvector | reduce document text to tsvectore.g. to_tsvector('english', 'The Fat Rats') => 'fat':2 'rat':3
|
| integer | number of lexemes in tsvectore.g. length('fat:2,4 cat:3 rat:5A'::tsvector) => 3
|
| tsvector | assign weight to each element of tsvectore.g. setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A') => 'cat':3A 'fat':2A,4A 'rat':5A
|
| tsvector | remove positions and weights from tsvectore.g. strip('fat:2,4 cat:3 rat:5A'::tsvector) => 'cat' 'fat' 'rat'
|
| tsquery | normalize words and convert to tsquerye.g. to_tsquery('english', 'The & Fat & Rats') => 'fat' & 'rat'
|
| tsquery | produce tsquery ignoring punctuatione.g. plainto_tsquery('english', 'The Fat Rats') => 'fat' & 'rat'
|
| integer | number of lexemes plus operators in tsquerye.g. numnode('(fat & rat) | cat'::tsquery) => 5
|
| text | get indexable part of a tsquerye.g. querytree('foo & ! bar'::tsquery) => 'foo'
|
| float4 | rank document for query e.g. ts_rank(textsearch, query) => 0.818
|
| float4 | rank document for query using cover density e.g. ts_rank_cd('{0.1, 0.2, 0.4, 1.0}', textsearch, query) => 2.01317
|
| text | display a query match e.g. ts_headline('x y z', 'z'::tsquery) => x y <b>z</b>
|
| tsquery | replace target with substitute within query e.g. ts_rewrite('a & b'::tsquery, 'a'::tsquery, 'foo|bar'::tsquery) => 'b' & ( 'foo' | 'bar' )
|
| tsquery | replace using targets and substitutes from a SELECT commande.g. SELECT ts_rewrite('a & b'::tsquery, 'SELECT t,s FROM aliases') => 'b' & ( 'foo' | 'bar' )
|
| regconfig | get default text search configuration e.g. get_current_ts_config() => english
|
| trigger | trigger function for automatic tsvector column updatee.g. CREATE TRIGGER ... tsvector_update_trigger(tsvcol, 'pg_catalog.swedish', title, body) =>
|
| trigger | trigger function for automatic tsvector column updatee.g. CREATE TRIGGER ... tsvector_update_trigger_column(tsvcol, configcol, title, body) =>
|
Note: All the text search functions that accept an optional
regconfigargument will use the configuration specified bydefault_text_search_configwhen that argument is omitted.
The functions in Table 7-38 are listed separately because they are not usually used in everyday text searching operations. They are helpful for development and debugging of new text search configurations.
| Function | Return Type | Description
|
| setof record | test a configuration e.g. ts_debug('english', 'The Brightest supernovaes') => (asciiword,"Word, all ASCII",The,{english_stem},english_stem,{}) ...
|
| text[] | test a dictionary e.g. ts_lexize('english_stem', 'stars') => {star}
|
| setof record | test a parser e.g. ts_parse('default', 'foo - bar') => (1,foo) ...
|
| setof record | test a parser e.g. ts_parse(3722, 'foo - bar') => (1,foo) ...
|
| setof record | get token types defined by parser e.g. ts_token_type('default') => (1,asciiword,"Word, all ASCII") ...
|
| setof record | get token types defined by parser e.g. ts_token_type(3722) => (1,asciiword,"Word, all ASCII") ...
|
| setof record | get statistics of a tsvector columne.g. ts_stat('SELECT vector from apod') => (foo,10,15) ...
|
| ISBN 9781906966041 | The PostgreSQL 9.0 Reference Manual - Volume 1A - SQL Language Reference | See the print edition |