From 9b0986ae373b8c996d77a8caf987cdaf9806e57d Mon Sep 17 00:00:00 2001 From: Otis Gospodnetic Date: Thu, 11 Jan 2007 10:53:25 +0000 Subject: [PATCH] - Added isOptimized() to IndexReader git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@495190 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ src/java/org/apache/lucene/index/IndexReader.java | 8 ++++++++ 2 files changed, 11 insertions(+) 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 true if the index is optimized; false 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.