来自 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
}

相关文章:

  • 2022-12-23
  • 2021-06-28
  • 2021-10-22
  • 2021-09-29
  • 2021-10-28
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-20
  • 2021-12-24
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案