Php 集合MongoDB没有文本索引

Php 集合MongoDB没有文本索引,php,mongodb,full-text-search,Php,Mongodb,Full Text Search,我试着运行这个简单的示例来尝试如何在Mongo2.4中使用textSearch feauture的示例(在MongoDB网站上找到) <?php $m = new Mongo(); $d = $m->demo; $c = $d->planets; $c->insert(array("name" => "Mercury", "desc" => "Mercury is the smallest and closest to th

我试着运行这个简单的示例来尝试如何在Mongo2.4中使用textSearch feauture的示例(在MongoDB网站上找到)

 <?php
    $m = new Mongo();
    $d = $m->demo;
    $c = $d->planets;

    $c->insert(array("name" => "Mercury", "desc" => "Mercury is the smallest and closest to the Sun"));
    $c->insert(array("name" => "Venus", "desc" => "Venus is the second planet from the Sun, orbiting it every 224.7 Earth days."));
    $c->insert(array("name" => "Earth", "desc" => "Earth is the the densest of the eight planets in the Solar System."));
    $c->insert(array("name" => "Mars", "desc" => "Mars is named after the Roman god of war."));


    $c->ensureIndex(array('desc' => 'text'));

    $r = $d->command(array("text" => "planets", 'search' => "sun" ));
    print_r($r);

    ?>
并且文本搜索已启用


谢谢你的帮助

我找到了解决方案,显然我们需要在字段上定义索引之前(文本索引):


在创建文本索引或使用text命令之前,需要显式启用该功能

您可以使用textSearchEnabled参数在启动时启用文本搜索功能:


mongod--setParameter textSearchEnabled=true

从MongoDB 2.6.x开始,默认情况下启用文本搜索。在MongoDB 2.4.x上,需要如上所示启用它
$c->ensureIndex(array('desc' => 'text')); 
$c->ensureIndex(array('name'=> 1,'desc' => 1),array('unique'=> true));