如何在mongodb中使用php搜索全文索引

时间:2013-04-17 21:55:40

标签: php mongodb

我使用mongodb 2.4并在"标题"中添加了全文索引。领域中的一个集合。我该如何使用php在该字段中搜索某些内容?

这是我现在使用的代码:

$params = array(
        '_id' => array(
            '$gt' => (int)$gt
        )
    );
$r = $this->collection->find( $params )->limit($limit);

1 个答案:

答案 0 :(得分:1)

这似乎是我的问题的答案:

<?php
$result = $db->command(
    array(
        'text' => 'bar', //this is the name of the collection where we are searching
        'search' => 'hotel', //the string to search
        'limit' => 5, //the number of results, by default is 1000
        'project' => Array( //the fields to retrieve from db
            'title' => 1
        )
    )
);

http://www.php.net/manual/en/mongodb.command.php#111891

相关问题