mongodb全文搜索和json对象

时间:2013-07-23 19:53:22

标签: mongodb search full-text-search full-text-indexing

我正在运行mongodb v2.4.5。我有一个包含以下字段的文档:

{ "_id" : ObjectId("<someid>"), temp:"python", github_repo_languages" : { "python" : 17, "java" : 984 } }

如果我运行查询:

db.users.runCommand( "text", { search: "java" })

{
"queryDebugString" : "java||||||",
"language" : "english",
"results" : [ ],
"stats" : {
    "nscanned" : 0,
    "nscannedObjects" : 0,
    "n" : 0,
    "nfound" : 0,
    "timeMicros" : 97
},
"ok" : 1
}

mongodb找不到任何文件。

以下是我的索引:

> db.users.getIndexes()
[
{
    "v" : 1,
    "key" : {
        "_id" : 1
    },
    "ns" : "workingon.users",
    "name" : "_id_"
},
{
    "v" : 1,
    "key" : {
        "_fts" : "text",
        "_ftsx" : 1
    },
    "ns" : "workingon.users",
    "name" : "users_text_index",
    "weights" : {
        "$**" : 1
    },
    "default_language" : "english",
    "language_override" : "language",
    "textIndexVersion" : 1
}
]

其他搜索适用于简单的文本字段。问题是复杂的json对象吗?是否有计划添加复杂的json对象?

1 个答案:

答案 0 :(得分:1)

根据文档(http://docs.mongodb.org/manual/core/text-search/),文本索引应该在字段或字段上,其值是字符串或字符串元素数组。正如你所指出的,json字段不起作用。