Index: src/test/org/apache/lucene/index/TestCheckIndex.java =================================================================== --- src/test/org/apache/lucene/index/TestCheckIndex.java (revision 697114) +++ src/test/org/apache/lucene/index/TestCheckIndex.java (working copy) @@ -49,7 +49,7 @@ ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); CheckIndex.out = new PrintStream(bos); - CheckIndexStatus indexStatus = CheckIndex.check(dir, false, null); + CheckIndexStatus indexStatus = CheckIndex.checkIndex(dir, false, null); if (indexStatus.clean == false) { System.out.println("CheckIndex failed"); System.out.println(bos.toString()); @@ -57,6 +57,6 @@ } final List onlySegments = new ArrayList(); onlySegments.add("_0"); - assertTrue(CheckIndex.check(dir, false, onlySegments).clean == true); + assertTrue(CheckIndex.checkIndex(dir, false, onlySegments).clean == true); } } Index: src/test/org/apache/lucene/util/_TestUtil.java =================================================================== --- src/test/org/apache/lucene/util/_TestUtil.java (revision 697114) +++ src/test/org/apache/lucene/util/_TestUtil.java (working copy) @@ -63,7 +63,7 @@ CheckIndex.out = new PrintStream(bos); //TODO: fix this - CheckIndexStatus indexStatus = CheckIndex.check(dir, false, null); + CheckIndexStatus indexStatus = CheckIndex.checkIndex(dir, false, null); if (indexStatus == null || indexStatus.clean == false) { System.out.println("CheckIndex failed"); System.out.println(bos.toString()); Index: src/java/org/apache/lucene/index/CheckIndexStatus.java =================================================================== --- src/java/org/apache/lucene/index/CheckIndexStatus.java (revision 698033) +++ src/java/org/apache/lucene/index/CheckIndexStatus.java (working copy) @@ -18,57 +18,122 @@ */ import org.apache.lucene.store.Directory; +import org.apache.lucene.document.Fieldable; // for javadoc import java.util.List; import java.util.ArrayList; /** + * Returned from {@link CheckIndex#checkIndex(Directory, + * boolean)} detailing the health and status of the index. * - * + *
WARNING: this API is new and experimental and is
+ * subject to suddenly change in the next release.
**/
+
public class CheckIndexStatus {
+ /** True if no problems were found with the index. */
public boolean clean;
+ /** True if we were unable to locate and load the segments_N file. */
+ public boolean missingSegments;
- public boolean missingSegments;
+ /** True if we were unable to open the segments_N file. */
public boolean cantOpenSegments;
+
+ /** True if we were unable to read the version number from segments_N file. */
public boolean missingSegmentVersion;
+ /** Name of latest segments_N file in the index. */
+ public String segmentsFileName;
- public String segmentsFileName;
+ /** Number of segments in the index. */
public int numSegments;
+
+ /** String description of the version of the index. */
public String segmentFormat;
+
+ /** Empty unless you passed specific segments list to check as optional 3rd argument.
+ * @see CheckIndex#checkIndex(Directory, boolean, List) */
public List/* WARNING: this API is new and experimental and is
+ * subject to suddenly change in the next release.
*/
-
public class CheckIndex {
+ /** Set this to see messages as the tool is checking */
public static PrintStream out = null;
+ private CheckIndex() {
+ }
+
private static class MySegmentTermDocs extends SegmentTermDocs {
int delCount;
@@ -62,13 +64,37 @@
}
}
- /** Returns true if index is clean, else false.*/
- public static CheckIndexStatus check(Directory dir, boolean doFix) throws IOException {
- return check(dir, doFix, null);
+ /** Returns true if index is clean, else false.
+ * @deprecated Please use {@link #checkIndex(Directory,
+ * boolean)} instead */
+ public static boolean check(Directory dir, boolean doFix) throws IOException {
+ return checkIndex(dir, doFix, null).clean;
}
- /** Returns true if index is clean, else false.*/
- public static CheckIndexStatus check(Directory dir, boolean doFix, List onlySegments) throws IOException {
+ /** Returns true if index is clean, else false.
+ * @deprecated Please use {@link #checkIndex(Directory,
+ * boolean, List)} instead */
+ public static boolean check(Directory dir, boolean doFix, List onlySegments) throws IOException {
+ return checkIndex(dir, doFix, onlySegments).clean;
+ }
+
+ /** Returns a {@link CheckIndexStatus} instance detailing
+ * the state of the index.
+ *
+ * WARNING: make sure
+ * you only call this when the index is not opened by any
+ * writer. */
+ public static CheckIndexStatus checkIndex(Directory dir, boolean doFix) throws IOException {
+ return checkIndex(dir, doFix, null);
+ }
+
+ /** Returns a {@link CheckIndexStatus} instance detailing
+ * the state of the index.
+ *
+ * WARNING: make sure
+ * you only call this when the index is not opened by any
+ * writer. */
+ public static CheckIndexStatus checkIndex(Directory dir, boolean doFix, List onlySegments) throws IOException {
NumberFormat nf = NumberFormat.getInstance();
SegmentInfos sis = new SegmentInfos();
CheckIndexStatus result = new CheckIndexStatus();
@@ -346,11 +372,16 @@
return result;
}
- /** Repairs the index using previously returned result from
- * {@link #check}. WARNING: this writes a new
- * segments file into the index, effectively removing
- * all documents in broken segments from the index. BE
- * CAREFUL. */
+ /** Repairs the index using previously returned result
+ * from {@link #checkIndex}.
+ *
+ * WARNING: this writes a
+ * new segments file into the index, effectively removing
+ * all documents in broken segments from the index.
+ * BE CAREFUL.
+ *
+ * WARNING: Make sure you only call this when the
+ * index is not opened by any writer. */
static public void fix(CheckIndexStatus result) throws IOException {
result.newSegments.commit(result.dir);
}
@@ -441,10 +472,10 @@
System.exit(1);
}
- CheckIndexStatus result = check(dir, doFix, onlySegments);
+ CheckIndexStatus result = checkIndex(dir, doFix, onlySegments);
if (!result.clean) {
- if (!doFix){
+ if (!doFix) {
msg("WARNING: would write new segments file, and " + result.totLoseDocCount + " documents would be lost, if -fix were specified\n");
} else {
msg("WARNING: " + result.totLoseDocCount + " documents will be lost\n");