CVS: spip/ecrire inc_base.php3, 1.98, 1.99 inc_cron.php3, 1.4, 1.5 inc_index.php3, 1.50, 1.51 inc_version.php3, 1.295, 1.296

Update of /home/spip-cvs/spip/ecrire
In directory miel:/tmp/cvs-serv19463/ecrire

Modified Files:
  inc_base.php3 inc_cron.php3 inc_index.php3 inc_version.php3
Log Message:
moteur de recherche newlook
(Ã tester !)

Index: inc_base.php3

RCS file: /home/spip-cvs/spip/ecrire/inc_base.php3,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- inc_base.php3 2 Feb 2004 01:49:37 -0000 1.98
+++ inc_base.php3 24 Feb 2004 22:30:55 -0000 1.99
@@ -42,9 +42,10 @@
     lang VARCHAR(10) DEFAULT '' NOT NULL,
     langue_choisie VARCHAR(3) DEFAULT 'non',
     id_trad bigint(21) DEFAULT '0' NOT NULL,
- extra longblob NULL,
     nom_site tinytext NOT NULL,
     url_site VARCHAR(255) NOT NULL,
+ extra longblob NULL,
+ index ENUM('', '1', 'non', 'oui', 'indx') DEFAULT '' NOT NULL,
     id_version int unsigned DEFAULT '0' NOT NULL,
     PRIMARY KEY (id_article),
     KEY id_rubrique (id_rubrique),
@@ -53,7 +54,8 @@
     KEY lang (lang),
     KEY statut (statut, date),
     KEY url_site (url_site),
- KEY date_modif (date_modif))";
+ KEY date_modif (date_modif),
+ KEY index (index))";
   $result = spip_query($query);

   $query = "CREATE TABLE spip_auteurs (
@@ -80,11 +82,13 @@
     source VARCHAR(10) DEFAULT 'spip' NOT NULL,
     lang VARCHAR(10) DEFAULT '' NOT NULL,
     extra longblob NULL,
+ idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL,
     PRIMARY KEY (id_auteur),
     KEY login (login),
     KEY statut (statut),
     KEY lang (lang),
- KEY en_ligne (en_ligne))";
+ KEY en_ligne (en_ligne),
+ KEY idx (idx))";
   $result = spip_query($query);

   $query = "CREATE TABLE spip_breves (
@@ -100,8 +104,10 @@
     langue_choisie VARCHAR(3) DEFAULT 'non',
     maj TIMESTAMP,
     extra longblob NULL,
+ idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL,
     PRIMARY KEY (id_breve),
- KEY id_rubrique (id_rubrique))";
+ KEY id_rubrique (id_rubrique),
+ KEY idx (idx))";
   $result = spip_query($query);

   $query = "CREATE TABLE spip_messages (
@@ -127,9 +133,11 @@
     texte longblob NOT NULL,
     id_groupe bigint(21) NOT NULL,
     extra longblob NULL,
+ idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL,
     maj TIMESTAMP,
     PRIMARY KEY (id_mot),
- KEY type(type))";
+ KEY type(type),
+ KEY idx (idx))";
   $result = spip_query($query);

   $query = "CREATE TABLE spip_groupes_mots (
@@ -163,9 +171,11 @@
     lang VARCHAR(10) DEFAULT '' NOT NULL,
     langue_choisie VARCHAR(3) DEFAULT 'non',
     extra longblob NULL,
+ idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL,
     PRIMARY KEY (id_rubrique),
     KEY lang (lang),
- KEY id_parent (id_parent))";
+ KEY id_parent (id_parent),
+ KEY idx (idx))";
   $result = spip_query($query);

   $query = "CREATE TABLE spip_documents (
@@ -210,6 +220,7 @@
     url_site blob NOT NULL,
     url_syndic blob NOT NULL,
     descriptif blob NOT NULL,
+ idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL,
     maj TIMESTAMP,
     syndication VARCHAR(3) NOT NULL,
     statut VARCHAR(10) NOT NULL,
@@ -220,7 +231,8 @@
     PRIMARY KEY (id_syndic),
     KEY id_rubrique (id_rubrique),
     KEY id_secteur (id_secteur),
- KEY statut (statut, date_syndic))";
+ KEY statut (statut, date_syndic),
+ KEY idx (idx))";
   $result = spip_query($query);

   $query = "CREATE TABLE spip_syndic_articles (
@@ -259,6 +271,7 @@
     nom_site text NOT NULL,
     url_site text NOT NULL,
     statut varchar(8) NOT NULL,
+ idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL,
     ip varchar(16),
     maj TIMESTAMP,
     id_auteur BIGINT DEFAULT '0' NOT NULL,
@@ -271,7 +284,8 @@
     KEY id_breve (id_breve),
     KEY id_message (id_message),
     KEY id_syndic (id_syndic),
