[SPIP] ~maj 3.0.10 --> 3.0.14
[lhc/web/www.git] / www / ecrire / inc / rechercher.php
index 858137f..28bcbc3 100644 (file)
@@ -3,7 +3,7 @@
 /***************************************************************************\
  *  SPIP, Systeme de publication pour l'internet                           *
  *                                                                         *
- *  Copyright (c) 2001-2012                                                *
+ *  Copyright (c) 2001-2014                                                *
  *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
  *                                                                         *
  *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
@@ -70,9 +70,21 @@ function expression_recherche($recherche, $options) {
        }
        else{
                // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP
+               // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
+               // 'une', 'des' ...)
                if (preg_match(",\s+,".$u, $recherche)){
                        $is_preg = true;
-                       $recherche = preg_replace(',\s+,'.$u, '|', $recherche);
+                       $recherche_inter = '|';
+                       $recherche_mots = explode(' ', $recherche);
+                       $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
+                       foreach ($recherche_mots as $mot) {
+                               if (strlen($mot) >= $min_long) {
+                                       $recherche_inter .= $mot.' ';
+                               }
+                       }
+                       // mais on cherche quand même l'expression complète, même si elle
+                       // comporte des mots de moins de quatre lettres
+                       $recherche = rtrim($recherche.preg_replace(',\s+,'.$u, '|', $recherche_inter), '|');
                }
 
                $preg = '/'.str_replace('/', '\\/', $recherche).'/' . $options['preg_flags'];