Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb多语言搜索:哪种模式更适合更快的搜索结果-嵌套或直接使用特定于语言的字段_Mongodb_Mongoose_Mongoose Schema_Mongodb Atlas_Mongodb Atlas Search - Fatal编程技术网

Mongodb多语言搜索:哪种模式更适合更快的搜索结果-嵌套或直接使用特定于语言的字段

Mongodb多语言搜索:哪种模式更适合更快的搜索结果-嵌套或直接使用特定于语言的字段,mongodb,mongoose,mongoose-schema,mongodb-atlas,mongodb-atlas-search,Mongodb,Mongoose,Mongoose Schema,Mongodb Atlas,Mongodb Atlas Search,我们使用Atlas搜索索引对产品进行模糊搜索,对于查询,我们使用Mongoose。我们想要的搜索类型包括多语言搜索,为此,我们对产品使用以下模式- { language: "de", name: String, description: String, translation: { en: { name: String, description: String }, fr: { na

我们使用Atlas搜索索引对产品进行模糊搜索,对于查询,我们使用Mongoose。我们想要的搜索类型包括多语言搜索,为此,我们对产品使用以下模式-

{
  language: "de",
  name: String,
  description: String,
  translation: {
     en: {
        name: String,
        description: String
     },
     fr: {
        name: String,
        description: String
     }
  }
}
考虑到搜索性能,上面的模式将是一个很好的选择,因为读取数据将有数千次或更多的点击。展望未来,由于这是一个电子商务系统,搜索查询可能会达到数百万。嵌套结构有利于查询,或者我们可以选择其他选项

  • 具有直接为语言指定的速记语言特定字段:
  • 使用字段名作为键嵌套特定于语言的字段
  • 或者适用于此场景的任何其他模式
  • 将根据用户选择的语言执行搜索。因此,如果用户选择法语作为其首选语言,我们将查找用户用法语键入的关键字


    另外,除了名称和描述之外,还有更多的字段是特定于语言的。

    我会选择选项一,因为Atlas搜索中对嵌套字段的支持有限,尽管选项2也可以。以下是我在您的案例中如何定义索引:

    {
      "mappings": {
        "fields": {
          "name_de": {
            "analyzer": "lucene.german",
            "type": "string"
          },
          "name_fr": {
            "analyzer": "lucene.french",
            "type": "string"
          },
          "name_en": {
            "analyzer": "lucene.english",
            "type": "string"
          },
            "description_de": {
            "analyzer": "lucene.german",
            "type": "string"
          },
          "description_fr": {
            "analyzer": "lucene.french",
            "type": "string"
          },
          "description_en": {
            "analyzer": "lucene.english",
            "type": "string"
          }
        }
      }
    }
    

    通过这种方式,您可以享受突出显示的好处,如果您的描述字段很长,则突出显示会特别有用。你也会得到更好的停止字支持和变音符号的开箱即用。如果您有任何问题,请在此处告诉我,我将提供帮助。

    根据您的建议,我不太关心Atlas搜索索引的大小,但不是通过修改映射来增加索引大小,而是减少索引大小,这是一个很好的选择。但有一件事我在你的回答中不明白,那就是,它将如何更好地支持变音符号呢?我的意思是,在我们目前使用的模式中有特定于语言的字段也可以做到这一点,即支持停止词和变音符号。默认情况下,停止词在语言分析器中。您可以指定如何在索引定义中处理变音符号。
        {
             name: {
                en: String,
                de: String,
                fr: String
             },
             description: {
                en: String,
                de: String,
                fr: String
             }
        }
    
    {
      "mappings": {
        "fields": {
          "name_de": {
            "analyzer": "lucene.german",
            "type": "string"
          },
          "name_fr": {
            "analyzer": "lucene.french",
            "type": "string"
          },
          "name_en": {
            "analyzer": "lucene.english",
            "type": "string"
          },
            "description_de": {
            "analyzer": "lucene.german",
            "type": "string"
          },
          "description_fr": {
            "analyzer": "lucene.french",
            "type": "string"
          },
          "description_en": {
            "analyzer": "lucene.english",
            "type": "string"
          }
        }
      }
    }