lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r561611 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/ParallelReader.java src/test/org/apache/lucene/index/TestParallelReader.java
Date Wed, 01 Aug 2007 00:43:12 GMT
Author: buschmi
Date: Tue Jul 31 17:43:11 2007
New Revision: 561611

URL: http://svn.apache.org/viewvc?view=rev&rev=561611
Log:
LUCENE-832: ParallelReader fixed to not throw NPE if isCurrent(), isOptimized() or getVersion()
is called.

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=561611&r1=561610&r2=561611
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Jul 31 17:43:11 2007
@@ -57,6 +57,9 @@
 
  8. LUCENE-970: FilterIndexReader now implements isOptimized(). Before
     a call of isOptimized() would throw a NPE. (Michael Busch)
+
+ 9. LUCENE-832: ParallelReader fixed to not throw NPE if isCurrent(),
+    isOptimized() or getVersion() is called. (Michael Busch)
       
 New features
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java?view=diff&rev=561611&r1=561610&r2=561611
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java Tue Jul 31 17:43:11
2007
@@ -279,6 +279,43 @@
     ensureOpen();
     return new ParallelTermPositions();
   }
+  
+  /**
+   * Checks recursively if all subreaders are up to date. 
+   */
+  public boolean isCurrent() throws CorruptIndexException, IOException {
+    for (int i = 0; i < readers.size(); i++) {
+      if (!((IndexReader)readers.get(i)).isCurrent()) {
+        return false;
+      }
+    }
+    
+    // all subreaders are up to date
+    return true;
+  }
+
+  /**
+   * Checks recursively if all subindexes are optimized 
+   */
+  public boolean isOptimized() {
+    for (int i = 0; i < readers.size(); i++) {
+      if (!((IndexReader)readers.get(i)).isOptimized()) {
+        return false;
+      }
+    }
+    
+    // all subindexes are optimized
+    return true;
+  }
+
+  
+  /** Not implemented.
+   * @throws UnsupportedOperationException
+   */
+  public long getVersion() {
+    throw new UnsupportedOperationException("ParallelReader does not support this method.");
+  }
+
 
   protected void doCommit() throws IOException {
     for (int i = 0; i < readers.size(); i++)
@@ -448,5 +485,6 @@
   }
 
 }
+
 
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java?view=diff&rev=561611&r1=561610&r2=561611
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java Tue Jul 31
17:43:11 2007
@@ -120,7 +120,81 @@
       // expected exception
     }
   }
+  
+  public void testIsCurrent() throws IOException {
+    Directory dir1 = getDir1();
+    Directory dir2 = getDir1();
+    ParallelReader pr = new ParallelReader();
+    pr.add(IndexReader.open(dir1));
+    pr.add(IndexReader.open(dir2));
+    
+    assertTrue(pr.isCurrent());
+    IndexReader modifier = IndexReader.open(dir1);
+    modifier.setNorm(0, "f1", 100);
+    modifier.close();
+    
+    // one of the two IndexReaders which ParallelReader is using
+    // is not current anymore
+    assertFalse(pr.isCurrent());
+    
+    modifier = IndexReader.open(dir2);
+    modifier.setNorm(0, "f3", 100);
+    modifier.close();
+    
+    // now both are not current anymore
+    assertFalse(pr.isCurrent());
+  }
+
+  public void testIsOptimized() throws IOException {
+    Directory dir1 = getDir1();
+    Directory dir2 = getDir1();
+    
+    // add another document to ensure that the indexes are not optimized
+    IndexWriter modifier = new IndexWriter(dir1, new StandardAnalyzer());
+    Document d = new Document();
+    d.add(new Field("f1", "v1", Field.Store.YES, Field.Index.TOKENIZED));
+    modifier.addDocument(d);
+    modifier.close();
+    
+    modifier = new IndexWriter(dir2, new StandardAnalyzer());
+    d = new Document();
+    d.add(new Field("f2", "v2", Field.Store.YES, Field.Index.TOKENIZED));
+    modifier.addDocument(d);
+    modifier.close();
+
+    
+    ParallelReader pr = new ParallelReader();
+    pr.add(IndexReader.open(dir1));
+    pr.add(IndexReader.open(dir2));
+    assertFalse(pr.isOptimized());
+    pr.close();
+    
+    modifier = new IndexWriter(dir1, new StandardAnalyzer());
+    modifier.optimize();
+    modifier.close();
+    
+    pr = new ParallelReader();
+    pr.add(IndexReader.open(dir1));
+    pr.add(IndexReader.open(dir2));
+    // just one of the two indexes are optimized
+    assertFalse(pr.isOptimized());
+    pr.close();
+
+    
+    modifier = new IndexWriter(dir2, new StandardAnalyzer());
+    modifier.optimize();
+    modifier.close();
+    
+    pr = new ParallelReader();
+    pr.add(IndexReader.open(dir1));
+    pr.add(IndexReader.open(dir2));
+    // now both indexes are optimized
+    assertTrue(pr.isOptimized());
+    pr.close();
+
+  }
 
+  
   private void queryTest(Query query) throws IOException {
     Hits parallelHits = parallel.search(query);
     Hits singleHits = single.search(query);
@@ -136,7 +210,7 @@
     }
   }
 
-  // Fiels 1-4 indexed together:
+  // Fields 1-4 indexed together:
   private Searcher single() throws IOException {
     Directory dir = new MockRAMDirectory();
     IndexWriter w = new IndexWriter(dir, new StandardAnalyzer(), true);



Mime
View raw message