MongoDB对象全文搜索

MongoDB对象全文搜索,mongodb,full-text-search,Mongodb,Full Text Search,我有这样的文件: > db.productGroup.find() { "_id": "1", "groupName": { "de": "ein produkt", "en": "a product" }, "ownerUuid": "companyA" } { "_id": "2", "groupName": { "de": "ein anderes produkt", "en": "another product" },

我有这样的文件:

> db.productGroup.find()
{
  "_id": "1",
  "groupName": {
    "de": "ein produkt",
    "en": "a product"
  },
  "ownerUuid": "companyA"
}
{
  "_id": "2",
  "groupName": {
    "de": "ein anderes produkt",
    "en": "another product"
  },
  "ownerUuid": "companyA"
}
{
  "_id": "3",
  "groupName": {
    "de": "ein produkt",
    "en": "a product"
  },
  "ownerUuid": "companyB"
}
我有以下索引配置:

> db.productGroup.getIndexes()
[
  {
    "v": 1,
    "key": {
      "_id": 1
    },
    "name": "_id_",
    "ns": "junit_masterdata.productGroup"
  },
  {
    "v": 1,
    "key": {
      "_fts": "text",
      "_ftsx": 1
    },
    "name": "groupName_text",
    "ns": "junit_masterdata.productGroup",
    "weights": {
      "groupName": 1
    },
    "default_language": "english",
    "language_override": "language",
    "textIndexVersion": 2
  },
  {
    "v": 1,
    "key": {
      "groupId": 1
    },
    "name": "groupId_1",
    "ns": "junit_masterdata.productGroup"
  }
]
现在我想使用全文搜索。但是,没有发现任何东西:

> db.productGroup.find({ $text: { $search: "produkt" } })
Fetched 0 record(s) in 0ms
> db.productGroup.find({ $text: { $search: "ein" } })
Fetched 0 record(s) in 0ms
知道我做错了什么吗?如果我能按语言划分搜索,我会得到额外的分数,但目前这只是一个不错的选择


PS:索引、文档和查询都是用Java(Morphia)生成的,但我甚至没有让它在shell上运行。

你不能这样做。您需要在定义的索引中直接指定一个字段(即
groupName.de
),以便搜索该字段。您可以选择在定义中直接包含多个字段
{“groupName.en”:“text”、“groupName.en”:“text”}
,但它实际上是无效的,因为每个索引只能指定一种语言,每个集合只能指定一个文本索引。此外,如果您打算进行德语搜索,则还需要将其定义为索引上的默认语言。Mongo文本索引不是一个成熟的产品,只是一个满足基本需求的“lite”实现。在语言搜索中,像“ein”这样的东西应该被忽略,就像“a”一样。只有像“产品”和“产品”这样的东西会被返回,就像“产品”是一个有效的复数匹配一样。感谢您的快速反馈。我想我们需要进行全面的开发:如果您确实需要能够以多种语言搜索数据,那么其他产品似乎更适合您的需求。许多数据库的目的不是直接关注文本搜索,它们提供了一种实现文本搜索的工具,但是没有一个提供真正专门构建的文本搜索引擎设计的功能。这些功能适合我们的用例(使用德语和英语进行全文搜索,以获得正确的停止词+词干)。我们主要关心的是,我们是否真的应该将该工作负载放入常规数据库中。