From f99e4e72607fb39d59c8a8626029df7162ae43d1 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 25 Jan 2008 09:36:21 +0000 Subject: [PATCH] LUCENE-1147: add -segment option to CheckIndex tool, to check only a specific segment or segments git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@615159 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++ .../org/apache/lucene/index/CheckIndex.java | 64 ++++++++++++++++--- .../apache/lucene/index/TestCheckIndex.java | 7 +- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d6c1eae81c6..f5c224507ce 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,10 @@ New features 1. LUCENE-1137: Added Token.set/getFlags() accessors for passing more information about a Token through the analysis process. The flag is not indexed/stored and is thus only used by analysis. + 2. LUCENE-1147: Add -segment option to CheckIndex tool so you can + check only a specific segment or segments in your index. (Mike + McCandless) + Optimizations Documentation diff --git a/src/java/org/apache/lucene/index/CheckIndex.java b/src/java/org/apache/lucene/index/CheckIndex.java index d9ce202b0c1..795042514fb 100644 --- a/src/java/org/apache/lucene/index/CheckIndex.java +++ b/src/java/org/apache/lucene/index/CheckIndex.java @@ -27,6 +27,8 @@ import java.io.PrintStream; import java.io.IOException; import java.util.Collection; import java.util.Iterator; +import java.util.List; +import java.util.ArrayList; /** * Basic tool to check the health of an index and write a @@ -62,6 +64,11 @@ public class CheckIndex { /** Returns true if index is clean, else false.*/ public static boolean check(Directory dir, boolean doFix) throws IOException { + return check(dir, doFix, null); + } + + /** Returns true if index is clean, else false.*/ + public static boolean check(Directory dir, boolean doFix, List onlySegments) throws IOException { NumberFormat nf = NumberFormat.getInstance(); SegmentInfos sis = new SegmentInfos(); @@ -115,6 +122,15 @@ public class CheckIndex { out.println("Segments file=" + segmentsFileName + " numSegments=" + numSegments + " version=" + sFormat); + if (onlySegments != null) { + out.print("\nChecking only these segments:"); + Iterator it = onlySegments.iterator(); + while (it.hasNext()) { + out.print(" " + it.next()); + } + out.println(":"); + } + if (skip) { out.println("\nERROR: this index appears to be created by a newer version of Lucene than this tool was compiled on; please re-compile this tool on the matching version of Lucene; exiting"); return false; @@ -127,6 +143,8 @@ public class CheckIndex { int numBadSegments = 0; for(int i=0;i