Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

- Added isOptimized() to IndexReader

Otis Gospodnetic9b0986ae373b
diff --git a/CHANGES.txt b/CHANGES.txt
index bcf8102585b..a98a474846e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -174,6 +174,9 @@ API Changes
setters for both the default Resolution, and per-field Resolution.
For backwards compatibility, DateField is still used if no Resolutions
are specified. (Michael Busch via Chris Hostetter)
+
+15. Added isOptimized() method to IndexReader.
+ (Otis Gospodnetic)
Bug fixes
diff --git a/src/java/org/apache/lucene/index/IndexReader.java b/src/java/org/apache/lucene/index/IndexReader.java
index 1a24696cd21..4e2092aba51 100644
--- a/src/java/org/apache/lucene/index/IndexReader.java
+++ b/src/java/org/apache/lucene/index/IndexReader.java
@@ -277,6 +277,14 @@ public abstract class IndexReader {
return SegmentInfos.readCurrentVersion(directory) == segmentInfos.getVersion();
}
+ /**
+ * Checks is the index is optimized (if it has a single segment and no deletions)
+ * @return <code>true</code> if the index is optimized; <code>false</code> otherwise
+ */
+ public boolean isOptimized() {
+ return segmentInfos.size() == 1 && hasDeletions() == false;
+ }
+
/**
* Return an array of term frequency vectors for the specified document.
* The array contains a vector for each vectorized field in the document.