From 9ef489e05f119087dd73d2aa51417cdbbe65563d Mon Sep 17 00:00:00 2001 From: x2000bedo Date: Sun, 15 Aug 2004 00:57:54 +0000 Subject: [PATCH] =?utf8?q?Mise=20=E0=20jour=20search.php=20pour=20la=20req?= =?utf8?q?u=EAte=20am=E9lior=E9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- htdocs/search.php | 20 +++++++++++--------- include/search.classes.inc.php | 11 ++++++++--- scripts/cron/recherche.sql | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/htdocs/search.php b/htdocs/search.php index 6a2950e..9649bf6 100644 --- a/htdocs/search.php +++ b/htdocs/search.php @@ -16,16 +16,16 @@ if (array_key_exists('rechercher', $_REQUEST)) { $with_soundex = ((isset($_REQUEST['with_soundex']) && $_REQUEST['with_soundex']==1)); if ($with_soundex) { - $nameField = new StringWithSoundexSField('name',array('u.nom_soundex','u.epouse_soundex','i.nom_soundex'),'i.nom'); - $firstnameField = new StringWithSoundexSField('firstname',array('u.prenom_soundex','i.prenom_soundex'),'i.prenom'); + $nameField = new StringWithSoundexSField('name',array('s.nom_soundex','s.epouse_soundex','i.nom_soundex'),''); + $firstnameField = new StringWithSoundexSField('firstname',array('s.prenom_soundex','i.prenom_soundex'),''); } else { - $nameField = new StringSField('name',array('u.nom','u.epouse','i.nom'),'i.nom'); - $firstnameField = new StringSField('firstname',array('u.prenom','i.prenom'),'i.prenom'); + $nameField = new StringSField('name',array('r.nom1','r.nom2','r.nom3'),''); + $firstnameField = new StringSField('firstname',array('r.prenom1','r.prenom2'),''); $with_soundex = ($nameField->length()==0 && $firstnameField->length()==0)?(-1):0; } - $promo1Field = new PromoSField('promo1','egal1',array('u.promo','i.promo'),'i.promo'); - $promo2Field = new PromoSField('promo2','egal2',array('u.promo','i.promo'),'i.promo'); + $promo1Field = new PromoSField('promo1','egal1',array('r.promo'),''); + $promo2Field = new PromoSField('promo2','egal2',array('r.promo'),''); $fields = new SFieldGroup(true,array($nameField,$firstnameField,$promo1Field,$promo2Field)); if ($nameField->length()<2 && $firstnameField->length()<2 && @@ -36,7 +36,7 @@ if (array_key_exists('rechercher', $_REQUEST)) { $offset = new NumericSField('offset'); $sql = 'SELECT SQL_CALC_FOUND_ROWS - i.matricule_ax,i.matricule, + r.matricule,i.matricule_ax, u.nom!="" AS inscrit, IF(u.nom!="",u.nom,i.nom) AS nom, u.epouse, @@ -48,8 +48,10 @@ 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 identification AS i - LEFT JOIN auth_user_md5 AS u ON (i.matricule=u.matricule) + FROM 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/search.classes.inc.php b/include/search.classes.inc.php index ee83b5a..134c947 100644 --- a/include/search.classes.inc.php +++ b/include/search.classes.inc.php @@ -117,10 +117,15 @@ class StringSField extends SField { * @param field nom de champ de la bdd concerné par la clause */ function get_single_where_statement($field) { //on rend les traits d'union et les espaces équivalents - $regexp = preg_replace('/[ -]/','[ \-]',$this->value); + //$regexp = preg_replace('/[ -]/','[ \-]',$this->value); //on remplace le pseudo language des * par une regexp - $regexp = str_replace('*','.+',$regexp); - return $field." RLIKE '^(.*[ -])?".replace_accent_regexp($regexp).".*'"; + //$regexp = str_replace('*','.+',$regexp); + //return $field." RLIKE '^(.*[ -])?".replace_accent_regexp($regexp).".*'"; + + //Nouvelle version plus rapide + $regexp = str_replace('-',' ',$this->value); + $regexp = str_replace('*','%',$regexp); + return $field." LIKE LCASE($regexp%)"; } /** clause ORDER BY correspondant à ce champ de formulaire */ diff --git a/scripts/cron/recherche.sql b/scripts/cron/recherche.sql index 3db8c2d..d43d25e 100644 --- a/scripts/cron/recherche.sql +++ b/scripts/cron/recherche.sql @@ -1,5 +1,5 @@ USE x4dat; -DROP TABLE recherche; +DROP TABLE IF EXISTS recherche; CREATE TABLE recherche SELECT i.matricule AS matricule,LOWER(REPLACE(i.nom,'-',' ')) AS nom1, 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 -- 2.1.4