我正在尝试在不区分变音符号的 MongoDB 集合字段中进行搜索(它是 $text 索引),并且我只想找到完全匹配的内容(而不是 .contains() 或类似内容)。
我能想到的唯一解决方案是配置文档索引以避免标记器。因此,我会将字段的所有内容作为单个标记,并且它只会返回完全匹配的内容。请问有人知道怎么做吗?
非常感谢!
示例: 我尝试在字段中搜索“iphone 7”。 我希望它返回给我:“iphone 7”、“iphone 7”。 它给我的回复是:“iphone 7”、“iphone 7”、“iphone 7 64gb”、“iphone 7 color blanco”。
最佳答案
您可以设置$diacriticSensitive: <boolean>
进行文本搜索时的值。
{
$text:
{
$search: <string>,
$language: <string>,
$caseSensitive: <boolean>,
$diacriticSensitive: <boolean>
}
}
查看此链接以获取更详细的说明 - https://docs.mongodb.com/manual/reference/operator/query/text/
关于MongoDB 搜索 : exact match and diacritic insensitivity (avoid tokenizer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40549436/