Table 9.42, Table 9.43 and Table 9.44 summarize the functions and operators that are provided for full text searching. See Chapter 12 for a detailed explanation of PostgreSQL™'s text search facility.
Table 9.42. Text Search Operators
Operator Description Example(s) |
---|
tsvector
tsquery Does tsvector match tsquery? (The arguments can be given in either order.)
|
text
Does text string, after implicit invocation
of
|
tsvector Concatenates two tsvectors. If both inputs contain lexeme positions, the second input's positions are adjusted accordingly.
|
tsquery ANDs two tsquerys together, producing a query that matches documents that match both input queries.
|
tsquery ORs two tsquerys together, producing a query that matches documents that match either input query.
|
Negates a tsquery, producing a query that matches documents that do not match the input query.
|
tsquery Constructs a phrase query, which matches if the two input queries match at successive lexemes.
|
tsquery Does first tsquery contain the second? (This considers only whether all the lexemes appearing in one query appear in the other, ignoring the combining operators.)
|
tsquery Is first tsquery contained in the second? (This considers only whether all the lexemes appearing in one query appear in the other, ignoring the combining operators.)
|
In addition to these specialized operators, the usual comparison operators shown in Table 9.1 are available 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.
Table 9.43. Text Search Functions
Function Description Example(s) |
---|
Converts an array of text strings to a tsvector.
The given strings are used as lexemes as-is, without further
processing. Array elements must not be empty strings
or
|
Returns the OID of the current default text search configuration (as set by default_text_search_config).
|
Returns the number of lexemes in the tsvector.
|
Returns the number of lexemes plus operators in the tsquery.
|
Converts text to a tsquery, normalizing words according to the specified or default configuration. Any punctuation in the string is ignored (it does not determine query operators). The resulting query matches documents containing all non-stopwords in the text.
|
Converts text to a tsquery, normalizing words according to the specified or default configuration. Any punctuation in the string is ignored (it does not determine query operators). The resulting query matches phrases containing all non-stopwords in the text.
|
Converts text to a tsquery, normalizing words according to the specified or default configuration. Quoted word sequences are converted to phrase tests. The word “or” is understood as producing an OR operator, and a dash produces a NOT operator; other punctuation is ignored. This approximates the behavior of some common web search tools.
|
Produces a representation of the indexable portion of
a tsquery. A result that is empty or
just
|
Assigns the specified
|
Assigns the specified
|
Removes positions and weights from the tsvector.
|
Converts text to a tsquery, normalizing words according to the specified or default configuration. The words must be combined by valid tsquery operators.
|
Converts text to a tsvector, normalizing words according to the specified or default configuration. Position information is included in the result.
|
Converts each string value in the JSON document to a tsvector, normalizing words according to the specified or default configuration. The results are then concatenated in document order to produce the output. Position information is generated as though one stopword exists between each pair of string values. (Beware that “document order” of the fields of a JSON object is implementation-dependent when the input is jsonb; observe the difference in the examples.)
|
Selects each item in the JSON document that is requested by
the
|
Removes any occurrence of the given
|
Removes any occurrences of the lexemes
in
|
Selects only elements with the given
|
Displays, in an abbreviated form, the match(es) for
the
|
Displays, in an abbreviated form, match(es) for
the
|
Computes a score showing how well
the
|
Computes a score showing how well
the
|
Replaces occurrences of
|
Replaces portions of the
|
Constructs a phrase query that searches
for matches of
|
Constructs a phrase query that searches
for matches of
|
Converts a tsvector to an array of lexemes.
|
Expands a tsvector into a set of rows, one per lexeme.
lexeme | positions | weights --------+-----------+--------- cat | {3} | {D} fat | {2,4} | {D,D} rat | {5} | {A}
|
All the text search functions that accept an optional regconfig argument will use the configuration specified by default_text_search_config when that argument is omitted.
The functions in Table 9.44 are listed separately because they are not usually used in everyday text searching operations. They are primarily helpful for development and debugging of new text search configurations.
Table 9.44. Text Search Debugging Functions
Function Description Example(s) |
---|
Extracts and normalizes tokens from
the
|
Returns an array of replacement lexemes if the input token is known to the dictionary, or an empty array if the token is known to the dictionary but it is a stop word, or NULL if it is not a known word. See Section 12.8.3 for details.
|
Extracts tokens from the
|
Extracts tokens from the
|
Returns a table that describes each type of token the named parser can recognize. See Section 12.8.2 for details.
|
Returns a table that describes each type of token a parser specified by OID can recognize. See Section 12.8.2 for details.
|
Executes the
|