diff --git a/.gitattributes b/.gitattributes
index cc147202614922a7c1e516417450f7a052c59ba9..2c2301eb65baa6d8e223b45ae8164982a42abbd1 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -615,6 +615,7 @@ ecrire/inc/notifications.php -text
 ecrire/inc/petitionner.php -text
 ecrire/inc/plonger.php -text
 ecrire/inc/plugin.php -text
+ecrire/inc/prepare_recherche.php -text
 ecrire/inc/puce_statut.php -text
 ecrire/inc/rechercher.php -text
 ecrire/inc/referencer_traduction.php -text
diff --git a/ecrire/inc/prepare_recherche.php b/ecrire/inc/prepare_recherche.php
new file mode 100644
index 0000000000000000000000000000000000000000..0e32fcaec42692efe91e5d5e70fb489e32d82437
--- /dev/null
+++ b/ecrire/inc/prepare_recherche.php
@@ -0,0 +1,96 @@
+<?php
+
+/***************************************************************************\
+ *  SPIP, Systeme de publication pour l'internet                           *
+ *                                                                         *
+ *  Copyright (c) 2001-2007                                                *
+ *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
+ *                                                                         *
+ *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
+ *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
+\***************************************************************************/
+
+
+if (!defined("_ECRIRE_INC_VERSION")) return;
+
+
+// Preparer les listes id_article IN (...) pour les parties WHERE
+// et points =  des requetes du moteur de recherche
+function inc_prepare_recherche_dist($recherche, $primary = 'id_article', $id_table='articles',$nom_table='spip_articles', $cond=false) {
+	static $cache = array();
+	static $fcache = array();
+
+	// si recherche n'est pas dans le contexte, on va prendre en globals
+	// ca permet de faire des inclure simple.
+	if (!isset($recherche) AND isset($GLOBALS['recherche']))
+		$recherche = $GLOBALS['recherche'];
+
+	// traiter le cas {recherche?}
+	if ($cond AND !strlen($recherche))
+		return array("''" /* as points */, /* where */ '1');
+
+	// Premier passage : chercher eventuel un cache des donnees sur le disque
+	if (!$cache[$recherche]['hash']) {
+		$dircache = sous_repertoire(_DIR_CACHE,'rech');
+		$fcache[$recherche] =
+			$dircache . substr(md5($recherche),0,10).'.txt';
+		if (lire_fichier($fcache[$recherche], $contenu))
+			$cache[$recherche] = @unserialize($contenu);
+	}
+
+	// si on n'a pas encore traite les donnees dans une boucle precedente
+	if (!$cache[$recherche][$primary]) {
+
+		$tables = liste_des_champs();
+		$x = preg_replace(',s$,', '', $id_table);
+		if ($x == 'syndic') $x = 'site';
+		$points = recherche_en_base($recherche,
+			$x,
+			array(
+				'score' => true,
+				'toutvoir' => true,
+				'jointures' => true
+			));
+		$points = $points[$x];
+
+		# Pour les forums, unifier par id_thread et forcer statut='publie'
+		if ($x == 'forum' AND $points) {
+			$p2 = array();
+			$s = spip_query("SELECT id_thread, id_forum FROM spip_forum WHERE statut='publie' AND ".calcul_mysql_in('id_forum', array_keys($points)));
+			while ($t = spip_fetch_array($s))
+				$p2[intval($t['id_thread'])]['score']
+					+= $points[intval($t['id_forum'])]['score'];
+			$points = $p2;
+		}
+
+		# calculer le {id_article IN()} et le {... as points}
+		if (!count($points)) {
+			$cache[$recherche][$primary] = array("''", '0');
+		} else {
+			$listes_ids = array();
+			$select = '0';
+			foreach ($points as $id => $p)
+				$listes_ids[$p['score']] .= ','.$id;
+			foreach ($listes_ids as $p => $liste_ids)
+				$select .= "+$p*(".
+					calcul_mysql_in("$id_table.$primary", substr($liste_ids, 1))
+					.") ";
+
+			$cache[$recherche][$primary] = array($select,
+				'('.calcul_mysql_in("$id_table.$primary",
+					array_keys($points)).')'
+				);
+		}
+
+		// ecrire le cache de la recherche sur le disque
+		ecrire_fichier($fcache[$recherche], serialize($cache[$recherche]));
+		// purger le petit cache
+		nettoyer_petit_cache('rech', 300);
+	}
+
+	return $cache[$recherche][$primary];
+}
+
+
+
+?>
diff --git a/ecrire/inc/rechercher.php b/ecrire/inc/rechercher.php
index 9080df373a7451d78a37e4c28b7575a08f67c063..1c612668d213220c710907623e45cffbdb02895d 100644
--- a/ecrire/inc/rechercher.php
+++ b/ecrire/inc/rechercher.php
@@ -317,86 +317,4 @@ function remplace_en_base($recherche='', $remplace=NULL, $tables=NULL, $options=
 	}
 }
 
