PHP Mongo全文搜索(错误“can';t find ns”)


PHP Mongo Full Text Search (error "can't find ns")

问题

当我尝试对我的Mongo数据库运行全文搜索时,我收到以下错误。

{"ok":0,"errmsg":"can't find ns"}

我试着在网上找到任何可以指代ns的东西,但没有成功。我认为这是一个索引问题。。。

我可以确认我的索引在那里,我甚至可以从Mongo命令行运行全文搜索,这很有效!只是不通过PHP。

设置

  • MongoDB 2.4.5版
  • PHP Mongo驱动程序1.4.2版
  • PHP 5.5.9

使用textSearchEnabled启动Mongo(2.4.5版)。PHP Mongo驱动程序1.4.2

mongod --setParameter textSearchEnabled=true

数据库

  • DB名称=空气动力学
  • 集合=https_aero_guides

PHP代码

这是我的代码

$this->mongo_db->_connection->admin->command(
    array(
       "setParameter" => 1, 
       "textSearchEnabled" => true
    )
);
$this->mongo_db->_connection->aero->https_aero_guides->ensureIndex(
    array(
        'title' => 'text'
    ),
    array(
        'name' => 'title_text',
        'weights' => array('title' => 100)
    )
);
$results = $this->mongo_db->_connection->aero->command(
    array(
        'text' => 'https_aero_guides',
        'search' => 'hello',
        'limit' => 5
    )
);

数据搜索依据

数据库具有以下行

[
{ title : "hello" }, 
{ title : "waynes" }, 
{ title : "world" }
]

Mongo索引

> db.https_aero_guides.getIndexes()
[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
    "ns" : "aero.https_aero_guides",
    "name" : "_id_"
},
    {
        "v" : 1,
        "key" : {
            "_fts" : "text",
            "_ftsx" : 1
        },
        "ns" : "aero.https_aero_guides",
        "name" : "title_text",
        "weights" : {
            "title" : 100
        },
        "default_language" : "english",
        "language_override" : "language",
        "textIndexVersion" : 1
    }
]

Mongo索引

wdberkeley你是对的。升级mongo解决了我们的问题。

干杯!