2017-01-30 108 views
0

我正在尝试使用mongodb全文搜索来显示作业列表。我已经完成了所有必要的步骤来创建文本索引并启用数据库上的全文搜索功能,并且除了使用PHP 5.6进行全文搜索外,一切工作都正常。Mongodb全文搜索使用PHP 5.6

回答

0

使用下面的代码在PHP为全文:

<?php 
$username = 'mongodbusername'; 
$password = 'changeMe'; 
$m = new MongoClient("mongodb://myadmin1:[email protected]/dbname"); 
//$m = new MongoClient("mongodb://localhost", array("username" => $username, "password" => $password,"db" => "jobma_integrations")); 
$db = $m->integrations; // this is your dbname 
$crawlingCollection = $db->crawled_jobs; // this is your collection name 
$c = $crawlingCollection->find(
    ['$text' => ['$search' => "sales \"ardmore\""]], // this \"ardmore\" is used for exact match and sales will be match with any where 
    ['score'=> ['$meta'=>'textScore']] 
)->sort(
    ['score'=> ['$meta'=>'textScore']] 
); 
echo "<pre>"; 
var_dump(iterator_to_array($c)); 
?> 
+0

对裁判https://code.tutsplus.com/tutorials/full-text-search-in-mongodb--cms-24835 – AmitChaudhary