{{ message }}
Repository navigation
Conversation
… GUC
textIndexVersion 3 has been MongoDB's default since 3.2, which means every
dump of a modern deployment carries version 3 in its index metadata — and
the hard error here fails entire mongorestore index-restoration phases,
silently leaving migrated collections with no text search.
Version 3 differs from version 2 by diacritic insensitivity ('cafe'
matches 'café'). This change implements it end to end:
- New GUC enableTextIndexVersion3 (default off): version 3 requires the
unaccent extension, which not every deployment installs. When the GUC is
off, version-3 specs are accepted and built with version-2 semantics,
with a NOTICE about the difference — restores complete either way.
- New text opclass reloption textversion (2|3) recorded on the index, so
the build and query sides agree on the semantics per index; a version-2
index created while the GUC is on stays diacritic sensitive.
- Build side: document text is folded via unaccent(text) before parsetext
when the index version is >= 3.
- Query side: the $text search string is folded the same way before
websearch_to_tsquery, guarded for options blobs serialized before the
reloption existed.
- unaccent(text) is resolved via the search path with a public-schema
fallback and cached; a missing extension raises a clear error with a
hint.
Folding runs before dictionary processing, which also fixes a subtle v2
gap: accented stopwords (e.g. portuguese 'São') are dropped from v2
indexes entirely, so searching 'sao' can never match — under v3 the folded
term is indexed and found.
Includes a regress suite covering: invalid versions still rejected, the
GUC-off compatibility path, folded matches in portuguese and english
configs, per-index version semantics, weighted multi-path indexes, and
updates keeping folded terms in sync.
Co-authored-by: veluacode <no-reply@velua.ai>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Guilherme M. Prestes da Silva <gmprestes@gmail.com>
gmprestes
force-pushed
the
text-index-version-3
branch
from
July 29, 2026 05:32
dbe77f3 to
8e14590
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Adds support for
textIndexVersion: 3on text indexes — MongoDB's default since 3.2 — implemented as diacritic folding through theunaccentextension, behind a new GUC (enableTextIndexVersion3, default off).Why
Every
mongodumptaken from a modern MongoDB deployment carries"textIndexVersion": 3in its index metadata. TodaycreateIndexeshard-errors on it:mongorestoretreats this as fatal for the collection's index phase, so migrations silently end with collections that have no text search at all. Since v3 is the upstream MongoDB default, this affects essentially every migration that includes a text index.Version 3 differs from version 2 by diacritic insensitivity (
cafematchescafé), plus small tokenizer changes. For languages with heavy diacritics (Portuguese, Spanish, French…) this is also a real search-quality gap, not just a compatibility one: users overwhelmingly type unaccented queries.How
enableTextIndexVersion3(default off). Version 3 requires theunaccentextension, which not every deployment installs — hence opt-in.NOTICEexplaining the difference. Restores complete either way (this alone fixes the mongorestore failure).textversion(2|3) recorded on the index itself, so build and query sides agree per index: a version-2 index created while the GUC is on stays diacritic sensitive; flipping the GUC later never changes existing indexes.rum_bson_single_path_extract_tsvectorpath): document text is folded viaunaccent(text)beforeparsetextwhen the index version is ≥ 3.BsonTextGenerateTSQueryCore): the$textsearch string is folded the same way beforewebsearch_to_tsquery, with a size guard for options blobs serialized before the reloption existed.unaccent(text)is resolved through the search path with apublic-schema fallback and cached; a missing extension raises a clear error with a hint (CREATE EXTENSION unaccent, or disable the GUC).Folding runs before dictionary processing, which also fixes a subtle v2 gap we found while testing: accented stopwords (e.g. Portuguese "São") are dropped from version-2 indexes entirely, so searching
sao(or evensão) can never match"São Paulo". Under v3 the folded termsaosurvives the dictionary and is indexed:Tests
New regress suite
text_indexes_version3covering:portugueseconfig — including the São-stopword case above;englishconfig, where the stemmer folds nothing (this is the common broken case in the wild:mongodumpmetadata defaults todefault_language: english, and under v2cafecan never matchCafé);Notes