文本索引mongodb不使用重音符号

时间:2018-03-16 13:02:30

标签: mongodb

这是我的样本数据:

>db.tests.find()
{ "_id" : ObjectId("5aabbdecb71313f21cef8d85"), "id" : 1235, "word" : "comida" }
{ "_id" : ObjectId("5aabbdecb71313f21cef8d86"), "id" : 1234, "word" : "alimentación" }

我在word字段上有搜索索引。所以我不仅可以通过确切的词搜索:

    > db.tests.find({ $text: { $search: 'alimentación', $language: 'es', $diacriticSensitive: false } })
    { "_id" : ObjectId("5aabbdecb71313f21cef8d86"), "id" : 1234, "word" : "alimentación" }
    > db.tests.find({ $text: { $search: 'alimentos', $language: 'es', $diacriticSensitive: false } })

{ "_id" : ObjectId("5aabbdecb71313f21cef8d86"), "id" : 1234, "word" : "alimentación" }

但是,如果我的搜索文字没有重音,则不匹配:

> db.tests.find({ $text: { $search: 'alimentacion', $language: 'es', $diacriticSensitive: false } })

获取查询计划信息我在搜索“alimentación”和“alimentacion”之间有所区别:

在第一个casa中,parsedTextQuery得到了单词的词干:

    "winningPlan" : {
        "stage" : "TEXT",
        "indexPrefix" : {},
        "indexName" : "word_text",
        "parsedTextQuery" : {
            "terms" : [ 
                "aliment"
            ],
            "negatedTerms" : [],
            "phrases" : [],
            "negatedPhrases" : []
        },

在第二种情况下没有,因为“alimentacion”不存在:

"winningPlan" : {
    "stage" : "TEXT",
    "indexPrefix" : {},
    "indexName" : "word_text",
    "parsedTextQuery" : {
        "terms" : [ 
            "alimentacion"
        ],
        "negatedTerms" : [],
        "phrases" : [],
        "negatedPhrases" : []
    },

使用Mongo的任何解决方法?

0 个答案:

没有答案