- KEY statut (statut, date_heure))";
+ KEY statut (statut, date_heure),
+ KEY idx (idx))";
   $result = spip_query($query);

   $query = "CREATE TABLE spip_petitions (
@@ -295,10 +309,12 @@
     url_site text NOT NULL,
     message mediumtext NOT NULL,
     statut varchar(10) NOT NULL,
+ idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL,
     maj TIMESTAMP,
     PRIMARY KEY (id_signature),
     KEY id_article (id_article),
- KEY statut(statut))";
+ KEY statut(statut),
+ KEY idx (idx))";
   $result = spip_query($query);

   $query = "CREATE TABLE spip_visites_temp (
@@ -554,6 +570,22 @@
     KEY id_syndic (id_syndic))";
   $result = spip_query($query);

+ $query = "CREATE TABLE spip_index_signatures (
+ hash bigint unsigned NOT NULL,
+ points int unsigned DEFAULT '0' NOT NULL,
+ id_signature int unsigned NOT NULL,
+ KEY hash (hash),
+ KEY id_signature (id_signature))";
+ $result = spip_query($query);
+
+ $query = "CREATE TABLE spip_index_forum (
+ hash bigint unsigned NOT NULL,
+ points int unsigned DEFAULT '0' NOT NULL,
+ id_forum int unsigned NOT NULL,
+ KEY hash (hash),
+ KEY id_forum (id_forum))";
+ $result = spip_query($query);
+
   $query = "CREATE TABLE spip_index_dico (
     hash bigint unsigned NOT NULL,
     dico VARCHAR(30) NOT NULL,
@@ -1434,6 +1466,26 @@
   if ($version_installee < 1.728) {
     spip_query("ALTER TABLE spip_articles ADD id_version int unsigned DEFAULT '0' NOT NULL");
     maj_version (1.728);
+ }
+
+ if ($version_installee < 1.730) {
+ spip_query("ALTER TABLE spip_articles ADD idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL");
+ spip_query("ALTER TABLE spip_articles INDEX idx (idx)");
+ spip_query("ALTER TABLE spip_auteurs ADD idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL");
+ spip_query("ALTER TABLE spip_auteurs INDEX idx (idx)");
+ spip_query("ALTER TABLE spip_breves ADD idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL");
+ spip_query("ALTER TABLE spip_breves INDEX idx (idx)");
+ spip_query("ALTER TABLE spip_mots ADD idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL");
+ spip_query("ALTER TABLE spip_mots INDEX idx (idx)");
+ spip_query("ALTER TABLE spip_rubriques ADD idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL");
+ spip_query("ALTER TABLE spip_rubriques INDEX idx (idx)");
+ spip_query("ALTER TABLE spip_syndic ADD idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL");
+ spip_query("ALTER TABLE spip_syndic INDEX idx (idx)");
+ spip_query("ALTER TABLE spip_forum ADD idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL");
+ spip_query("ALTER TABLE spip_forum ADD INDEX idx (idx)");
+ spip_query("ALTER TABLE spip_signatures ADD idx ENUM('', '1', 'non', 'oui', 'idx') DEFAULT '' NOT NULL");
+ spip_query("ALTER TABLE spip_signatures INDEX idx (idx)");
+ maj_version (1.730);
   }

   return true;

Index: inc_cron.php3

RCS file: /home/spip-cvs/spip/ecrire/inc_cron.php3,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- inc_cron.php3 28 Jan 2004 19:55:34 -0000 1.4
+++ inc_cron.php3 24 Feb 2004 22:30:55 -0000 1.5
@@ -173,36 +173,13 @@

   //
- // Gerer l'indexation automatique
+ // Gerer l'indexation
   //

