Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 658890) +++ CHANGES.txt (working copy) @@ -64,6 +64,11 @@ replacement character U+FFFD. This is a change to the index file format. (Marvin Humphrey via Mike McCandless) + 8. LUCENE-1288: Add getVersion() and getGeneration() to IndexCommit. + getVersion() returns the same value that IndexReader.getVersion() + returns when the reader is opened on the same commit. (Jason + Rutherglen via Mike McCandless) + Bug fixes 1. LUCENE-1134: Fixed BooleanQuery.rewrite to only optimize a single Index: src/test/org/apache/lucene/index/TestDeletionPolicy.java =================================================================== --- src/test/org/apache/lucene/index/TestDeletionPolicy.java (revision 658890) +++ src/test/org/apache/lucene/index/TestDeletionPolicy.java (working copy) @@ -43,10 +43,17 @@ public class TestDeletionPolicy extends LuceneTestCase { private void verifyCommitOrder(List commits) { - long last = SegmentInfos.generationFromSegmentsFileName(((IndexCommit) commits.get(0)).getSegmentsFileName()); + final IndexCommit firstCommit = ((IndexCommit) commits.get(0)); + long last = SegmentInfos.generationFromSegmentsFileName(firstCommit.getSegmentsFileName()); + assertEquals(last, firstCommit.getGeneration()); + long lastVersion = firstCommit.getVersion(); for(int i=1;i last); + assertTrue("SegmentInfos versions are out-of-order", nowVersion > lastVersion); + assertEquals(now, commit.getGeneration()); last = now; } } Index: src/java/org/apache/lucene/index/DirectoryIndexReader.java =================================================================== --- src/java/org/apache/lucene/index/DirectoryIndexReader.java (revision 658890) +++ src/java/org/apache/lucene/index/DirectoryIndexReader.java (working copy) @@ -343,6 +343,8 @@ private String segmentsFileName; Collection files; Directory dir; + long generation; + long version; ReaderCommit(SegmentInfos infos, Directory dir) throws IOException { segmentsFileName = infos.getCurrentSegmentFileName(); @@ -355,6 +357,8 @@ if (info.dir == dir) files.addAll(info.files()); } + version = infos.getVersion(); + generation = infos.getGeneration(); } public String getSegmentsFileName() { return segmentsFileName; @@ -365,6 +369,12 @@ public Directory getDirectory() { return dir; } + public long getVersion() { + return version; + } + public long getGeneration() { + return generation; + } } /** Index: src/java/org/apache/lucene/index/IndexCommit.java =================================================================== --- src/java/org/apache/lucene/index/IndexCommit.java (revision 658890) +++ src/java/org/apache/lucene/index/IndexCommit.java (working copy) @@ -89,4 +89,17 @@ public int hashCode() { return getDirectory().hashCode() + getSegmentsFileName().hashCode(); } + + /** Returns the version for this IndexCommit. This is the + same value that {@link IndexReader#getVersion} would + return if it were opened on this commit. */ + public long getVersion() { + throw new UnsupportedOperationException("This IndexCommit does not support this method."); + } + + /** Returns the generation (the _N in segments_N) for this + IndexCommit */ + public long getGeneration() { + throw new UnsupportedOperationException("This IndexCommit does not support this method."); + } } Index: src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java =================================================================== --- src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java (revision 658890) +++ src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java (working copy) @@ -109,6 +109,12 @@ cp.delete(); } } + public long getVersion() { + return cp.getVersion(); + } + public long getGeneration() { + return cp.getGeneration(); + } } private List wrapCommits(List commits) { Index: src/java/org/apache/lucene/index/IndexFileDeleter.java =================================================================== --- src/java/org/apache/lucene/index/IndexFileDeleter.java (revision 658890) +++ src/java/org/apache/lucene/index/IndexFileDeleter.java (working copy) @@ -577,11 +577,15 @@ boolean deleted; Directory directory; Collection commitsToDelete; + long version; + long generation; public CommitPoint(Collection commitsToDelete, Directory directory, SegmentInfos segmentInfos) throws IOException { this.directory = directory; this.commitsToDelete = commitsToDelete; segmentsFileName = segmentInfos.getCurrentSegmentFileName(); + version = segmentInfos.getVersion(); + generation = segmentInfos.getGeneration(); int size = segmentInfos.size(); files = new ArrayList(size); files.add(segmentsFileName); @@ -606,6 +610,14 @@ return directory; } + public long getVersion() { + return version; + } + + public long getGeneration() { + return generation; + } + /** * Called only be the deletion policy, to remove this * commit point from the index.