Fix advanced search when soundex is activated.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 3 Oct 2010 15:43:03 +0000 (17:43 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 3 Oct 2010 15:43:03 +0000 (17:43 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/userfilter.php
include/ufbuilder.inc.php
ut/userfiltertest.php

index ddbf5dd..d45a08c 100644 (file)
@@ -414,7 +414,7 @@ class UFC_NameTokens implements UserFilterCondition
         foreach ($this->tokens as $i => $token) {
             $sub = $uf->addNameTokensFilter($token);
             if ($this->soundex) {
-                $c = XDB::format($sub . '.soundex = {?}', $token);
+                $c = XDB::format($sub . '.soundex = {?}', soundex_fr($token));
             } else if ($this->exact) {
                 $c = XDB::format($sub . '.token = {?}', $token);
             } else {
index 45c589b..354ef18 100644 (file)
@@ -520,18 +520,8 @@ class UFBF_Quick extends UFB_Field
             } else {
                 $flags = array('public');
             }
-            if ($ufb->b('with_soundex')) {
-                $soundex = true;
-                $st = array();
-                foreach ($strings as $string) {
-                    $st[] = soundex_fr($string);
-                }
-            } else {
-                $soundex = false;
-                $st = $strings;
-            }
             $exact =$ufb->b('exact');
-            $conds->addChild(new UFC_NameTokens($st, $flags, $soundex, $exact));
+            $conds->addChild(new UFC_NameTokens($st, $flags, $ufb->b('with_soundex'), $exact));
 
             $ufb->addOrder(new UFO_Score());
         }
index cf21bdc..0928200 100644 (file)
@@ -424,16 +424,13 @@ class UserFilterTest extends PlTestCase
             // soundex, !exact
             array(self::buildProfileQuery('LEFT JOIN  search_name AS sn ON (p.pid = sn.pid)
                                                WHERE  sn.soundex = \'XLNO\''),
-                new UFC_NameTokens('XLNO', array(), true), -1),
+                new UFC_NameTokens('xelnor', array(), true), -1),
             array(self::buildProfileQuery('LEFT JOIN  search_name AS sn ON (p.pid = sn.pid)
                                                WHERE  sn.soundex IN (\'XLNO\', \'BROS\')'),
-                new UFC_NameTokens(array('XLNO', 'BROS'), array(), true), -1),
-            array(self::buildProfileQuery('LEFT JOIN  search_name AS sn ON (p.pid = sn.pid)
-                                               WHERE  sn.soundex = \'ZZZZZZ\''),
-                new UFC_NameTokens('ZZZZZZ', array(), true), 0),
+                new UFC_NameTokens(array('xelnor', 'barrois'), array(), true), -1),
             array(self::buildProfileQuery('LEFT JOIN  search_name AS sn ON (p.pid = sn.pid)
                                                WHERE  sn.soundex = \'BROS\' AND FIND_IN_SET(\'public\', sn.flags)'),
-                new UFC_NameTokens('BROS', UFC_NameTokens::FLAG_PUBLIC, true), -1),
+                new UFC_NameTokens('barrois', UFC_NameTokens::FLAG_PUBLIC, true), -1),
         );
 
         /* UFC_Nationality