Expand description
v7.12.1 — full-text search lexer / stemmer.
Powers to_tsvector, plainto_tsquery, to_tsquery, and
friends. Two configs are supported in v7.12:
simple— lowercase + tokenise; no stopwords, no stemming.english— lowercase + tokenise + drop PG-standard english stopwords + Porter v1 stem.
Other configs (spanish, german, russian, …) error with
EvalError::TypeMismatch carrying the unsupported-config name
so callers see the same shape as ::regtype rejection.
Porter stemmer implementation follows the original 1980 Algorithm; corner-case behaviour matches Snowball english v1 (the variant PG also uses).
Structs§
- Token
- v7.39 (round 651) — a typed token, PG-shaped.
Enums§
- Token
Type - Tokenise on Unicode word boundaries — anything that is not an
alphanumeric scalar value (or
_) splits the token. Lowercases each emitted token. v7.39 (round 651) — PG’s token types, asts_token_type('default')publishes them. Only the ones SPG’s parser actually produces are here; the numbering is PG’s sopg_ts_config_map.maptokentypeandts_debug.aliasagree with it. - TsConfig
- v7.12.1 — supported tokeniser configs.
- TsDict
- The two dictionaries SPG has (round 650).
Constants§
- DEFAULT_
RANK_ WEIGHTS - PG default weights: D=0.1, C=0.2, B=0.4, A=1.0.
Functions§
- apply_
rank_ norm - v7.38 (read01, T12.1) — apply PG’s ranking normalization bitmask to a raw
rank. Flags are applied in PG’s order over the tsvector’s total position
count (
len) and distinct-lexeme count (uniq): 1 → /log2(len+1) · 2 → /len · 8 → /uniq · 16 → /log2(uniq+1) · 32 → r/(r+1) (flag 4, the cover-extent distance, is cover-density only and handled by the caller.) Verified against live PG 18.4. - is_
english_ stopword - PG’s standard english stopword list (
tsearch_data/english.stop). Subset of the 127 words in PG 17’s distribution — verbatim. - phraseto_
tsquery - v7.12.1 —
phraseto_tsquery(config, text): same tokenise + stem, but preserve order — fold into nested phrase nodes whose<N>distance is the position gap between surviving lexemes. Dropped stopwords still advance the position counter (as into_tsvector), so'cats and dogs'yields'cat' <2> 'dog', matching PG. - plainto_
tsquery - v7.12.1 —
plainto_tsquery(config, text): tokenise + stem, fold the surviving lexemes into an AND tree. ReturnsEvalError::TypeMismatchonly for an unsupported config — an all-stopwords input becomes an emptyTerm("")so the caller can detect it. - porter_
stem - to_
tsquery - v7.12.1 —
to_tsquery(config, text): explicit operator syntax over already-stemmed terms. Reuses the v7.12.0 external-form parser, then walks each leaf throughporter_stem(when the config isenglish). ReturnsTypeMismatchon malformed input. - to_
tsvector - v7.12.1 — tokenise + (optionally) stem
textinto a sorted + deduped lexeme set with merged positions. Each token’s position is 1-based and clamped at 16383 (PG18-measured, round 753: a 20k-word document’s positions top out at 16383 — theMAXENTRYPOS - 1clamp — while every lexeme is still recorded). - tokenize
- The old tokenizer, kept for callers that want bare words.
- tokenize_
typed - v7.39 (round 651) — split
textthe way PG’s default parser does. - ts_
query_ matches - v7.12.2 — evaluate
tsvector @@ tsquery. Walks the query AST treating each leaf as “does the vector contain this lexeme”. Phrase semantics: the v7.12.2 implementation honours the<N>distance — both operand terms must appear with their positions exactlyNapart in the vector. Higher-arity phrase chains nest asPhrase(Phrase(a,b,1), c, 1), so the match recursion folds position sets across the AND of the chain (a fully general n-gram match in a single pass). - ts_rank
- v7.12.2 —
ts_rank(vec, q)basic form. Score is the sum of per-matched-lexeme weight factors divided by1 + log(unique terms in query). Matches PG’sts_rankwith default normalisation flag 0. - ts_
rank_ cd - v7.12.2 —
ts_rank_cd(vec, q)cover-density variant. Higher score when matched lexemes cluster closer together; defaults to a per-lexeme contribution divided by the average gap between matched positions. Returns 0 when no terms match. - websearch_
to_ tsquery - v7.12.1 —
websearch_to_tsquery(config, text): Google-style syntax. Quoted phrases → phrase node;OR(case-insensitive) → OR; leading-→ NOT; otherwise AND.
Type Aliases§
- Rank
Weights - v7.38 (read01, T12.1) — a ts_rank weight array in PG order
[D, C, B, A].