lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1045212 - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/index/IndexReader.java test/org/apache/lucene/index/TestIndexReader.java
Date Mon, 13 Dec 2010 16:09:01 GMT
Author: mikemccand
Date: Mon Dec 13 16:09:01 2010
New Revision: 1045212

URL: http://svn.apache.org/viewvc?rev=1045212&view=rev
Log:
LUCENE-2812: fix IndexReader.indexExists to return false when segments_N file cannot be read

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java?rev=1045212&r1=1045211&r2=1045212&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexReader.java Mon Dec 13 16:09:01
2010
@@ -835,13 +835,17 @@ public abstract class IndexReader implem
 
   /**
    * Returns <code>true</code> if an index exists at the specified directory.
-   * If the directory does not exist or if there is no index in it.
    * @param  directory the directory to check for an index
    * @return <code>true</code> if an index exists; <code>false</code>
otherwise
    * @throws IOException if there is a problem with accessing the index
    */
   public static boolean indexExists(Directory directory) throws IOException {
-    return SegmentInfos.getCurrentSegmentGeneration(directory) != -1;
+    try {
+      new SegmentInfos().read(directory);
+      return true;
+    } catch (IOException ioe) {
+      return false;
+    }
   }
 
   /** Returns the number of documents in this index. */

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java?rev=1045212&r1=1045211&r2=1045212&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexReader.java Mon Dec
13 16:09:01 2010
@@ -1850,5 +1850,16 @@ public class TestIndexReader extends Luc
     }
     dir.close();
   }
-  
+
+  // LUCENE-2812
+  public void testIndexExists() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()));
+    writer.addDocument(new Document());
+    writer.prepareCommit();
+    assertFalse(IndexReader.indexExists(dir));
+    writer.close();
+    assertTrue(IndexReader.indexExists(dir));
+    dir.close();
+  }
 }



Mime
View raw message