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.
设置
- Mongo数据库 v 2.4.5
- PHP Mongo 驱动程序 v.1.4.2
- PHP 5.5.9
已启动 Mongo(版本 2.4.5)启用 textSearch。 PHP Mongo 驱动程序 1.4.2
mongod --setParameter textSearchEnabled=true
数据库
- 数据库名称 = aero
- Collection = 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 解决了我们的问题。
干杯!
问题
当我尝试 运行 对我的 Mongo 数据库进行全文搜索时,我收到以下错误。
{"ok":0,"errmsg":"can't find ns"}
我试过在网上找到任何可以引用 ns 的东西,但没有成功。我假设它是一个索引问题...
我可以确认我的索引在那里,我什至可以从 Mongo 命令行 运行 进行全文搜索并且它有效!只是不是通过 PHP.
设置
- Mongo数据库 v 2.4.5
- PHP Mongo 驱动程序 v.1.4.2
- PHP 5.5.9
已启动 Mongo(版本 2.4.5)启用 textSearch。 PHP Mongo 驱动程序 1.4.2
mongod --setParameter textSearchEnabled=true
数据库
- 数据库名称 = aero
- Collection = 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 解决了我们的问题。
干杯!