【问题标题】:PHP Mongo Full Text Search (error "can't find ns")PHP Mongo全文搜索(错误“找不到ns”)
【发布时间】:2015-02-18 03:59:03
【问题描述】:

问题

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

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

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

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

设置

  • MongoDB v 2.4.5
  • PHP Mongo 驱动程序 v.1.4.2
  • PHP 5.5.9

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

mongod --setParameter textSearchEnabled=true

数据库

  • 数据库名称 = aero
  • 收藏 = 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 索引

【问题讨论】:

  • 如果要进行文本搜索,请使用 MongoDB >= 2.6,其中文本搜索实际上是一个成熟的功能。您可以通过常规查找查询而不是命令来使用它。

标签: php mongodb full-text-search


【解决方案1】:

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

干杯!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 2012-06-08
    • 2011-06-26
    • 2016-03-03
    • 2012-03-17
    相关资源
    最近更新 更多