使用 Mongodb 和 PHP 进行文本搜索

Text Search with Mongodb and PHP

是否可以通过匹配记录中的关键字或日期范围来查询mongodb?

例如,如果我有一个 collection,其中包含 "Title"、"Author" 和 "Date" 等字段。我有此记录,标题为 "hello world",作者为 "john billy",日期为“2014/05/12”。

是否可以通过输入 "world" 或 "billy" 或日期范围(2014/01/12 至 2014/06/12)来 return 此记录

我应该如何编写查询以获得我想要的记录?

提前致谢!

下面是我的日期期间代码:$from_Id 是

        $rangeQuery = array('timestamp' => array( '$gte' => $from_Id, '$lte' => $to_Id ));

        $cursor = $collection->find($rangeQuery);

你必须使用$lt/$lte(对应$gt/$gte(对应>/>=)运算符在您的查询中设置日期范围。只需查找 mongodb 文档即可:

http://docs.mongodb.org/manual/reference/operator/query-comparison/

这是来自 php 文档 (http://php.net/manual/en/mongocollection.find.php) 的示例:

<?php

$m = new MongoClient();
$db = $m->selectDB('test');
$collection = new MongoCollection($db, 'phpmanual');

// search for documents where 5 < x < 20
$rangeQuery = array('x' => array( '$gt' => 5, '$lt' => 20 ));

$cursor = $collection->find($rangeQuery);
foreach ($cursor as $doc) {
    var_dump($doc);
}

?>

@SaTya 给的link 可以帮你用关键词搜索