MongoDB对象的全文搜索

时间:2015-10-31 15:59:38

标签: 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"
  },
  "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上运行它。

0 个答案:

没有答案