Full-Text Search
This page covers the PostgreSQL-style text search functions in src/query/fts.rs, the @@ operator and its index path, the MySQL, gRPC and REST routes into text search, the per-wire text scorers, and the Tantivy index in src/index/fulltext.rs that no wire or SQL path reaches. The posting-list layout of the tsvector GIN index is described in GIN: JSON, arrays and full-text postings and is not repeated here. The operator summary is in How it works.
What reaches what
| Entry point | Implementation | Uses an index |
|---|---|---|
SQL to_tsvector(...) @@ to_tsquery(...) on any SQL wire |
src/query/fts.rs plus engine dispatch |
Yes, the FTS GIN index when its key matches (gin.md) |
MySQL MATCH (...) AGAINST (...)
|
Rewritten to to_tsvector('simple', ...) @@ to_tsquery('simple', ...)
|
No (see below) |
SQL match_text(col, q)
|
Brute-force substring test | No |
gRPC Search
|
SELECT ... WHERE match_text(...) |
No |
REST /api/v1/search
|
SELECT ... WHERE col LIKE '%term%' |
No |
Elasticsearch match and related queries |
Lucene BM25 in src/protocol/elasticsearch/bm25.rs
|
No, statistics per query |
Neo4j db.index.fulltext.queryNodes
|
BM25 in src/protocol/bolt/fulltext.rs
|
No, scans the candidate set |
Redis FT.SEARCH TEXT filters |
Term match in src/protocol/redis/commands/search.rs
|
No, exact scan |
TantivyIndex, SimpleFullTextIndex
|
src/index/fulltext.rs |
Not wired |
(source: src/query/engine.rs, ts_match_values, try_fts_candidates; src/protocol/mysql/fulltext.rs, rewrite; src/protocol/grpc/wire.rs, search; src/protocol/http/routes.rs, full_text_search; src/index/mod.rs, IndexManager::create_fulltext_index)
MongoDB $text has no handler in the snapshot: a search of src/protocol/mongodb/ finds no $text operator. (source: src/protocol/mongodb/, no $text match)
Text processing (src/query/fts.rs)
Tokenizer
tokenize splits on any character that is not alphanumeric and not an apostrophe, lowercases with to_ascii_lowercase, trims leading and trailing apostrophes, and numbers positions from 1. (source: src/query/fts.rs, tokenize)
Because the document side lowercases ASCII only while the query side (normalize_word) uses full Unicode to_lowercase, a word with a non-ASCII uppercase letter (for example Ärger) is stored with its uppercase letter and searched in lowercase. Not verified: no test covers non-ASCII uppercase input. (source: src/query/fts.rs, tokenize, normalize_word)
Configurations
Only two configuration names change processing:
| Config argument | Stop words | Stemming |
|---|---|---|
english, pg_catalog.english
|
English list of about 100 words | Porter |
Anything else (simple, german, …) |
None | None |
| Missing, or not a string | Treated as english
|
Porter |
(source: src/query/fts.rs, is_english, english_stop_words; src/query/engine.rs, to_tsvector dispatch)
CREATE TEXT SEARCH CONFIGURATION is accepted and does nothing. Tested by test_fts_create_text_search_config_noop. (source: src/query/engine.rs, that test)
Stemmer
porter_stem implements the original Porter algorithm (steps 1a through 5b). Tested by test_porter_stem_basic and test_to_tsvector_english. (source: src/query/fts.rs, porter_stem)
In a query, a stop word still occupies its position slot, so phraseto_tsquery('the cat sat') keeps the gaps PostgreSQL keeps. (source: src/query/fts.rs, normalized_words)
tsvector format
A tsvector value is a text string in PostgreSQL's output form: lexemes in sorted order, each quoted, with positions and weights, for example 'cat':2A,5 'sat':3. Weight D is the default and is not printed. Positions are u16. (source: src/query/fts.rs, format_tsvector, parse_tsvector)
looks_like_tsvector decides whether a text operand is already a tsvector. cast_text implements ::tsvector and ::tsquery. (source: src/query/fts.rs, looks_like_tsvector, cast_text)
tsquery model
| Node | Printed as |
|---|---|
Lexeme { text, prefix, weights } |
'word', 'word':*, 'word':AB
|
And(l, r) |
l & r |
Or(l, r) |
l \| r |
Not(x) |
!x |
Phrase(l, r, distance) |
l <-> r for distance 1, l <N> r otherwise |
(source: src/query/fts.rs, TsQueryNode, format_tsquery)
The module doc comment says phraseto_tsquery is "treated as AND here" and describes a "prefix-notation sexp" storage format. Both are out of date: the code builds Phrase nodes and prints PostgreSQL's infix form. (source: src/query/fts.rs, module doc, phraseto_tsquery, format_tsquery)
Query constructors
| Function | Behaviour |
|---|---|
to_tsquery(cfg, q) |
Parses operators; an operand that normalizes to several words becomes a phrase |
plainto_tsquery(cfg, q) |
ANDs the normalized words |
phraseto_tsquery(cfg, q) |
Phrase with the stop-word gaps kept |
websearch_to_tsquery(cfg, q) |
Quoted phrases, or, and leading - for negation |
Text cast '...'::tsquery
|
Parses without normalization |
(source: src/query/fts.rs, parse_tsquery, plainto_tsquery, phraseto_tsquery, websearch_to_tsquery, parse_tsquery_string) Tested by test_fts_plainto_tsquery and test_fts_match_common_shapes. (source: src/query/engine.rs, those tests)
Matching
tsvector_matches evaluates the query tree against the lexeme map. A phrase whose lexemes carry no positions (a tsvector built with strip) matches whenever both sides are present. (source: src/query/fts.rs, tsvector_matches) Tested by test_tsvector_match_basic, test_tsvector_no_match, test_fts_tsmatch_true and test_fts_tsmatch_false.
The engine's @@ accepts either operand order. If the vector side is plain text that does not look like a tsvector, it is converted with to_tsvector('english', text). (source: src/query/engine.rs, ts_match_values) Tested by test_fts_where_clause_filter and test_fts_generated_tsvector_column.
Ranking
ts_rank follows PostgreSQL's calc_rank:
| Item | Value |
|---|---|
| Weights A, B, C, D | 1.0, 0.4, 0.2, 0.1 |
| OR queries | Per-term sum with 1/i^2 decay, divided by 1.644934 and by the term count |
| AND queries | Pairwise word_distance between term positions, capped at MAXENTRYPOS (1 << 14) |
| Negative result | Replaced by 1e-20
|
| Result type | float4 |
(source: src/query/fts.rs, ts_rank, rank_or, rank_and, word_distance) Tested by test_ts_rank_matches_postgres_formula, test_ts_rank_positive, test_fts_ts_rank_positive and test_ts_rank_is_float4_with_postgres_values.
The engine passes only the first two arguments: a weights array or a normalization flag is ignored. ts_rank_cd is dispatched to the same function, so cover density ranking is not implemented. (source: src/query/engine.rs, ts_rank/ts_rank_cd dispatch)
Other functions
| Function | Notes |
|---|---|
setweight, strip, tsvector_to_array, numnode, querytree, \|\| on vectors |
Implemented. Tested by test_setweight, test_concat_tsvectors
|
ts_headline |
Implemented. Tested by test_ts_headline
|
similarity, word_similarity, strict_word_similarity, show_trgm
|
pg_trgm style trigram sets. Tested by test_trigrams, test_similarity_close, test_similarity_identical, test_fts_similarity
|
% operator |
similarity(a, b) >= 0.3. Tested by test_fts_trgm_percent_operator
|
similarity_threshold() |
Constant 0.3; there is no setting to change it |
unaccent |
Implemented. Tested by test_unaccent_basic, test_fts_unaccent
|
ts_debug, ts_lexize, ts_parse, ts_token_type
|
Return NULL |
(source: src/query/fts.rs; src/query/engine.rs, function dispatch)
The @@ index path
CREATE INDEX ... USING gin on a tsvector column or on a to_tsvector(...) expression writes __catalog__:ftsidx:... and builds lexeme postings in the engine-wide registry. (source: src/query/engine.rs, execute_create_index) The posting keys, how &, |, <->, ! and prefix lexemes become candidate sets, and the tests that check the index against brute force are on the GIN page.
Two limits decide whether a query uses it:
-
fts_key_of_exprmatches only a bare column orto_tsvector([cfg,] column). Any other expression, including aCOALESCEaround the column, gets no index. (source:src/query/engine.rs,fts_key_of_expr) -
try_fts_candidatesis skipped inside an explicit transaction, so@@in a transaction always scans. (source:src/query/engine.rs,try_fts_candidates)
MySQL MATCH ... AGAINST
rewrite replaces each MATCH (cols) AGAINST ('q' [mode]) before parsing:
| Position | Rewritten to |
|---|---|
WHERE predicate |
to_tsvector('simple', COALESCE(col,'')) @@ to_tsquery('simple', q'), or CONCAT_WS(' ', cols) for several columns |
Select list or ORDER BY
|
ts_rank(...) wrapped in a CASE that returns 0 when there is no match |
(source: src/protocol/mysql/fulltext.rs, rewrite, rank_query)
| Mode | Query built |
|---|---|
| Natural language (default) | Any word matches (OR) |
IN BOOLEAN MODE |
+word required, -word excluded, word* prefix, "..." phrase, ( ) groups |
There are no stop words and no minimum token length, unlike InnoDB. Tested by boolean_queries and rewrites_predicate_and_rank. (source: src/protocol/mysql/fulltext.rs, boolean_query, natural_query, tests)
Because the rewrite wraps the column in COALESCE and uses the simple configuration, it never matches an FTS index key, so MATCH ... AGAINST always scans. A FULLTEXT KEY inside CREATE TABLE is stored as an ordinary index. (source: src/protocol/mysql/fulltext.rs, rewrite; src/query/engine.rs, fts_key_of_expr; src/query/sql/parser.rs, inline index clause) The MySQL wire page notes that relevance numbers are SynergyDB's own.
match_text, gRPC and REST
match_text(col, q) returns NULL for a NULL column, false for a non-string, and otherwise true when every whitespace-separated term of q occurs as a case-insensitive substring of the column. It is a scan; a code comment says a later planner pass would rewrite it onto Tantivy, which has not happened. Not verified: no test calls match_text directly. (source: src/query/engine.rs, match_text dispatch)
The gRPC Search call builds SELECT "col" FROM "table" WHERE match_text("col", 'q') with quoted identifiers. (source: src/protocol/grpc/wire.rs, search)
REST POST /api/v1/search builds SELECT {columns} FROM {table} WHERE {first column} LIKE '%term%' LIMIT n and gives every hit a score of 1.0. Only the search term has its quotes escaped; the table and column names are inserted without quoting or validation. Not verified: no test covers this route. (source: src/protocol/http/routes.rs, full_text_search)
Text scoring on other wires
| Wire | Scoring | Statistics | Tests |
|---|---|---|---|
| Elasticsearch | Lucene BM25, k1 = 1.2, b = 0.75, one-byte length norms as in Lucene |
Computed per query by scanning the index's documents |
norms_round_trip_like_lucene, matches_elasticsearch_bm25
|
| Neo4j Bolt full-text indexes | BM25, k1 = 1.2, b = 0.75, over a Lucene classic query subset (terms, phrases, prefix, fuzzy, boolean operators) |
IDF from the documents scanned for the query |
analyzer_splits_and_lowercases, graphiti_style_query, operators_prefix_fuzzy_and_escapes
|
Redis FT.SEARCH
|
Term and phrase match on lowercased terms; no stemming or stop words | Exact scan over the index's documents | See Redis |
(source: src/protocol/elasticsearch/bm25.rs, K1, B, int_to_byte4; src/protocol/elasticsearch/mod.rs, attach_bm25_stats; src/protocol/bolt/fulltext.rs, parse, search; src/protocol/redis/commands/search.rs, tokenize, module doc)
Elasticsearch analyzers are standard, whitespace, keyword and a lowercase keyword variant. (source: src/protocol/elasticsearch/field_types.rs, analyze) Details are on the Elasticsearch wire page and the Neo4j Bolt protocol page.
Unwired: src/index/fulltext.rs
Not wired: only IndexManager::create_fulltext_index creates either structure below, and nothing calls it. See Unwired index structures. (source: src/index/mod.rs, create_fulltext_index)
TantivyIndex
| Item | Value |
|---|---|
| Crate |
tantivy 0.22 |
| Schema |
id (stored), content (TEXT, default tokenizer) |
| Writer memory | 50 MB |
| Reader reload | ReloadPolicy::OnCommitWithDelay |
| Methods |
add, remove, search, search_field, search_phrase (wraps the query in quotes), search_fuzzy (term~d), term_frequency (document frequency), commit, reload
|
(source: src/index/fulltext.rs, TantivyIndex; Cargo.toml, tantivy)
The map from Tantivy document to RecordId (id_mapping) is an in-memory HashMap. An index opened from an existing directory starts with an empty map, so its searches return no record ids. Tested by test_tantivy_index (single process only). (source: src/index/fulltext.rs, id_mapping, test_tantivy_index)
SimpleFullTextIndex
An in-memory inverted index: lowercase alphanumeric tokens longer than one character, postings as sets of record ids, score = matched term count / sqrt(document length). Tested by test_simple_fulltext_index and test_simple_fulltext_remove. (source: src/index/fulltext.rs, SimpleFullTextIndex)
Parity record
The committed feature matrix lists the full-text section at 6 of 8 probes matching PostgreSQL: phraseto_tsquery diverged (SynergyDB false, PostgreSQL true) and the trigram % probe was unsupported by the harness's decimal decoding. That file's header total is 269/295, while later status entries report 295/295, so the committed file predates those runs. (source: test-scripts/feature-matrix/FEATURE_MATRIX.md, fts section; docs/status/2026-11-30-pg-result-types.md) The current phraseto_tsquery builds phrase nodes (see above). Not verified: whether the committed divergence still reproduces.