Index: LucenePluginApi.java
===================================================================
--- LucenePluginApi.java	(revision 9297)
+++ LucenePluginApi.java	(working copy)
@@ -59,12 +59,10 @@
      */
     public int rebuildIndex()
     {
-        int nbDocuments = -1;
         if (hasAdminRights()) {
-            nbDocuments = getLucenePlugin().rebuildIndex(context);
+            return getLucenePlugin().rebuildIndex(context);
         }
-
-        return nbDocuments;
+        return -2;
     }
 
     /**
@@ -77,12 +75,10 @@
      */
     public int rebuildIndex(com.xpn.xwiki.api.XWiki wiki, Context context)
     {
-        int nbDocuments = -1;
         if (wiki.hasAdminRights()) {
-            nbDocuments = getLucenePlugin().rebuildIndex(context.getContext());
+            return getLucenePlugin().rebuildIndex(context.getContext());
         }
-
-        return nbDocuments;
+        return -2;
     }
 
     /**
Index: IndexRebuilder.java
===================================================================
--- IndexRebuilder.java	(revision 9297)
+++ IndexRebuilder.java	(working copy)
@@ -42,24 +42,56 @@
  * 
  * @version $Id: $
  */
-public class IndexRebuilder
+public class IndexRebuilder implements Runnable
 {
     private static final Log LOG = LogFactory.getLog(IndexRebuilder.class);
 
     private IndexUpdater indexUpdater;
+    private XWikiContext context;
+    private boolean rebuildInProgress = false;
 
     public IndexRebuilder(IndexUpdater indexUpdater, XWikiContext context)
     {
         this.indexUpdater = indexUpdater;
-
         if (indexUpdater.needInitialBuild) {
-            int retval = this.rebuildIndex(context);
+            this.startRebuildIndex(context);
             if (LOG.isInfoEnabled()) {
-                LOG.info("Initializing Lucene search index, " + retval + " documents found");
+                LOG.info("Launched initial lucene indexing");
             }
         }
     }
 
+    public void run() {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Start lucene rebuild thread");
+        }
+        try {
+            rebuildIndex(context);
+        } catch (Exception e) {
+            if (LOG.isErrorEnabled()) {
+                LOG.error("Error in lucene rebuild thread", e);
+            }
+        } finally {
+            rebuildInProgress = false;
+        }
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("End lucene rebuild thread");
+        }
+     }
+
+    public synchronized int startRebuildIndex(XWikiContext context) {
+        if (rebuildInProgress) {
+            LOG.error("Cannot launch rebuild because a build is in progress");
+            return -1;
+        } else {
+            this.context = context;
+            this.rebuildInProgress = true;
+            Thread indexRebuilderThread = new Thread(this);
+            indexRebuilderThread.start();
+            return 0;
+        }
+    }
+
     /**
      * First empties the index, then fetches all Documents, their translations and their attachments
      * for re-addition to the index.
@@ -68,7 +100,7 @@
      * @return total number of documents and attachments successfully added to the indexer queue, -1
      *         when errors occured. TODO: give more detailed results
      */
-    public int rebuildIndex(XWikiContext context)
+    private int rebuildIndex(XWikiContext context)
     {
         this.indexUpdater.cleanIndex();
         int retval = 0;
@@ -143,6 +175,12 @@
                 }
 
                 if (document != null) {
+                    while (this.indexUpdater.getQueueSize()>1000) {
+                            try {
+                            Thread.sleep(30000);
+                            } catch (InterruptedException e) {
+                            }
+                    }
                     this.indexUpdater.add(document, context);
                     retval++;
                     retval += addTranslationsOfDocument(document, context);
Index: LucenePlugin.java
===================================================================
--- LucenePlugin.java	(revision 9297)
+++ LucenePlugin.java	(working copy)
@@ -105,7 +105,7 @@
 
     public synchronized int rebuildIndex(XWikiContext context)
     {
-        return indexRebuilder.rebuildIndex(context);
+        return indexRebuilder.startRebuildIndex(context);
     }
 
     /**
Index: IndexUpdater.java
===================================================================
--- IndexUpdater.java	(revision 9297)
+++ IndexUpdater.java	(working copy)
@@ -55,7 +55,7 @@
     /**
      * Milliseconds of sleep between checks for changed documents
      */
-    private int indexingInterval = 3000;
+    private int indexingInterval = 30000;
 
     private boolean exit = false;
 
@@ -410,7 +410,7 @@
 
         this.indexingInterval =
             1000 * Integer.parseInt(config
-                .getProperty(LucenePlugin.PROP_INDEXING_INTERVAL, "300"));
+                .getProperty(LucenePlugin.PROP_INDEXING_INTERVAL, "30"));
 
         // Note: There's no need to open the Searcher here (with a call to
         // openSearcher()) as each
