如何使用 Spring 为文本搜索设置 default_language

How do I set the default_language for Text Search with Spring

在我的模型中,我设置了 @TextIndexed 注释以将字段添加到 MongoDB 的全文索引:

@TextIndexed
private String descriptionShort;

到目前为止这有效。

但是如何将索引的 default_language 设置为 "De" 呢?

我注意到当在模型实体上找到语言 属性 时,语言由 Spring 自动设置。 至少行为指向了这个结论。 但是,我没有找到这方面的任何文档?

我的模型目前没有语言 属性 所以我想知道如何实现这一点?

根据unit test's the class can be annotated to the default language through the @Document annotation. There is also a section in the reference documentation。基本上使用与单元测试中相同的代码:

@Document(language = "german")
static class TextIndexedDocumentRoot {

        @TextIndexed String textIndexedPropertyWithDefaultWeight;
        @TextIndexed(weight = 5) String textIndexedPropertyWithWeight;

        TextIndexedDocumentWihtLanguageOverride nestedDocument;
    }

    static class TextIndexedDocumentWihtLanguageOverride {

        @Language String lang;

        @TextIndexed String textIndexedPropertyInNestedDocument;

        String nonTextIndexedProperty;
    }
}

请注意,此处的 @Language 注释用作文档中存储的不同语言短语的 language_override setting, but this would actually happen within the "sub-document" as shown with the default field name of "language" anyway, and it a common pattern for enabling multi language support

另请注意,语言可以是 "german""de" 作为 ISO 代码,或文档中列出的 Text Search Languages 支持的任何语言。其他选项仅在企业版中可用。