2017-01-30 7 views
0

Ich versuche, mongodb Volltextsuche für die Anzeige der Jobliste zu verwenden. Ich habe alle notwendigen Schritte unternommen, um die Textindizes zu erstellen und die Volltextsuche in der Datenbank zu aktivieren, und alles funktioniert gut, außer von der Volltextsuche mit PHP 5.6.Mongodb Volltextsuche Mit PHP 5.6

Antwort

0

verwenden Sie den Code unten in PHP für den vollständigen Text:

<?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

für ref https://code.tutsplus.com/tutorials/full-text-search-in-mongodb--cms-24835 – AmitChaudhary