lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r931314 - in /lucene/dev/trunk/lucene: backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java src/java/org/apache/lucene/index/DirectoryReader.java src/test/org/apache/lucene/index/TestIndexWriterReader.java
Date Tue, 06 Apr 2010 20:38:14 GMT
Author: mikemccand
Date: Tue Apr  6 20:38:14 2010
New Revision: 931314

URL: http://svn.apache.org/viewvc?rev=931314&view=rev
Log:
LUCENE-1976: fix again for 3.1 (fix was temporarily lost in flex merge)

Modified:
    lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java

Modified: lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java?rev=931314&r1=931313&r2=931314&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java
(original)
+++ lucene/dev/trunk/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java
Tue Apr  6 20:38:14 2010
@@ -86,7 +86,7 @@ public class TestIndexWriterReader exten
 
     // get a reader
     IndexReader r1 = writer.getReader();
-    //assertTrue(r1.isCurrent());
+    assertTrue(r1.isCurrent());
 
     String id10 = r1.document(10).getField("id").stringValue();
     
@@ -94,7 +94,7 @@ public class TestIndexWriterReader exten
     newDoc.removeField("id");
     newDoc.add(new Field("id", Integer.toString(8000), Store.YES, Index.NOT_ANALYZED));
     writer.updateDocument(new Term("id", id10), newDoc);
-    //assertFalse(r1.isCurrent());
+    assertFalse(r1.isCurrent());
 
     IndexReader r2 = writer.getReader();
     assertTrue(r2.isCurrent());
@@ -157,7 +157,7 @@ public class TestIndexWriterReader exten
     IndexReader r0 = writer.getReader();
     assertTrue(r0.isCurrent());
     writer.addIndexesNoOptimize(new Directory[] { dir2 });
-    //assertFalse(r0.isCurrent());
+    assertFalse(r0.isCurrent());
     r0.close();
 
     IndexReader r1 = writer.getReader();

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DirectoryReader.java?rev=931314&r1=931313&r2=931314&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DirectoryReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/DirectoryReader.java Tue Apr
 6 20:38:14 2010
@@ -56,6 +56,7 @@ class DirectoryReader extends IndexReade
   private IndexDeletionPolicy deletionPolicy;
   private Lock writeLock;
   private SegmentInfos segmentInfos;
+  private SegmentInfos segmentInfosStart;
   private boolean stale;
   private final int termInfosIndexDivisor;
 
@@ -148,6 +149,7 @@ class DirectoryReader extends IndexReade
     this.directory = writer.getDirectory();
     this.readOnly = true;
     segmentInfos = infos;
+    segmentInfosStart = (SegmentInfos) infos.clone();
     this.termInfosIndexDivisor = termInfosIndexDivisor;
     if (codecs == null) {
       this.codecs = CodecProvider.getDefault();
@@ -930,7 +932,12 @@ class DirectoryReader extends IndexReade
   @Override
   public boolean isCurrent() throws CorruptIndexException, IOException {
     ensureOpen();
-    return SegmentInfos.readCurrentVersion(directory, codecs) == segmentInfos.getVersion();
+    if (writer == null || writer.isClosed()) {
+      // we loaded SegmentInfos from the directory
+      return SegmentInfos.readCurrentVersion(directory, codecs) == segmentInfos.getVersion();
+    } else {
+      return writer.nrtIsCurrent(segmentInfosStart);
+    }
   }
 
   @Override

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java?rev=931314&r1=931313&r2=931314&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java Tue
Apr  6 20:38:14 2010
@@ -84,6 +84,7 @@ public class TestIndexWriterReader exten
 
     // get a reader
     IndexReader r1 = writer.getReader();
+    assertTrue(r1.isCurrent());
 
     String id10 = r1.document(10).getField("id").stringValue();
     
@@ -91,15 +92,20 @@ public class TestIndexWriterReader exten
     newDoc.removeField("id");
     newDoc.add(new Field("id", Integer.toString(8000), Store.YES, Index.NOT_ANALYZED));
     writer.updateDocument(new Term("id", id10), newDoc);
+    assertFalse(r1.isCurrent());
 
     IndexReader r2 = writer.getReader();
+    assertTrue(r2.isCurrent());
     assertEquals(0, count(new Term("id", id10), r2));
     assertEquals(1, count(new Term("id", Integer.toString(8000)), r2));
     
     r1.close();
     writer.close();
+    assertTrue(r2.isCurrent());
     
     IndexReader r3 = IndexReader.open(dir1, true);
+    assertTrue(r3.isCurrent());
+    assertTrue(r2.isCurrent());
     assertEquals(0, count(new Term("id", id10), r3));
     assertEquals(1, count(new Term("id", Integer.toString(8000)), r3));
 
@@ -143,9 +149,18 @@ public class TestIndexWriterReader exten
     createIndexNoClose(!optimize, "index2", writer2);
     writer2.close();
 
+    IndexReader r0 = writer.getReader();
+    assertTrue(r0.isCurrent());
     writer.addIndexesNoOptimize(new Directory[] { dir2 });
+    assertFalse(r0.isCurrent());
+    r0.close();
 
     IndexReader r1 = writer.getReader();
+    assertTrue(r1.isCurrent());
+
+    writer.commit();
+    assertTrue(r1.isCurrent());
+
     assertEquals(200, r1.maxDoc());
 
     int index2df = r1.docFreq(new Term("indexname", "index2"));



Mime
View raw message