Reputation: 103
I'm trying to search in a MongoDB collection field without diacritic sensitivity (it is a $text index) and I want to find only exact matches (not a .contains() or like).
The only solution I can think of is to configure the index of the documents to avoid the tokenizer. Therefore, I would have all the content of the field as a single token and it would only give me back the ones that matched exactly. Does anyone know how to do this, please?
Thank you so much!
Example: I try to search "iphone 7" in the field. I want it to give me back: "iphóne 7", "iphone 7". What it gives me back: "iphóne 7", "iphone 7", "iphóne 7 64gb", "iphone 7 color blanco".
Upvotes: 2
Views: 1162
Reputation: 2650
you can set $diacriticSensitive: <boolean>
value when doing text searches.
{
$text:
{
$search: <string>,
$language: <string>,
$caseSensitive: <boolean>,
$diacriticSensitive: <boolean>
}
}
check this link for more detailed explanation - https://docs.mongodb.com/manual/reference/operator/query/text/
Upvotes: 3