diff --git a/ecrire/inc/prepare_recherche.php b/ecrire/inc/prepare_recherche.php index 78672cb0c7f8bc5be2eda58d01961bd6f3a80e74..d6534c273117bbbcb1f75d2f4487da09e8139a95 100644 --- a/ecrire/inc/prepare_recherche.php +++ b/ecrire/inc/prepare_recherche.php @@ -31,8 +31,8 @@ function inc_prepare_recherche_dist($recherche, $table='articles', $cond=false, // traiter le cas {recherche?} if ($cond AND !strlen($recherche)) return array("0 as points" /* as points */, /* where */ ''); - - + + $rechercher = false; if (!isset($cache[$recherche][$table])){ diff --git a/ecrire/inc/rechercher.php b/ecrire/inc/rechercher.php index c503e79fa04fca1e01205d88c3268ca83df5b579..4e436da4a6585b7954976e30691cfe426a7e2146 100644 --- a/ecrire/inc/rechercher.php +++ b/ecrire/inc/rechercher.php @@ -132,21 +132,24 @@ function recherche_en_base($recherche='', $tables=NULL, $options=array(), $serve if (!strlen($recherche)) return array(); + $preg = '/'.$recherche.'/' . $options['preg_flags']; + // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite - if (preg_quote($recherche, '/') == $recherche) { + // ou si l'expression reguliere est invalide + if (preg_quote($recherche, '/') == $recherche + OR (@preg_match($preg,'')===FALSE) ) { $methode = 'LIKE'; $q = sql_quote( "%" - . str_replace(array('%','_'), array('\%', '\_'), $recherche) + . preg_replace(",\s+,","%",str_replace(array('%','_'), array('\%', '\_'), trim($recherche))) . "%" ); + $preg = '/'.preg_replace(",\s+,",".+",trim($recherche)).'/' . $options['preg_flags']; } else { $methode = 'REGEXP'; $q = sql_quote($recherche); } - $preg = '/'.$recherche.'/' . $options['preg_flags']; - $jointures = $options['jointures'] ? liste_des_jointures() : array();