From 5dcd3c41c2b6725f54f5e6860436ef8a3be29232 Mon Sep 17 00:00:00 2001 From: x2000bedo Date: Mon, 30 Aug 2004 23:52:48 +0000 Subject: [PATCH] =?utf8?q?Bug=20"Task=20#37=20=3F=20soundex=20ne=20marche?= =?utf8?q?=20pas=20sur=20la=20recherche=20avanc=E9e"=20r=E9solu?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- htdocs/advanced_search.php | 13 ++++++++++--- include/search.classes.inc.php | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/htdocs/advanced_search.php b/htdocs/advanced_search.php index 2386d12..5c87379 100644 --- a/htdocs/advanced_search.php +++ b/htdocs/advanced_search.php @@ -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()); diff --git a/include/search.classes.inc.php b/include/search.classes.inc.php index 78975a9..5f2e868 100644 --- a/include/search.classes.inc.php +++ b/include/search.classes.inc.php @@ -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); } } -- 2.1.4