Set memory_limit to 64M and disable debug (and backtraces) in CLI scripts.
[platal.git] / bin / search.rebuild_db.php
index 0509c92..11220f2 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/php5 -q
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require('./connect.db.inc.php');
-require('user.func.inc.php');
+require './connect.db.inc.php';
 
-ini_set('memory_limit', "16M");
-XDB::execute('DELETE FROM search_name');
-
-$res = XDB::iterRow('SELECT auth_user_md5.user_id, nom, prenom, nom_usage, profile_nick FROM auth_user_md5 LEFT JOIN auth_user_quick USING(user_id)');
+$res = XDB::iterRow('SELECT  pid
+                       FROM  profiles');
 $i = 0;
-$muls = array(1, 1, 1, 0.2);
-while ($tmp = $res->next()) {
-    $uid = array_shift($tmp);
-    _user_reindex($uid, $tmp, $muls);
-    printf("\r%u / %u",  ++$i, $res->total());
+$n = $res->total();
+$pids = array();
+while ($pid = $res->next()) {
+    $pids[] = intval($pid[0]);
+    ++$i;
+    if (count($pids) == 100) {
+        Profile::rebuildSearchTokens($pids);
+        printf("\r%u / %u",  $i, $n);
+        $pids = array();
+    }
+}
+if (count($pids) > 0) {
+    Profile::rebuildSearchTokens($pids);
+    printf("\r%u / %u",  $i, $n);
 }
 
 print "done\n";