Exemplo n.º 1
0
 public function countContacts($pattern='') {
   if(trim($pattern)) $pattern = "$pattern ";
   else $pattern = '-is:archive';
   return OBM_Search::count('contact', $pattern);
 }
Exemplo n.º 2
0
 public function testBuildQuery() {
     $strings[] = "toto";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%' OR lastname #LIKE 'toto%'))";
     $strings[] = "toto titi";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%' OR lastname #LIKE 'toto%') AND (firstname #LIKE 'titi%' OR lastname #LIKE 'titi%'))";
     $strings[] = "name:toto";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%'))";
     $strings[] = "name:toto:";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto:%'))";
     $strings[] = "toto:";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto:%' OR lastname #LIKE 'toto:%'))";
     $strings[] = "name:toto lname:titi";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%') AND (lastname #LIKE 'titi%'))";
     $strings[] = '"toto titi"';
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto titi%' OR lastname #LIKE 'toto titi%'))";
     $strings[] = "name:\"toto titi\"";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto titi%'))";
     $strings[] = "name:\"toto titi\" lname:\"titi toto\"";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto titi%') AND (lastname #LIKE 'titi toto%'))";
     $strings[] = "(toto titi)";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%' OR lastname #LIKE 'toto%') AND (firstname #LIKE 'titi%' OR lastname #LIKE 'titi%'))";
     $strings[] = "name:(toto titi)";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%') AND (firstname #LIKE 'titi%'))";
     $strings[] = "name:(toto titi) lname:(titi toto)";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%') AND (firstname #LIKE 'titi%') AND (lastname #LIKE 'titi%') AND (lastname #LIKE 'toto%'))";
     $strings[] = "toto titi lname:tutu";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%' OR lastname #LIKE 'toto%') AND (firstname #LIKE 'titi%' OR lastname #LIKE 'titi%') AND (lastname #LIKE 'tutu%'))";
     $strings[] = "name:toto titi lname:tutu";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'toto%') AND (firstname #LIKE 'titi%' OR lastname #LIKE 'titi%') AND (lastname #LIKE 'tutu%'))";
     $strings[] = "txtx name:toto titi lname:(tutu tata) tyty name:\"test de\"";
     $assert[] = "(1 = 1 AND (firstname #LIKE 'txtx%' OR lastname #LIKE 'txtx%') AND (firstname #LIKE 'titi%' OR lastname #LIKE 'titi%') AND (firstname #LIKE 'tyty%' OR lastname #LIKE 'tyty%') AND (firstname #LIKE 'toto%') AND (firstname #LIKE 'test de%') AND (lastname #LIKE 'tutu%') AND (lastname #LIKE 'tata%'))";
     foreach($strings as $index => $string) {
       $result = OBM_Search::buildSearchQuery('SearchableMockup',$string);
       $this->assertEquals($assert[$index], $result);
     }
 }  
Exemplo n.º 3
0
 public static function search($pattern, $offset=0, $limit=100) {
   return OBM_Contact::fetchAll(
     OBM_Search::buildSearchQuery('contact', $pattern, $offset, $limit, array('sort' => 'sortable asc')));
 }