Hi,
I’m struggling to find out how to correctly set a diacritic insensitive text index for my collection of persons. It’s a normal collection without collation.
The MongoDB version is 5.0.15
I need a text index (not using mongo atlas) for the name
and familyName
fields. I created an index with this config:
{
"v": 2,
"key": {
"_fts": "text",
"_ftsx": 1
},
"name": "personsFullname",
"weights": {
"familyName": 1,
"name": 1
},
"default_language": "es",
"language_override": "language",
"textIndexVersion": 3
}
The problem is that even though the MongoDB manual says that from version 3 the text search is diacritic insensitive it doesn’t work that way.
Suppose I have these 3 records:
[
{
"_id": "aaaaaaa",
"name": "Roberto ",
"familyName": "Torres García "
},
{
"_id": "bbbbbbb",
"name": "Ruben A",
"familyName": "Parras García"
},
{
_id:"ccccc",
"name": "Karla",
"familyName": "Rosas García"
}
]
If I search for García
(using diacritic for i):
db.getCollection("personsData").find({ "$text": { "$search": "García" } })
It finds the 3 records.
But if I search for Garcia
(Not using diacritic for i):
db.getCollection("personsData").find({ "$text": { "$search": "Garcia" } })
It finds no records.
What am I missing here?
Thank you in advance.