Monday, February 24, 2014

Some note for Phalcon and Mongo DB

Search like % with Phalcon and Mongo DB

 /**
* Get condition to query
* @param type $searchKey
*/
private function _conditions($searchKey) {        
    $string = preg_replace('/\s+/', '|', $searchKey);
    $condition = ['$or' => [
                ['Question' => ['$regex' => "($string)", '$options' => 'i']], 
                ['Content' => ['$regex' => "($string)", '$options' => 'i']]
             ]];
        return $condition;

}


No comments:

Post a Comment