PHP MongoClient (PECL) 和精确词全文搜索

PHP MongoClient (PECL) and exact word full text search

我创建了一个具有不同权重的全文搜索索引,当您执行如下基本查询时,它对 "OR" 基本搜索非常有效:

db.items.find( { $text: { $search: "iphone 5" }}, {score: {$meta: "textScore"}}).pretty()

此查询(shell 客户端)将查找包含字词 "iphone" OR“5”的所有项目。在 PHP 中,我们这样查询:

$product = 'iphone 5';
$search = array( '$text' => array('$search' => $product) );
$m = new MongoClient("mongodb://localhost:xxxxx", array("username" => 'xxxxx', "password" => 'xxxxx', "db" => 'xxxxx'));
$db = $m->mybase;
$collection = $db->items;
$cursor = $collection->find( $search, array('score' => array('$meta' => 'textScore') ) )->sort( array('score' => array('$meta' => 'textScore') ) );

我的问题是关于 PHP 中全文搜索中的 "AND" 运算符。在 shell 客户端,为了获得所有包含单词 "iphone" AND "5" 的项目,我执行以下操作:

db.items.find( { $text: { $search: "\"iphone\" \"5\"" }}, {score: {$meta: "textScore"}}).pretty()

它工作得很好,但在 PHP 我尝试了很多方法来获得相同的结果,但它根本不起作用,我试过的是:

$product = '\"iphone\" \"5\"';
$product = '\"iphone\" \"5\"';
$product = "\'iphone\' \'5\'";
...

如何在 PHP 中做到这一点,以便获得与 shell 相同的结果?

好吧,饭后我想起简单引号与特殊字符(如“\”)的双引号不同,所以我简单地更改为该工作代码:

$product = "\"iphone\" \"5\"";

它很有魅力,希望有一天能对某人有所帮助 ;)