- if (lire_meta('activer_moteur') == 'oui') {
- $fichier_index = $dir_ecrire.'data/.index';
- if ($id_article OR $id_auteur OR $id_breve OR $id_mot OR $id_rubrique) {
+ if ($use_cache AND (lire_meta('activer_moteur') == 'oui')) {
+ if (timeout('indexation')) {
       include_ecrire("inc_index.php3");
- $s = '';
- if ($id_article AND !deja_indexe('article', $id_article))
- $s .= "article $id_article\n";
- if ($id_auteur AND !deja_indexe('auteur', $id_auteur))
- $s .= "auteur $id_auteur\n";
- if ($id_breve AND !deja_indexe('breve', $id_breve))
- $s .= "breve $id_breve\n";
- if ($id_mot AND !deja_indexe('mot', $id_mot))
- $s .= "mot $id_mot\n";
- if ($id_rubrique AND !deja_indexe('rubrique', $id_rubrique))
- $s .= "rubrique $id_rubrique\n";
- if ($s) {
- if ($f = @fopen($fichier_index, 'a')) {
- fputs($f, $s);
- fclose($f);
- }
- }
- }
- if ($use_cache AND @file_exists($fichier_index)) {
- if (timeout('indexation')) {
- include_ecrire("inc_index.php3");
- effectuer_une_indexation();
- }
+ effectuer_une_indexation();
     }
   }

Index: inc_index.php3

RCS file: /home/spip-cvs/spip/ecrire/inc_index.php3,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- inc_index.php3 28 Jan 2004 00:00:46 -0000 1.50
+++ inc_index.php3 24 Feb 2004 22:30:55 -0000 1.51
@@ -69,30 +69,36 @@
}

function deja_indexe($type, $id_objet) {
- $table_index = 'spip_index_'.$type.'s';
+ $table_index = 'spip_index_'.table_objet($type);
   $col_id = 'id_'.$type;
   $query = "SELECT $col_id FROM $table_index WHERE $col_id=$id_objet LIMIT 0,1";
   $n = @spip_num_rows(@spip_query($query));
   return ($n > 0);
}

-function indexer_objet($type, $id_objet, $forcer_reset = true, $full = true) {
+function indexer_objet($type, $id_objet, $forcer_reset = true, $full = true /* full : inutilise ? */) {
   global $index, $mots;

- if (!$id_objet OR (!$forcer_reset AND deja_indexe($type, $id_objet))) return;
+ $table = 'spip_'.table_objet($type);
+ $table_index = 'spip_index_'.table_objet($type);
+ $col_id = 'id_'.$type;
+
+ if (!$id_objet) return;
+ if (!$forcer_reset AND deja_indexe($type, $id_objet)) {
+ spip_log ("$type $id_objet deja indexe");
+ spip_query("UPDATE $table SET idx='oui' WHERE $col_id=$id_objet");
+ return;
+ }
+ // marquer "en cours d'indexation"
+ spip_query("UPDATE $table SET idx='idx' WHERE $col_id=$id_objet");
+
+ include_ecrire("inc_texte.php3");
+ include_ecrire("inc_filtres.php3");

   spip_log("indexation $type $id_objet");
   $index = '';
   $mots = "INSERT IGNORE INTO spip_index_dico (hash, dico) VALUES (0,'')";

- if ($type != 'syndic'){
- $table_index = 'spip_index_'.$type.'s';
- } else {
- $table_index = "spip_index_".$type;
- }
- $col_id = 'id_'.$type;
-
-
   switch($type) {
   case 'article':
     $query = "SELECT * FROM spip_articles WHERE id_article=$id_objet";
@@ -223,21 +229,25 @@
     while (list($hash, $points) = each($index)) $q[] = "(0x$hash,$points,$id_objet)";
     spip_query("INSERT INTO $table_index (hash, points, $col_id) VALUES ".join(',',$q));
   }
+
+ // marquer "indexe"
+ spip_query("UPDATE $table SET idx='oui' WHERE $col_id=$id_objet");
}

+/*
+ Valeurs du champ 'idx' de la table spip_objet(s)
+ '' ne sait pas
+ '1' ˆ (re)indexer
+ 'oui' deja indexe
+ 'idx' en cours
+ 'non' ne jamais indexer
+*/

// API pour l'espace prive
function marquer_indexer ($objet, $id_objet) {
- global $dir_ecrire;
- $fichier_index = $dir_ecrire.'data/.index';
- if (!$f = @fopen($fichier_index, 'a')) {
- spip_log ("impossible d'ecrire dans $fichier_index !");
- @unlink ($fichier_index); // on essaie de forcer
- $f = @fopen($fichier_index, 'a');
- }
   spip_log ("demande indexation $objet $id_objet");
- fputs($f, "$objet $id_objet 1\n"); // 1 = forcer reindexation
- fclose($f);
+ $table = 'spip_index_'.table_objet($objet);
+ spip_query ("UPDATE $table SET idx='1' WHERE id_$objet=$id_objet");
}
function indexer_article($id_article) {
   marquer_indexer('article', $id_article);
@@ -259,19 +269,37 @@
}

function effectuer_une_indexation() {
- $fichier_index = 'ecrire/data/.index';
- if ($s = @sizeof($suite = @file($fichier_index))) {
- include_ecrire("inc_texte.php3");
- include_ecrire("inc_filtres.php3");
- $s = $suite[$n = @rand(0, $s-1)];
- unset($suite[$n]);
- $f = fopen($fichier_index, 'wb');
- fwrite($f, join("", $suite));
- fclose($f);
- $s = explode(' ', trim($s));
- indexer_objet($s[0], $s[1], $s[2]);
+ $nombre_indexations = 1; // on peut etre plus gourmand si on est presse
+
+ // chercher un objet a indexer dans une des tables d'objets
+ $types = array('article','auteur','breve','mot','rubrique','syndic','forum','signature');
+ $type = $types[rand(0,sizeof($types)-1)];
+ $table_objet = 'spip_'.table_objet($type);
+ $table_index = 'spip_index_'.table_objet($type);
+
+ // limiter aux objets publies
+ switch ($type) {
+ case 'article':
+ case 'breve':
+ case 'rubrique':
+ case 'syndic':
+ case 'forum':
+ case 'signature':
+ $critere = "AND statut='publie'";
+ break;
+ case 'auteur':
+ $critere = "AND statut IN ('0minirezo', '1comite')";
+ break;
+ case 'mot':
+ default:
+ $critere = '';
+ break;
+ }
+
+ $s = spip_query("SELECT id_$type, idx FROM $table_objet WHERE idx IN ('','1') $critere LIMIT 0,$nombre_indexations");
+ while ($t = spip_fetch_array($s)) {
+ indexer_objet($type, $t[0], $t[1]);
   }
- else @unlink($fichier_index);
}

function executer_une_indexation_syndic() {
@@ -290,33 +318,10 @@
}

function creer_liste_indexation() {
- $fichier_index = 'data/.index';
- $elements = array('article', 'breve', 'mot', 'auteur', 'rubrique', 'syndic');
-
- while (list(,$element) = each ($elements)) {
- $table = "spip_".$element."s";
- if ($element == 'syndic') $table = 'spip_syndic';
- switch($element) {
- case 'article':
- case 'breve':
- case 'syndic':
- $statut = "WHERE statut='publie'";
- break;
- case 'auteur':
- $statut = "WHERE statut IN ('0minirezo', '1comite')";
- break;
- default:
- $statut = '';
- }
-
- $res = spip_query("SELECT id_$element FROM $table $statut");
- while ($row = spip_fetch_array($res))
- $liste .= "$element ".$row["id_$element"]."\n";
- }
-
- if ($f = @fopen("$fichier_index", "w")) {
- @fputs($f, $liste);
- @fclose($f);
+ $types = array('article','auteur','breve','mot','rubrique','syndic','forum','signature');
+ while (list(,$type) = each($types)) {
+ $table = table_objet($type);
+ spip_query("UPDATE $table SET idx='1'");
   }
}

@@ -327,23 +332,20 @@
     spip_query("DELETE FROM spip_index_mots");
     spip_query("DELETE FROM spip_index_rubriques");
     spip_query("DELETE FROM spip_index_syndic");
+ spip_query("DELETE FROM spip_index_forum");
+ spip_query("DELETE FROM spip_index_signatures");
     spip_query("DELETE FROM spip_index_dico");
}

// cree la requete pour une recherche en txt integral
function requete_txt_integral($objet, $hash_recherche) {
- if ($objet == 'syndic') {
- $table = "spip_".$objet;
- $index_table = "spip_index_".$objet;
- } else {
- $table = "spip_".$objet."s";
- $index_table = "spip_index_".$objet."s";
- }
+ $table = "spip_".table_objet($objet);
+ $index_table = "spip_index_".table_objet($objet);
   $id_objet = "id_".$objet;
- return "SELECT objet.*, SUM(idx.points) AS points
- FROM $table AS objet, $index_table AS idx
- WHERE objet.$id_objet = idx.$id_objet
- AND idx.hash IN ($hash_recherche)
+ return "SELECT objet.*, SUM(rec.points) AS points
+ FROM $table AS objet, $index_table AS rec
+ WHERE objet.$id_objet = rec.$id_objet
+ AND rec.hash IN ($hash_recherche)
     GROUP BY objet.$id_objet
     ORDER BY points DESC
     LIMIT 0,10";

Index: inc_version.php3

RCS file: /home/spip-cvs/spip/ecrire/inc_version.php3,v
retrieving revision 1.295
retrieving revision 1.296
diff -u -d -r1.295 -r1.296
--- inc_version.php3 22 Feb 2004 16:42:21 -0000 1.295
+++ inc_version.php3 24 Feb 2004 22:30:55 -0000 1.296
@@ -156,7 +156,7 @@
// (utilise pour les modifs de la base de donnees)

// version de la base
-$spip_version = 1.728;
+$spip_version = 1.730;

// version de spip
$spip_version_affichee = "1.7 CVS";
@@ -815,6 +815,16 @@
$langue_site = lire_meta('langue_site');
if (!$langue_site) include_ecrire('inc_lang.php3');
$spip_lang = $langue_site;
+
+
+// Nommage bizarre des tables d'objets
+function table_objet($type) {
+ if ($type == 'syndic' OR $type == 'forum')
+ return $type;
+ else
+ return $type.'s';
+}
+

//
// Enregistrement des evenements