You need to specify some fields for $in :
$who=array('$or' => array( array('somefield' => array('$in' => array(new MongoRegex($title)))), array('otherotherfield' => array('$in' => array(new MongoRegex($tags)))) ));
So this works, saying, saying: if some field is in the range of some values
http://docs.mongodb.org/manual/reference/operator/in/
Edit
This may still not work due to the built-in $regex . If so, you can try:
$who=array('$or' => array( array('somefield' => new MongoRegex($title)), array('otherotherfield' => new MongoRegex($tags)) ));
Edit
If any of these queries do not work, you can:
$who = array('$or' => array()); foreach($arr_query as $q){ $who['$or'][] = array('title' => new MongoRegex("/^$q/")); $who['$or'][] = array('tags' => new MongoRegex("/^$q/")); }
Something like this should work, again it is untested, but if my memory serves me correctly, it should do it.
Other editing
This works fine for me:
$mongo = new Mongo(); $db = $mongo->tstvid; $videos = $db->videos; $videos->insert(array('title' => 'test1', 'tags' => array('h','h'))); $videos->insert(array('title' => 'test2', 'tags' => array('h','h'))); $videos->insert(array('title' => 'test3', 'tags' => array('h','h'))); $videos->insert(array('title' => 'tst3', 'tags' => array('h','test'))); $user_query = preg_replace("/[[:blank:]]+/"," ", "test"); $arr_query = explode(' ', $user_query); if (count($arr_query) > 1) { $who = array( '$or' => array() ); foreach ($arr_query as $q) { $who['$or'][] = array('title' => new MongoRegex("/^". $q ."/i")); $who['$or'][] = array('title' => new MongoRegex("/^". $q ."/i")); } } else { $regex=new MongoRegex("/^". $user_query ."/i"); $tregex=new MongoRegex("/^". $user_query ."/i"); $who=array( '$or' => array( array('title' => $regex), array('tags' => $tregex) ) ); } $vids=$videos->find($who); $results=""; $i=0; foreach($vids as $vid){ $results .= "<li>".$vid['title']."</li>\n"; $i++; } if($i==0){ $results="<em>No results found</em>"; } echo $results;
And he outputs:
test1 test2 test3 tst3
So, I'm not sure what is wrong, but I would recommend double checking that your script is breaking the keywords correctly and the schema is being viewed correctly, calling these requests in the console.
It should be noted that I also tried this:
$user_query = preg_replace("/[[:blank:]]+/"," ", "test h");
And it worked.