lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhang, Lisheng" <>
Subject RE: Detect a corrupted index
Date Sat, 27 Jul 2013 05:38:49 GMT

I used in the following code to detect data corruption in lucene 4.3.0:

   import org.apache.lucene.index.CheckIndex;

   CheckIndex checkIndex = new CheckIndex(getLuceneDirectory(folderPath));
   CheckIndex.Status status = checkIndex.checkIndex();
   if(!status.clean) {

   private static void printStatusDetails(CheckIndex.Status status) {
    if(status.toolOutOfDate) {
      log("Index version and checking tool does not match, checking is not conclusive");

    if(status.missingSegments) {
      log("Cannot locate and load the segments_N file.");

    if(status.missingSegmentVersion) {
      log("Cannot read version number from segment_N file");

    if(status.cantOpenSegments) {
      log("Cannot open segment_N file");

    if(status.numBadSegments > 0) {
      log("There are (" + status.numBadSegments + ") out of (" + status.numSegments + ") total

  private static Directory getLuceneDirectory(String path)
    throws Exception {
    return File(path));

Best regards, Lisheng

-----Original Message-----
From: ABlaise []
Sent: Friday, July 26, 2013 7:33 PM
Subject: Detect a corrupted index

Hi everyone !

So I am working on a Lucene index that will run on a server and since this
server might crash/be killed at any time, even during the creation of an
index, I would like to be able to detect if an index is corrupted or not. I
don't care about repairing it, rebuilding it from scratch doesn't take too

Any idea or hint on how I should proceed ? I searched for related topics but
they all seemed old and don't apply to Lucene 4.3.1

Thanks in advance


View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message