-// Preparer les listes id_article IN (...) pour les parties WHERE
-// et points =  des requetes du moteur de recherche
-// http://doc.spip.org/@prepare_recherche_api
-function prepare_recherche_api($recherche, $primary = 'id_article', $id_table='articles',$nom_table='spip_articles', $cond=false) {
-	static $cache = array();
-	static $fcache = array();
-
-	// si recherche n'est pas dans le contexte, on va prendre en globals
-	// ca permet de faire des inclure simple.
-	if (!isset($recherche) AND isset($GLOBALS['recherche']))
-		$recherche = $GLOBALS['recherche'];
-
-	// traiter le cas {recherche?}
-	if ($cond AND !strlen($recherche))
-		return array("''" /* as points */, /* where */ '1');
-
-	spip_timer("rechapi");
-	// Premier passage : chercher eventuel un cache des donnees sur le disque
-	if (!$cache[$recherche]['hash']) {
-		$dircache = sous_repertoire(_DIR_CACHE,'rech2');
-		$fcache[$recherche] =
-			$dircache . substr(md5($recherche),0,10).'.txt';
-		if (lire_fichier($fcache[$recherche], $contenu))
-			$cache[$recherche] = @unserialize($contenu);
-	}
-
-	// si on n'a pas encore traite les donnees dans une boucle precedente
-	if (!$cache[$recherche][$primary]) {
-		include_spip('inc/rechercher');
-
-		$tables = liste_des_champs();
-		$x = preg_replace(',s$,', '', $id_table);
-		if ($x == 'syndic') $x = 'site';
-		$points = recherche_en_base($recherche,
-			$x,
-			array(
-				'score' => true,
-				'toutvoir' => true,
-				'jointures' => true
-			));
-		$points = $points[$x];
-
-		# Pour les forums, unifier par id_thread et forcer statut='publie'
-		if ($x == 'forum' AND $points) {
-			$p2 = array();
-			$s = spip_query("SELECT id_thread, id_forum FROM spip_forum WHERE statut='publie' AND ".calcul_mysql_in('id_forum', array_keys($points)));
-			while ($t = spip_fetch_array($s))
-				$p2[intval($t['id_thread'])]['score']
-					+= $points[intval($t['id_forum'])]['score'];
-			$points = $p2;
-		}
-
-		# calculer le {id_article IN()} et le {... as points}
-		if (!count($points)) {
-			$cache[$recherche][$primary] = array("''", '0');
-		} else {
-			$listes_ids = array();
-			$select = '0';
-			foreach ($points as $id => $p)
-				$listes_ids[$p['score']] .= ','.$id;
-			foreach ($listes_ids as $p => $liste_ids)
-				$select .= "+$p*(".
-					calcul_mysql_in("$id_table.$primary", substr($liste_ids, 1))
-					.") ";
-
-			$cache[$recherche][$primary] = array($select,
-				'('.calcul_mysql_in("$id_table.$primary",
-					array_keys($points)).')'
-				);
-		}
-
-		// ecrire le cache de la recherche sur le disque
-		ecrire_fichier($fcache[$recherche], serialize($cache[$recherche]));
-		// purger le petit cache
-		nettoyer_petit_cache('rech2', 300);
-	}
-
-	spip_log("recherche api ($recherche) de #$primary# : ".spip_timer("rechapi"));
-
-	return $cache[$recherche][$primary];
-}
-
 ?>
diff --git a/ecrire/public/criteres.php b/ecrire/public/criteres.php
index 7a58983b2c0549b28559ff2e76484d82a983b911..0c78925b3dab5813cd93667690d39965e1cf6b0b 100644
--- a/ecrire/public/criteres.php
+++ b/ecrire/public/criteres.php
@@ -152,8 +152,8 @@ function critere_recherche_dist($idb, &$boucles, $crit) {
 	// Ne pas executer la requete en cas de hash vide
 	$boucle->hash = '
 	// RECHERCHE
-	include_spip("inc/rechercher");
-	list($rech_select, $rech_where) = prepare_recherche_api('.$quoi.', "'.$boucle->primary.'", "'.$boucle->id_table.'", "'.$t.'", "'.$crit->cond.'");
+	$prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\');
+	list($rech_select, $rech_where) = $prepare_recherche('.$quoi.', "'.$boucle->primary.'", "'.$boucle->id_table.'", "'.$t.'", "'.$crit->cond.'");
 	';
 
 	// Sauf si le critere est conditionnel {recherche ?}