lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r673979 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/index/ src/test/org/apache/lucene/index/
Date Fri, 04 Jul 2008 09:43:13 GMT
Author: mikemccand
Date: Fri Jul  4 02:43:12 2008
New Revision: 673979

URL: http://svn.apache.org/viewvc?rev=673979&view=rev
Log:
LUCENE-1325: add IndexCommit.isOptimized() method

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=673979&r1=673978&r2=673979&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Jul  4 02:43:12 2008
@@ -83,6 +83,9 @@
     DeletionPolicy that keeps more than the last commit around.
     (Jason Rutherglen via Mike McCandless)
 
+12. LUCENE-1325: Added IndexCommit.isOptimized().  (Shalin Shekhar
+    Mangar via Mike McCandless)
+
 Bug fixes
     
  1. LUCENE-1134: Fixed BooleanQuery.rewrite to only optimize a single 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java?rev=673979&r1=673978&r2=673979&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryIndexReader.java Fri Jul 
4 02:43:12 2008
@@ -360,6 +360,7 @@
     Directory dir;
     long generation;
     long version;
+    final boolean isOptimized;
 
     ReaderCommit(SegmentInfos infos, Directory dir) throws IOException {
       segmentsFileName = infos.getCurrentSegmentFileName();
@@ -374,6 +375,11 @@
       }
       version = infos.getVersion();
       generation = infos.getGeneration();
+      isOptimized = infos.size() == 1 && !infos.info(0).hasDeletions();
+    }
+
+    public boolean isOptimized() {
+      return isOptimized;
     }
     public String getSegmentsFileName() {
       return segmentsFileName;

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java?rev=673979&r1=673978&r2=673979&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexCommit.java Fri Jul  4 02:43:12
2008
@@ -75,6 +75,13 @@
   }
 
   /**
+   * Returns true if this commit is an optimized index.
+   */
+  public boolean isOptimized() {
+    throw new UnsupportedOperationException("This IndexCommit does not support this method.");
+  }
+
+  /**
    * Two IndexCommits are equal if both their Directory and versions are equal.
    */
   public boolean equals(Object other) {

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java?rev=673979&r1=673978&r2=673979&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexFileDeleter.java Fri Jul  4 02:43:12
2008
@@ -579,6 +579,7 @@
     Collection commitsToDelete;
     long version;
     long generation;
+    final boolean isOptimized;
 
     public CommitPoint(Collection commitsToDelete, Directory directory, SegmentInfos segmentInfos)
throws IOException {
       this.directory = directory;
@@ -595,7 +596,12 @@
         if (segmentInfo.dir == directory) {
           files.addAll(segmentInfo.files());
         }
-      }
+      } 
+      isOptimized = segmentInfos.size() == 1 && !segmentInfos.info(0).hasDeletions();
+    }
+
+    public boolean isOptimized() {
+      return isOptimized;
     }
 
     public String getSegmentsFileName() {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java?rev=673979&r1=673978&r2=673979&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestDeletionPolicy.java Fri Jul  4
02:43:12 2008
@@ -61,11 +61,16 @@
   class KeepAllDeletionPolicy implements IndexDeletionPolicy {
     int numOnInit;
     int numOnCommit;
+    Directory dir;
     public void onInit(List commits) {
       verifyCommitOrder(commits);
       numOnInit++;
     }
-    public void onCommit(List commits) {
+    public void onCommit(List commits) throws IOException {
+      IndexCommit lastCommit = (IndexCommit) commits.get(commits.size()-1);
+      IndexReader r = IndexReader.open(dir);
+      assertEquals("lastCommit.isOptimized()=" + lastCommit.isOptimized() + " vs IndexReader.isOptimized="
+ r.isOptimized(), r.isOptimized(), lastCommit.isOptimized());
+      r.close();
       verifyCommitOrder(commits);
       numOnCommit++;
     }
@@ -263,10 +268,12 @@
       KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy();
 
       Directory dir = new RAMDirectory();
+      policy.dir = dir;
 
       IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true,
policy, IndexWriter.MaxFieldLength.LIMITED);
       writer.setMaxBufferedDocs(10);
       writer.setUseCompoundFile(useCompoundFile);
+      writer.setMergeScheduler(new SerialMergeScheduler());
       for(int i=0;i<107;i++) {
         addDoc(writer);
         if (autoCommit && i%10 == 0)

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?rev=673979&r1=673978&r2=673979&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Fri Jul  4 02:43:12
2008
@@ -1315,6 +1315,16 @@
 
       IndexReader r2 = r.reopen();
       assertFalse(c.equals(r2.getIndexCommit()));
+      assertFalse(r2.getIndexCommit().isOptimized());
+      r2.close();
+
+      writer = new IndexWriter(d, new StandardAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
+      writer.optimize();
+      writer.close();
+
+      r2 = r.reopen();
+      assertTrue(r2.getIndexCommit().isOptimized());
+
       r.close();
       r2.close();
       d.close();



Mime
View raw message