From c579b001208bb629d2e02a1d7a7e442828ab46dd Mon Sep 17 00:00:00 2001 From: x2000bedo Date: Sun, 15 Aug 2004 22:22:30 +0000 Subject: [PATCH] Modification pour virer la table __soundex MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Cela m'a permis de voir que dans la version actuelle du site, on ne mettait pas à jour le soundex quand un admin validait un changement de nom ! Avec la nouvelle version, de tels problèmes ne se poseront plus puisqu'on régénère la table de recherche (donc les soundex) entièrement au moins une fois par jour. Vivement la modularisation pour éviter de telles incohérences... --- htdocs/search.php | 8 ++++---- include/valid_epouses.inc.php | 2 +- scripts/cron/recherche.php | 18 ++++++++++++++++++ scripts/cron/recherche.pl | 8 ++++++-- scripts/cron/recherche.sql | 4 ++++ 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 scripts/cron/recherche.php diff --git a/htdocs/search.php b/htdocs/search.php index 04d1188..c1275dc 100644 --- a/htdocs/search.php +++ b/htdocs/search.php @@ -7,6 +7,7 @@ if ($public_directory) new_skinned_page('search.tpl', AUTH_PUBLIC); else new_skinned_page('search.tpl', AUTH_COOKIE); +$page->assign('advanced',0); $page->assign('public_directory',$public_directory); require_once("applis.func.inc.php"); @@ -17,9 +18,9 @@ if (array_key_exists('rechercher', $_REQUEST)) { if ($with_soundex) { $nameField = new - StringWithSoundexSField('name',array('s.nom_soundex','s.epouse_soundex','i.nom_soundex'),'r.nom1'); + StringWithSoundexSField('name',array('r.nom1_soundex','r.nom2_soundex','r.nom3_soundex'),''); $firstnameField = new - StringWithSoundexSField('firstname',array('s.prenom_soundex','i.prenom_soundex'),'r.prenom1'); + StringWithSoundexSField('firstname',array('r.prenom1_soundex','r.prenom2_soundex'),''); } else { $nameField = new StringSField('name',array('r.nom1','r.nom2','r.nom3'),'r.nom1'); @@ -50,10 +51,9 @@ if (array_key_exists('rechercher', $_REQUEST)) { ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type, ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type, c.uid AS contact - FROM recherche AS r + FROM '.(($with_soundex)?'recherche_soundex':'recherche').' AS r INNER JOIN identification AS i ON (i.matricule=r.matricule) LEFT JOIN auth_user_md5 AS u ON (u.matricule=r.matricule) - '.(($with_soundex)?'LEFT JOIN __soundex AS s ON (s.user_id=u.user_id)':'').' LEFT JOIN contacts AS c ON (c.uid='.((array_key_exists('uid',$_SESSION))?$_SESSION['uid']:0).' AND c.contact=u.user_id) LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0) LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid) diff --git a/include/valid_epouses.inc.php b/include/valid_epouses.inc.php index 3b63199..905b46b 100644 --- a/include/valid_epouses.inc.php +++ b/include/valid_epouses.inc.php @@ -76,7 +76,7 @@ class EpouseReq extends Validate { if($no_update_bd) return false; $alias = ($this->epouse ? $this->alias : ""); - $globals->db->query("UPDATE auth_user_md5 set epouse='".$this->epouse."',epouse_soundex='".soundex_fr($this->epouse)."',alias='".$this->alias."' WHERE user_id=".$this->uid); + $globals->db->query("UPDATE auth_user_md5 set epouse='".$this->epouse."',alias='".$this->alias."' WHERE user_id=".$this->uid); $f = fopen("/tmp/flag_recherche","w"); fputs($f,"1"); fclose($f); diff --git a/scripts/cron/recherche.php b/scripts/cron/recherche.php new file mode 100644 index 0000000..7cdcf88 --- /dev/null +++ b/scripts/cron/recherche.php @@ -0,0 +1,18 @@ +dbhost,$globals->dbuser,$globals->dbpwd); +mysql_select_db($globals->dbdb); + +$result = mysql_query("SELECT matricule,nom1,nom2,nom3,prenom1,prenom2,promo FROM recherche"); + +while ($row = mysql_fetch_row($result)) { + list($matricule,$nom1,$nom2,$nom3,$prenom1,$prenom2,$promo) = $row; + $sql = "INSERT INTO recherche_soundex + (matricule,nom1_soundex,nom2_soundex,nom3_soundex,prenom1_soundex,prenom2_soundex,promo) + VALUES($matricule,'".soundex_fr($nom1)."','".soundex_fr($nom2)."','".soundex_fr($nom3)."','". + soundex_fr($prenom1)."','".soundex_fr($prenom2)."',$promo)"; + mysql_query($sql); +} +?> diff --git a/scripts/cron/recherche.pl b/scripts/cron/recherche.pl index a1a0c4f..695b3d4 100755 --- a/scripts/cron/recherche.pl +++ b/scripts/cron/recherche.pl @@ -5,15 +5,19 @@ my $mode = shift; #mode autre = mise à jour si flag my @args = ("mysql x4dat ; - system(@args) - if (/1/); + if (/1/) { + system(@args); + system(@args2); + } close INFILE; open(OUTFILE,'>/tmp/flag_recherche'); print OUTFILE "0"; diff --git a/scripts/cron/recherche.sql b/scripts/cron/recherche.sql index d43d25e..3b10b07 100644 --- a/scripts/cron/recherche.sql +++ b/scripts/cron/recherche.sql @@ -4,3 +4,7 @@ CREATE TABLE recherche SELECT i.matricule AS matricule,LOWER(REPLACE(i.nom,'-',' LOWER(REPLACE(u.nom,'-',' ')) AS nom2, LOWER(REPLACE(u.epouse,'-',' ')) AS nom3, LOWER(REPLACE(i.prenom,'-',' ')) AS prenom1, LOWER(REPLACE(u.prenom,'-',' ')) AS prenom2,i.promo AS promo FROM identification AS i LEFT JOIN auth_user_md5 AS u ON (u.matricule=i.matricule); +DROP TABLE IF EXISTS recherche_soundex; +CREATE TABLE recherche_soundex (matricule int(8) unsigned PRIMARY KEY,nom1_soundex +char(4),nom2_soundex char(4),nom3_soundex char(4),prenom1_soundex char(4),prenom2_soundex char(4), +promo smallint(4) unsigned); -- 2.1.4