MongoDB 核心將支援全文搜尋功能 (2.3.2)

weixin_34219944發表於2012-12-27

來自 MongoDB 官方 JIRA 的一個新特性報告稱 MongoDB 將在 2.3.2 版本中增加全文搜尋功能。該功能還是體驗到階段,使用方法包括:

db.adminCommand( { setParameter : "*", textSearchEnabled : true } );

或者是:

./mongod --setParameter textSearchEnabled=true

特性:

  • parsing + stemming for latin languages
  • multi-word scoring
  • phrase matching
  • word negation
  • weights per field
  • additional suffix index fields for coverings
  • additional prefix index fields for partitioning
  • specify language per document

簡單使用示例:

> db.foo.insert( { _id: 1 , desc: "the dog is running" } )
> db.foo.insert( { _id: 2 , desc: "the cat is walking" } )
> db.foo.ensureIndex( { "desc": "text" } )
> db.foo.runCommand( "text", { search : "walk" } )
{
    "queryDebugString" : "walk||||||",
    "language" : "english",
    "results" : [
        {
            "score" : 0.75,
            "obj" : {
                "_id" : 2,
                "desc" : "the cat is walking"
            }
        }
    ],
    "stats" : {
        "nscanned" : 1,
        "nscannedObjects" : 0,
        "n" : 1,
        "timeMicros" : 330
    },
    "ok" : 1
}

相關文章