Update of /var/cvs/contributions/lucene/src/org/mmbase/module/lucene
In directory james.mmbase.org:/tmp/cvs-serv29898

Modified Files:
        Searcher.java 
Log Message:
If a corrupt index is detected, try to implicitely repare it


See also: 
http://cvs.mmbase.org/viewcvs/contributions/lucene/src/org/mmbase/module/lucene


Index: Searcher.java
===================================================================
RCS file: 
/var/cvs/contributions/lucene/src/org/mmbase/module/lucene/Searcher.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- Searcher.java       23 Jul 2008 13:58:48 -0000      1.51
+++ Searcher.java       20 Aug 2008 10:54:39 -0000      1.52
@@ -34,7 +34,7 @@
  * A wrapper around Lucene's [EMAIL PROTECTED] 
org.apache.lucene.search.IndexSearcher}. Every [EMAIL PROTECTED] Indexer} has 
its own Searcher.
  *
  * @author Pierre van Rooden
- * @version $Id: Searcher.java,v 1.51 2008/07/23 13:58:48 michiel Exp $
+ * @version $Id: Searcher.java,v 1.52 2008/08/20 10:54:39 michiel Exp $
  * @todo  Should the StopAnalyzers be replaced by index.analyzer? Something 
else?
  **/
 public class Searcher implements NewSearcher.Listener, 
FullIndexEvents.Listener {
@@ -86,6 +86,19 @@
         return status != FullIndexEvents.Status.IDLE ? intermediateSize : -1;
     }
 
+    protected void repare(final CorruptIndexException ci, final boolean copy) {
+        org.mmbase.util.ThreadPools.jobsExecutor.execute(new Runnable() {
+                public void run() {
+                    log.info("Reparing index " + index + " because " + 
ci.getMessage());
+                    index.clear(true);
+                    if (! copy) {
+                        index.clear(false);
+                        index.fullIndex();
+                    }
+                }
+            });
+    }
+
     protected synchronized IndexSearcher getSearcher(boolean copy) throws 
IOException {
         if (copy) return  new IndexSearcher(index.getDirectoryForFullIndex());
         if (searcher != null && needsNewSearcher) {
@@ -107,9 +120,14 @@
                 }, 10000);
         }
         if (searcher == null) {
+            try {
             searcher = new IndexSearcher(index.getDirectory());
             needsNewSearcher = false;
             return searcher;
+            } catch (CorruptIndexException ci) {
+                repare(ci, copy);
+                throw ci;
+            }
         } else {
             return searcher;
         }
@@ -283,6 +301,10 @@
             } catch ( FileNotFoundException nfe) {
                 log.debug(nfe + " returning -1");
                 return -1;
+            } catch (CorruptIndexException ci) {
+                repare(ci, copy);
+                log.warn(ci + " returning -1");
+                return -1;
             } catch (IOException ioe) {
                 log.service(ioe + " returning -1");
                 return -1;
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to