<?php
$m = new MongoClient;
$cursor = $m->demo->articles->find(
[
'$text' => [ '$search' => '"advent" "xdebug"' ],
'subject' => new MongoRegex( '/an/' )
],
[
'_id' => 0, 'subject' => 1,
'score' => [ '$meta' => 'textScore' ]
]
)->limit( 4 )->sort( [ 'score' => [ '$meta' => 'textScore' ] ] );
foreach ( $cursor as $record )
{
printf( "Score: %4.2f, Title: %s\n", $record['score'], $record['subject'] );
}
?>