lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dor...@apache.org
Subject svn commit: r637041 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/SegmentInfos.java src/test/org/apache/lucene/index/TestIndexReaderReopen.java
Date Fri, 14 Mar 2008 10:35:19 GMT
Author: doronc
Date: Fri Mar 14 03:35:18 2008
New Revision: 637041

URL: http://svn.apache.org/viewvc?rev=637041&view=rev
Log:
LUCENE-1228: IndexWriter.commit() was not updating the index version.

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=637041&r1=637040&r2=637041&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Mar 14 03:35:18 2008
@@ -73,6 +73,9 @@
 
  5. LUCENE-1226: Fixed IndexWriter.addIndexes(IndexReader[]) to commit
     successfully created compound files. (Michael Busch)
+    
+ 6. LUCENE-1228: IndexWriter.commit() was not updating the index version and as
+    result IndexReader.reopen() failed to sense index changes. (Doron Cohen)
 	
 New features
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?rev=637041&r1=637040&r2=637041&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Fri Mar 14 03:35:18
2008
@@ -738,6 +738,7 @@
     assert other.generation > generation;
     lastGeneration = other.lastGeneration;
     generation = other.generation;
+    version = other.version;
   }
 
   /** Writes & syncs to the Directory dir, taking care to

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java?rev=637041&r1=637040&r2=637041&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java Fri Mar
14 03:35:18 2008
@@ -17,6 +17,7 @@
  * limitations under the License.
  */
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -26,22 +27,27 @@
 import java.util.Random;
 import java.util.Set;
 
+import org.apache.lucene.analysis.KeywordAnalyzer;
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.Field.Index;
 import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.index.IndexWriter.MaxFieldLength;
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.RAMDirectory;
 
 import junit.framework.TestCase;
 
 public class TestIndexReaderReopen extends TestCase {
     
+  private File indexDir;
+
   public void testReopen() throws Exception {
     final Directory dir1 = new RAMDirectory();
     
@@ -119,6 +125,68 @@
     });
   }
 
+  // LUCENE-1228: IndexWriter.commit() does not update the index version
+  // populate an index in iterations.
+  // at the end of every iteration, commit the index and reopen/recreate the reader.
+  // in each iteration verify the work of previous iteration. 
+  // try this once with reopen once recreate, on both RAMDir and FSDir.
+  public void testCommitReopenFS () throws IOException {
+    Directory dir = FSDirectory.getDirectory(indexDir);
+    doTestReopenWithCommit(dir, true);
+  }
+  public void testCommitRecreateFS () throws IOException {
+    Directory dir = FSDirectory.getDirectory(indexDir);
+    doTestReopenWithCommit(dir, false);
+  }
+  public void testCommitReopenRAM () throws IOException {
+    Directory dir = new RAMDirectory();
+    doTestReopenWithCommit(dir, true);
+  }
+  public void testCommitRecreateRAM () throws IOException {
+    Directory dir = new RAMDirectory();
+    doTestReopenWithCommit(dir, false);
+  }
+
+  private void doTestReopenWithCommit (Directory dir, boolean withReopen) throws IOException
{
+    IndexWriter iwriter = new IndexWriter(dir, new KeywordAnalyzer(), true, MaxFieldLength.LIMITED);
+    iwriter.setMergeScheduler(new SerialMergeScheduler());
+    IndexReader reader = IndexReader.open(dir);
+    try {
+      int M = 3;
+      for (int i=0; i<4; i++) {
+        for (int j=0; j<M; j++) {
+          Document doc = new Document();
+          doc.add(new Field("id", i+"_"+j, Store.YES, Index.UN_TOKENIZED));
+          iwriter.addDocument(doc);
+          if (i>0) {
+            int k = i-1;
+            int n = j + k*M;
+            Document prevItereationDoc = reader.document(n);
+            assertNotNull(prevItereationDoc);
+            String id = prevItereationDoc.get("id");
+            assertEquals(k+"_"+j, id);
+          }
+        }
+        iwriter.commit();
+        if (withReopen) {
+          // reopen
+          IndexReader r2 = reader.reopen();
+          if (reader != r2) {
+            reader.close();
+            reader = r2;
+          }
+        } else {
+          // recreate
+          reader.close();
+          reader = IndexReader.open(dir);
+        }
+      }
+    } finally {
+      iwriter.close();
+      reader.close();
+    }
+  }
+  
   public void testMultiReaderReopen() throws Exception {
     final Directory dir1 = new RAMDirectory();
     createIndex(dir1, true);
@@ -914,6 +982,16 @@
   private abstract static class TestReopen {
     protected abstract IndexReader openReader() throws IOException;
     protected abstract void modifyIndex(int i) throws IOException;
+  }
+
+
+  protected void setUp() throws Exception {
+    // TODO Auto-generated method stub
+    super.setUp();
+    String tempDir = System.getProperty("java.io.tmpdir");
+    if (tempDir == null)
+      throw new IOException("java.io.tmpdir undefined, cannot run test");
+    indexDir = new File(tempDir, "IndexReaderReopen");
   }
   
 }



Mime
View raw message