Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Reverse merged revision(s) from lucene/dev/trunk up to 1237502

Uwe Schindler10ba9abeb208
diff --cc lucene/src/java/org/apache/lucene/index/DirectoryReader.java
index 73b29f1e099,3a733532a0f..4fb34ee457b
--- a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
+++ b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
@@@ -494,7 -301,8 +494,15 @@@ public final class DirectoryReader exte
return DirectoryReader.open(directory, writer, infos, subReaders, termInfosIndexDivisor);
}
-- /** Version number when this IndexReader was opened. */
- @Override
++ /**
++ * Version number when this IndexReader was opened. Not
++ * implemented in the IndexReader base class.
++ *
++ * <p>This method
++ * returns the version recorded in the commit that the
++ * reader opened. This version is advanced every time
++ * a change is made with {@link IndexWriter}.</p>
++ */
public long getVersion() {
ensureOpen();
return segmentInfos.getVersion();
@@@ -607,69 -420,6 +615,53 @@@
return commits;
}
- /**
- * Returns the time the index in the named directory was last modified.
- * Do not use this to check whether the reader is still up-to-date, use
- * {@link #isCurrent()} instead.
- * @throws CorruptIndexException if the index is corrupt
- * @throws IOException if there is a low-level IO error
- */
- public static long lastModified(final Directory directory) throws CorruptIndexException, IOException {
- return ((Long) new SegmentInfos.FindSegmentsFile(directory) {
- @Override
- public Object doBody(String segmentFileName) throws IOException {
- return Long.valueOf(directory.fileModified(segmentFileName));
- }
- }.run()).longValue();
- }
-
+ /**
+ * Reads version number from segments files. The version number is
+ * initialized with a timestamp and then increased by one for each change of
+ * the index.
+ *
+ * @param directory where the index resides.
+ * @return version number.
+ * @throws CorruptIndexException if the index is corrupt
+ * @throws IOException if there is a low-level IO error
+ */
+ public static long getCurrentVersion(Directory directory) throws CorruptIndexException, IOException {
+ return SegmentInfos.readCurrentVersion(directory);
+ }
+
+ /**
+ * Reads commitUserData, previously passed to {@link
+ * IndexWriter#commit(Map)}, from current index
+ * segments file. This will return null if {@link
+ * IndexWriter#commit(Map)} has never been called for
+ * this index.
+ *
+ * @param directory where the index resides.
+ * @return commit userData.
+ * @throws CorruptIndexException if the index is corrupt
+ * @throws IOException if there is a low-level IO error
+ *
+ * @see #getCommitUserData()
+ */
+ public static Map<String, String> getCommitUserData(Directory directory) throws CorruptIndexException, IOException {
+ return SegmentInfos.readCurrentUserData(directory);
+ }
+
+ /**
+ * Returns <code>true</code> if an index exists at the specified directory.
+ * @param directory the directory to check for an index
+ * @return <code>true</code> if an index exists; <code>false</code> otherwise
+ * @throws IOException if there is a problem with accessing the index
+ */
+ public static boolean indexExists(Directory directory) throws IOException {
+ try {
+ new SegmentInfos().read(directory);
+ return true;
+ } catch (IOException ioe) {
+ return false;
+ }
+ }
+
private static final class ReaderCommit extends IndexCommit {
private String segmentsFileName;
Collection<String> files;