Bug "Task #37 ? soundex ne marche pas sur la recherche avancée" résolu
authorx2000bedo <x2000bedo>
Mon, 30 Aug 2004 23:52:48 +0000 (23:52 +0000)
committerx2000bedo <x2000bedo>
Mon, 30 Aug 2004 23:52:48 +0000 (23:52 +0000)
htdocs/advanced_search.php
include/search.classes.inc.php

index 2386d12..5c87379 100644 (file)
@@ -10,8 +10,15 @@ require_once("geoloc.inc.php");
 if (array_key_exists('rechercher', $_REQUEST)) {
     $page->assign('formulaire',0);
 
-    $nameField = new StringSField('name',array('u.nom','u.epouse'),'');
-    $firstnameField = new StringSField('firstname',array('u.prenom'),'');
+    $with_soundex = ((isset($_REQUEST['with_soundex']) && $_REQUEST['with_soundex']==1));
+
+    if ($with_soundex) {
+        $nameField = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule');
+        $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule');
+    } else {
+        $nameField = new StringSField('name',array('u.nom','u.epouse'),'');
+        $firstnameField = new StringSField('firstname',array('u.prenom'),'');
+    }
     $promo1Field = new PromoSField('promo1','egal1',array('u.promo'),'');
     $promo2Field = new PromoSField('promo2','egal2',array('u.promo'),'');
    
@@ -68,7 +75,7 @@ if (array_key_exists('rechercher', $_REQUEST)) {
     $nbpages = ($page->get_template_vars('nb_resultats_total')-1)/$globals->search_results_per_page;
     $page->assign('offsets',range(0,$nbpages));
     $page->assign('url_args',$fields->get_url());
-    $page->assign('with_soundex',0);
+    $page->assign('with_soundex',$with_soundex);
     $page->assign('offset',$offset->value);
     $page->assign('perpage',$globals->search_results_per_page);
     $page->assign('is_admin',has_perms());
index 78975a9..5f2e868 100644 (file)
@@ -126,17 +126,30 @@ class RefSField extends SField {
             return " LIKE '%".$this->value."%'";
     }
 
+    function get_single_match_statement($field) {
+        return $field.$this->compare();
+    }
+
     function get_single_where_statement($field) {
         if ($this->refTable=='')
-            return $field.$this->compare();
+            return $this->get_single_match_statement($field);
         return false;
     }
 
     function get_select_statement() {
         if ($this->value=='' || $this->refTable=='')
             return false;
+        $res = implode(' OR ',array_filter(array_map(array($this,'get_single_match_statement'),$this->fieldDbName)));
         return 'INNER JOIN '.$this->refTable.' AS '.$this->refAlias.
-        ' ON('.$this->refCondition.' AND '.$this->fieldDbName[0].$this->compare().")";
+        ' ON('.$this->refCondition.' AND '.'('.$res.')'.")";
+    }
+}
+
+class RefWithSoundexSField extends RefSField {
+    function get_request() {
+        parent::get_request();
+        if ($this->value!='')
+            $this->value=soundex_fr($this->value);
     }
 }